A reader just sent me a bug report where he noticed that his autosuggestions didn't seem to work right in ColdFusion 8. The same dataset was returned from two things he typed into the box. One worked - and one did not.
Turns out he had typed, for example, "cat", and expected to see suggestions with the word cat anywhere in the result. He had written his back end SQL that way. He saw words with "cat" in the middle being returned, but they refused to show up as suggestions.
Turns out CF's autosuggest will ignore any result that doesn't start the letters you typed in the box. This is a reasonable choice as it is what most folks want. Spry works the same way, but does have an option to do internal matching as well. I've filed an ER with Adobe, but wanted to blog the issue in case others run into it as well.
Archived Comments
Hi Ray,
I really don't think this is a "gotcha" at all. I would think that auto-suggest should work that way.
You should at least know what to start with when you use auto-suggest. With internal matching you run the risk of retuning a bunch of garbage if I start typing the word "ice" I am pretty sure I am not thinking of the word "choice" but I maybe thinking of Iceland, or icesavers.
After all this is auto suggest not auto full-text.
I agree with Gary, it seems to have been implemented the same way as the auto-suggest works on the google search toolbar in FF and pretty much every programming ide i've used that had an autocomplete/suggest feature.
I can see there may be occassions where the other usage might be desirable but the default behaviour should always be to match from the start of the string imho.
I would disagree with those that disagree. In Google's case, there is far too much junk in their system to allow searching anywhere but the beginning, but if you are building your own application, you should be able to have it act the way you want. In my mind, the whole idea with an autosuggest tool is that you know what you are looking for has certain letters, a word, or words somewhere in the string and you want the system to show you all the options. I work with standardized nomenclature systems in the medical field and often the term you want to search for is in the middle of the string.
@Steve: "In Google's case, there is far too much junk in their system to allow searching anywhere but the beginning"
You've not seen their nifty real-time route updates when you drag the middle of a route on Maps, have you :-)
To be clear - I think CF's behavior makes sense. But I wanted to warn folks inc ase they think otherwise - AND I do think there are cases where you want the "match anywhere" type behavior and it should be supported by CF, like Spry supports it as an option.
Well...I dont think it makes any sense at all. Yeah, I'm the one who sent this in to Ray....I write the query to return what I want to return - not what CF thinks I want to return. If I so choose to place a leading % and trailing % in the where statement, thats what I want. The thing that bothers is that a proper JSON response was received and not displayed.
I too, like Steve above, need my suggest to pick up tings in the middle of a string. Thats what I like about Cfajax - what you query is what you get.
@Tom - I have not seen that yet. To clarify my comment about Google; it was not intended to be derogatory, simply that with current technology, their repository is far too large for autosuggest to work efficiently if it were to search anywhere but the beginning. Google produces some great tools and I suppose in the very near future we will have to re-edit old Star Trek episodes to hear Kirk say "Google, what are the current atmospheric conditions on Epsilon V?"
Completely off topic. Sorry Ray.
No worries Steve. I'm sure I'm not the only who thinks one day Google will announce it's new name.
Skynet.
;)
(And if you don't get it, you are too young!)
I seem to be very contributive today!
To bypass this "feature", you can tell YUI not to do that:
<cfajaximport scriptSrc="CFIDE/scripts" cssSrc="CFIDE/scripts/ajax" tags="cfinput-autosuggest">
<script>
try{
YAHOO.widget.DataSource.prototype.queryMatchContains = true;
} catch (hmm ){
alert( hmm );
}
</script>
And for Skynet, i'll be back for that, trust me. :o)
I've actually created a custom tag that adds all the YUI widget functionality that CF didn't include:
http://betterautosuggest.ri...
Lets you do lists (think gmail recipient field) and querymatchContains plus lots more.
At the moment there is an issue with using queryMatchContains with binded autosuggests but it looks like PhilNgs code will help with that; will let you know how it goes.
Dominic
@PhilNg
I know this is a very old post but I still wanted to say thanks! Your script works like a champ and it saved me a lot of frustration.