I have a wildcard query that looks something like:
q=location:los a*
I'd like it to match "los angeles" and "los altos". A query like:
q=los*
Works just fine, but as soon as I add whitespace I get no results. How I can use whitespace in my wildcard queries?
Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter. The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).
Wildcards, * , can also be used for either or both endpoints to specify an open-ended range query. This is a divergence from Lucene's Classic Query Parser. field:[* TO 100] finds all field values less than or equal to 100. field:[100 TO *] finds all field values greater than or equal to 100.
You can search for "solr" by loading the Admin UI Query tab, enter "solr" in the q param (replacing *:* , which matches all documents), and "Execute Query". See the Searching section below for more information. To index your own data, re-run the directory indexing command pointed to your own directory of documents.
I've recently come across this problem myself, and it seems that all you need to do is escape the space in your query. Your original query would be interpreted by Solr as something like this:
location:los id:a*
(assuming "id" is your default search field)
However, if you were to write your query as:
location:los\ a*
Then it would end up being parsed as:
location:los a*
And the above should yield the results that you desire (assuming your data is properly indexed).
Tip: Figuring all this out is simple. Just add &debugQuery=on
to the end of the url you use when submitting your query to see how it was parsed by Solr.
Solution for your problem using complex query parser:
q={!complexphrase inOrder=true}location:"los a*"
To know more about Complex phrase query parser, checkout this link! https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-ComplexPhraseQueryParser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With