Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

Solr exact word search

I want to configure my Solr search engine so I get an exact match for the search term I enter.

eg. 'taxes' should return documents with 'taxes' and not 'tax', 'taxation' etc.

Any help or tips would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I presume your field is a TextField, by default solr does a fuzzy search on this field. What you want is to set up your field as a string field and add no tokenizer then you'll get an exact match.

You can even combine the exact search with a fuzzy search and use DisMax to boost the relative weights.

Example (schema.xml) :

<field name="name"             type="string" indexed="true" stored="false" required="true" />
<field name="nameString"       type="string" indexed="true" stored="false" required="true" />
<copyField source="name" dest="nameString"/>

Example (solrconfig.xml) :

<requestHandler name="accounts" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="defType">dismax</str>
      <str name="qf">
        nameString^10.0 name^5.0 description^1.0
      </str>
      <str name="tie">0.1</str>
    </lst>
  </requestHandler>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...