Closed JohnMcLear closed 12 years ago
Hi johnyma22, thanks for showing up here So the problem is that you are getting only the remote results if someone searches something more complicated, right? The reason for this is that local results are processed by javascript in a very simple way: doubleSuggest concatenates all the strings from the localSource json object contained in the attributes you passed in the seekValue property. For example:
data = [{id: 'asdf123', name: 'foo', name2: 'bar', name3: 'baz' }]
settings = {
localSource: data,
seekValue: 'name, name2, name3'
}
$('...').doubleSuggest(settings);
If you type "fo" doubleSuggest performs a "foo bar baz".search("foo") and will suggest the result matched. But if you search for "fo bar" it can't match both strings, returns false, that row is not suggested.
Two solutions come to my mind:
Provide doubleSuggest a "tags" or "related" property in your local data source like
data = [{id: 'asdf123', name: 'foo', name2: 'bar', name3: 'baz', related: "fo bar bbaz foobar bar ba ETC ETC ETC" }]
settings = {
localSource: data,
seekValue: 'related' // or 'name, name2, name3, related'
}
This would be done when you are building the data object, related terms should come from your natural language proccessing tool, you'll need to find out if it features a way to get related keywords given a certain word...
OR
hack doubleSuggest to search for each word separatly instead of a matching against a long string.
queryStr = "f bar"
var data = "foo bar baz";
var matched = false;
query = queryStr.split(' ');
for (var k in query) {
if (query.hasOwnProperty(k)) {
if(data.search(query[k]) !== -1) matched = true;
}
}
if (matched) {alert('yes!')}
Try this hack in jquery.doubleSuggest.js in line 279.
Tell me how you did :D
Cheers
This got me somewhere but I'm not sure it's the best method
var matched = false; var query = queryString.split(' '); for (var k in query) { if (query.hasOwnProperty(k)) { var dataVal = data[i]['name']; var queryVal = query[k]; if(dataVal.search(new RegExp(queryVal, "i")) !== -1){ matched = true; } } } // If the search returned at least one result, and that result is not already selected. if (matched) { // A hack to tell doubleSuggest not to expect a full string
I went down the hack route, any chance you could add this as an option? It needs fixing/tidying up etc :)
http://www.youtube.com/watch?v=M2v0IOGK_iQ&feature=youtu.be <-- just for the sake of sanity
Thanks for the video, really got me to the point. I pulled a new branch called word_search with the modifications we talked about. I did a quick test and seems it works for me, hope it works for you...
About the flickering effect you complain about, is because doubleSuggests hides the search result on every keydown (when it performs a new search), and as it seems you are only using this plugin with the localSource disabled, it wont provide a good UX this way, but... I also tweaked how the "Loading..." message (which is customizable) is displayed/removed so maybe you want to give it a try.
Other solution that i came up with (yet did not implemented), is to ignore the "bla".search() part when you are retrieving results from the remoteSource, as they must match to what the user typed, so a new filtering process wouldn't be that necessary in such case...
Chreers ;)
Oh, wow man you are frigging awesome :) I'm going to have a play with this tonight
This is perfect :) Great job! PS I am using local results now, was still writing the code to populate my array.
Thanks man! Let me know if you put this option in so I can track the project.
Glad it worked :D Thanks for the feedback, I will consider merging some part (if not all) of the code from this branch. Make sure you keep track of the progress by "watching" this repo.
I'm closing this issue.
LOL thanks a lot man, really surprised me :D Are those guys involved in your proyect?
BTW, what server side tool did you used to get the natural language search?
Using MySQL natural search: http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
cool ;)
On Tue, Mar 27, 2012 at 11:43 AM, John McLear < reply@reply.github.com
wrote:
Using MySQL natural search: http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
Reply to this email directly or view it on GitHub: https://github.com/hernantz/doubleSuggest/issues/2#issuecomment-4717841
So I'm not sure of the best way to solve this but I will try to explain the problem... Searching for Limp Bizkit obviously returns a result Searching for Bizkit obviously returns a result Searching for L Bizkit does not.
This is a problem for me because my users search for "St John's Bradford" and my search API does a natural language lookup and returns the correct response but the auto-completer can't handle this response as it doesn't match the input text. My API responds with "St John's Primary School, Bradford"...
Does that make sense?
Great job though, fast, light, love it, going to put it live on my site once this last hurdle is crossed :) Thanks!