Solr - match only exact phrase

Tom_LK picture Tom_LK · Feb 22, 2012 · Viewed 12k times · Source

I have a problem with a phrase query.

Query input: "to many results"

I want to have only the text that contain exact matching phrase:

  1. "word word word to many results word word word"

  2. "word word to many results word"

But the problem is:

  1. "word word word to many results word word word"

  2. "word word to many results word"

  3. "word many results word" - I don't wanna have this in my result

Schema:

<fieldType name="text" class="solr.TextField" termVectors="true" termPositions="true" termOffsets="true" autoGeneratePhraseQueries="true">
<analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory" />
    <filter class="solr.TrimFilterFactory" />
    <filter class="solr.LowerCaseFilterFactory" />
    <filter class="solr.ReversedWildcardFilterFactory" />
</analyzer>
<analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory" />
    <filter class="solr.TrimFilterFactory" />
    <filter class="solr.LowerCaseFilterFactory" />
</analyzer>

Thanks for help

Answer

Jayendra picture Jayendra · Feb 22, 2012

If you need an exact phrase match in same order, you would need to pass the query in phrase e.g "to many results".
This would return results for exact match and all words together.

If the query is not a phrase query and just needs all words present, the search would looks for words in the document within some positions (depends on the definition of slop) and the default search operator which have default is OR.

If you are using dismax, its control by the query slop for the qf and Minimum match (mm), the number of terms needed to be present in the document for it to be returned as a result.

If you are using standard request handler you need to check the Query parser default operator.

http://wiki.apache.org/solr/SchemaXml#Default_query_parser_operator