同义词Solr two-way

时间:2016-04-02 11:05:07

标签: solr synonym

我希望Solr 4以双向方式返回给定同义词列表的同义词。

索引内容

Nice villa front of the sea
Looking for condo around 2 billions $
Superb house with 3 bedrooms
Flat for sale

synonyms.txt

#Equivalent synonyms may be separated with commas and give
#no explicit mapping.  In this case the mapping behavior will
#be taken from the expand parameter in the schema.  This allows
#the same synonym file to be used in different synonym handling strategies.

villa, house, home, condo, appartement, residence, flat 

schema.xml中

<analyzer type="index">
  <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
  <tokenizer class="solr.StandardTokenizerFactory"/>
  <filter class="solr.EnglishPossessiveFilterFactory"/>
  <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="false"/>
  <filter class="solr.LowerCaseFilterFactory"/>
  <filter class="solr.PorterStemFilterFactory"/>
</analyzer>

<analyzer type="query">
  <tokenizer class="solr.StandardTokenizerFactory"/>
  <filter class="solr.LowerCaseFilterFactory"/>
  <filter class="solr.EnglishPossessiveFilterFactory"/>
  <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="true"/>
  <filter class="solr.PorterStemFilterFactory"/>
</analyzer>

实际上:

搜索&#34;别墅&#34;返回所有结果但如果我在Synonyms.txt中搜索任何其他单词,我除了相应的句子之外别无其他。

即持平回报:

Flat for sale

即房屋退货:

Superb house with 3 bedrooms

我希望所有同义词(公寓,住宅,公寓等)与&#34; villa&#34;关键字。

1 个答案:

答案 0 :(得分:0)

您的分析仪配置存在许多问题。

  • “正如MatsLindh所指出的那样,标记生成器后,同义词过滤器应该是
  • SynonymFilter应该出现在PhoneticFilter之前。否则,在您的示例中,Flat将被忽略,因为它不是全部为小写。
  • inject应该true设置为<analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.EnglishPossessiveFilterFactory"/> <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" /> <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="true"/> <filter class="solr.PorterStemFilterFactory"/> </analyzer> ,因为您现在只是阻止了拼音代币而不是原始代币。

尝试使用此配置:

EUR-USD,USD-EUR,SEk-CAD