Tarun Nagpal
Tarun Nagpal

Reputation: 964

Exact match in SOLR

I am using NGramFilterFactory. My schema is as given below

<fieldType name="c_text" class="solr.TextField">
<analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="255"/>
</analyzer>

<analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<field name="parentId" type="string" indexed="true" stored="true"/>
<field name="data_s" type="c_text" indexed="true" stored="true"/>
<field name="email" type="c_text" indexed="true" stored="true"/>
<field name="receivedDate" type="tdate" indexed="true" stored="true"/>

I want to make exatc phrase search like "Hello World" on data_s field but unable to make it. If i give
data_s:hello world
it returns all the records which have hello or world or both. If i give
data_s:"hello world"
it returns nothing.

How can i make a exact phrase search on this. I also require to make a search on partial text like "ello", that's why I am using NGramFilterFactory.

So my requirement is to make a search on exact phrase and partial text too.

Upvotes: 0

Views: 1552

Answers (1)

Tarun Nagpal
Tarun Nagpal

Reputation: 964

My Solution:-

I am using copy field for this.

<field name="content" type="text_general" indexed="true" stored="false" 
 multiValued="true"/>
<copyField source="data_s" dest="content"/>

Whenever i need to make exact search, I am searching on "content" field.

I was using solr3.5 and "text_general" is defined as in this solr version

    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
</fieldType>

Upvotes: 1

Related Questions