Solr search multiple word in query

2019-09-09 13:28发布

问题:

I have following fields in solr schema

make
model
city
province

I created a copyfield search and copy these 4 field in it

now I want, if a user is searching for

'audi a4' where audi is a make and a4 is model, 

I should get result where in a row make is audi and model is a4.

In case if I search for

'asd audi asd' 

then i should get result of audi only.

In case if i search for

'asd aasd audi asd a4',

then it should display audi a4 results.

Please help me to achieve this.

Please see schema for copy field

   <copyField source="Make" dest="search"/>
   <copyField source="Model" dest="search"/>
   <copyField source="City" dest="search"/>

Field created is as follow

<field name="search" type="string" indexed="true" stored="false" multiValued="true"/>

回答1:

You can try this fieldType for your field.

<fieldType name="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>

or you can try this field Type for search field

<fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="1" catenateWords="0" catenateNumbers="0" preserveOriginal="1" catenateAll="0" splitOnCaseChange="0"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
      <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>

So your field is now

<field name="search" type="text_ws" indexed="true" stored="false" multiValued="true"/>


标签: php search solr