fatdragon
fatdragon

Reputation: 2299

solr field specific query returns exact match for the whole field

I'm just getting started with solr but thought this is somewhat counterintuitive. Please help.

Two of my documents have author = "Rick Riordan". When I run these queries:

Rick

=> returns 2 docs, good!

author:Rick

=> returns nothing.... why?

author:"Rick Riordan"

=> returns 2 docs.... looks like it assumes exact match.

Upvotes: 0

Views: 233

Answers (2)

Abhijit Bashetti
Abhijit Bashetti

Reputation: 8658

Change the field Type for your Field author. Re-index the same and Try Searching the same.

<fieldType>
<analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    </fieldType>

fire your query on a field name like below

q=:author:Rick

Upvotes: 1

Pankaj
Pankaj

Reputation: 592

You can use this as a fieldType.

It'll do the following- 1. Generate tokens on white spaces. So that you can either search on individual words or whole word. 2. It will remove duplicate indexes reducing index size.

<fieldType name="strings" class="solr.TextField" sortMissingLast="true" omitNorms="true">
    <analyzer>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <!--  <tokenizer class="solr.KeywordTokenizerFactory"/>-->
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    </analyzer>
</fieldType>

Upvotes: 1

Related Questions