fedorshishi
fedorshishi

Reputation: 1477

Solr query emulates exactly match

I use solr to make a short query with brand. I want the equal match, but understand that it is impossible in the Lucene. I tried some hardcoded query just for tests

myBrand:2\+2 and myBrand:\+

I get 2:2, seems and condition not working or not so how I am expect?

Also, i try fq

myBrand:2\+2 with a fq of myBrand:\+

Now, no results at all.

I use Solr 5 and make all tests in the Solr web interface. Is there some method to get the best matching of some short brands, nicknames and etc, when I no need too much eristics and want strong equal matching? Or anyway I have to filter results in my own code after solr query executed?

query by fields

query with filter

query with filter2

UPDATED

Changes in a schema resolved my issues. Now it is working for the queries 2+2 like a charm.

<fieldType name="text_general" class="solr.TextField" multiValued="true" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.PatternTokenizerFactory" pattern="\s*"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.PatternTokenizerFactory" pattern="\s*"/>
    </analyzer>
</fieldType>

Upvotes: 1

Views: 1603

Answers (1)

MatsLindh
MatsLindh

Reputation: 52902

Equal matches are not impossible. You just have to use a field type that retains the exact value, such as StrField or a TextField with KeywordTokenizer (if you want to make it case insensitive).

Matching would be field:"Exact value" or any regular query syntax. The reason why Solr/Lucene wouldn't do an "exact" match is that the regular TextField definitions in the example breaks the text into separate tokens.

For filters you usually want the exact value (both for a facet and for the fq, so you can filter the results exactly), so this is not a Lucene limitation, but something introduced by the type of fields you're working with.

The solution might be to have the same content in many fields (one to search against for regular text queries) and one to filter and facet on. Use copyField to get the same values into several fields from the same source field.

Upvotes: 3

Related Questions