I would like to add autocomplete to my tagging functionality.
A couple of questions:
-
How do I generate a list of autocomplete suggestions that includes matches in both the prefix and the middle of string? For example, if the user type “auto”, the autocomplete suggestions should include terms such as “autocomplete” and “build automation”.
-
I would like to allow multi-word tags and use comma (“,”) as a separator for tags. So when the use hits the space bar, he is still typing out the same tag, but when he hits the comma key, he’s starting a new tag. How do I do that?
I am using Django, jQuery, MySQL, and Solr. What is the best way to achieve to implement the above 2 features?
I’ve implemented exactly what you’re asking about and it works really well. There’s two issues to be aware of:
Like the previous answer, I’d start with the same article linked above, but you DO want the Edge NGram analyzer. The thing you’ll add is to ALSO do whitespace tokenization.
And then you’d make these changes to your schema.xml file. This example assumes you already have a field called “title” defined, and it’s what you’d like to display as well. I create a second field, which is ONLY used for autocomplete prefix matching.
Step 1: Define Edge NGram Text field type
Step 2: Define the New Field
Step 3: Copy the Title’s content over to the prefix field during indexing
That’s pretty much it for the schema. Just remember: