Now I’m trying to create a search api, something like the searchbox in hotels.com and expedia.com where you type the destination you want to go to and you get results, but I’m having a difficult time in getting proper results according to the user input.
But this way I’m missing a lot hits, assume the keyword is “san fran” then I don’t get San Francisco in the json above but I get other destinations like ‘San Marino’ and ‘San Benito’. If I input “amm” as keyword, I don’t get city Amman.
So I’m here seeking help, can someone enlighten me how to achieve what I’m trying to do? What kind of query would suit this case best? Should I use a conjunction query maybe?
Hi lenix,
Wondering if you can post your index definition up for us to see? Especially, to check out the analyzer you’re using.
One of the things about search systems is depending on the text analyzer, something like “San Francisco” or “Amman” will get tokenized into something like [“san”, “francisco”] and into [“amman”]
But, when you search for “san fran” and “amm”, it would be looking for [“san”, “fran”] and “amm”, respectively, so the “fran” won’t match, and the “amm” won’t match.
I’m not sure if you need to use a different analyzer or not, I’ll try to give that a test today too. But I did use QueryString with a * wildcard and received good results using same analyzer as you.
But that page does not describe using a wildcard * with the QueryString, only + and -… Also it says in a note
Certain queries that are supported by FTS are not yet supported by the query string syntax. This includes wildcards, regexp, and date range queries.
Also I’m still unable to get the results I want by any of those query types, as I described above, if I have ‘san fran’ as a keyword, I don’t get ‘San Francisco’ back. I tried creating my own analyzer with a whitespace tokenizer but it also didn’t help.
Please if someone can give any sort of help it would be much appreciated.
Sorry we have some updates docs coming that should help show these examples better.
There are two approaches to consider. One is using a Wildcard Query in the query string.
“The wildcard query uses a wildcard expression to search within individual terms for matches. Wildcard expressions can be any single character (?) or zero to many characters (*). Wildcard expressions can appear in the middle or end of a term but not at the beginning of the search term.”
You should be able to search: “san fran*” or “amm*”. I think you’ve tried it, did it work for you?
Or you can do a Prefix query, but you will have to generate your JSON definition for the query and pass it to the service. (You cannot using simple query string method using the search box in the web console for this special type of query). For example, I indexed the “country” field in the travel-sample database, then I query it for a specific prefix:
Regex and Wildcard queries don’t work for me whatsoever (I get zero hits/results). Keep in mind I’m using the latest SDK and I’ve tried on both the latest Stable CB build and the 5.0 Beta. Not sure what I’m doing wrong.