Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr wildcard query with whitespace

Tags:

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?

like image 297
tbaz Avatar asked Apr 05 '12 05:04

tbaz


People also ask

What is the difference between Q and FQ in solr?

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).

What are wildcard search parameters solr?

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.

How do I query a collection in solr?

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.


2 Answers

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.

like image 72
Aubergine Avatar answered Sep 19 '22 13:09

Aubergine


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

like image 42
Jaikumar H Manjunath Avatar answered Sep 18 '22 13:09

Jaikumar H Manjunath