Facing issue while searching on string type field

2019-03-01 05:44发布

问题:

I am facing issue in Solr search. My schema is as follows

<fieldType name="c_text" class="solr.TextField">
<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>
<field name="parentId" type="string" indexed="true" stored="true"/>
<field name="data_s" type="c_text" indexed="true" stored="true"/>
<field name="email" type="string" indexed="true" stored="true"/>
<field name="receivedDate" type="tdate" indexed="true" stored="true"/>

I am searching on email field. which contains the data in following format
Tarun Nagpal <tarunn@abc.com>

//This is working fine
email:*tarun*

But following is giving no result

email:"Tarun Nagpal"

Can you please help, why it is not searching phrase like search on email field. Search on data_s field is working fine.

回答1:

You need to use the text field type since you intend to search the tokens:

To be specific for Tarun Nagpal <tarunn@abc.com>:

A string field will answer == equality and wildcard queries like *un Nagp*, *unn@abc.com> and even more apparently exotic queries.

A text field will answer to the tokens tarun, nagpal, tarunn abc and com.

Other field types implementing N-gram and Soundex can even correct your spelling.


See the excellent https://stackoverflow.com/a/2119479/604511



标签: solr solrj