搜索引擎 Solr Analyzer 显示有找到但是 Sunspot 却找不到

lulalala · 2012年07月19日 · 最后由 lulalala 回复于 2012年07月23日 · 9857 次阅读

请问有在用 sunspot/solr 的大家,我在 solr analyzer 可以看到有 match,但是在 console 中搜寻却找不到:

>> Buy::Topic.search{ keywords '恐惧' }.total
=> 55
>> Buy::Topic.search{ keywords '恐惧研' }.total
=> 0
>> Buy::Topic.search{ keywords '恐惧 研' }.total
=> 7
>> Buy::Topic.search{ keywords '恐惧 研究' }.total
=> 4

我有特别去重新 reindex 过了,但是结果还是这样,就好像我的 query 不会正确分词。

这是我的 schema.xml

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer type="index">
    <tokenizer class="solr.CJKTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="2" side="front"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.CJKTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

我的 rails 栏位都是 sunspot 的 text,所以应该会用这个才对。

匿名 #1 2012年07月19日

直接通过浏览器搜索试试。首先确定是 solr 的问题还是 ruby 的问题。比如你的 solr 部署在http://localhost:8080/yourapp, 就访问下 http://localhost:8080/yourapp/select/?q=ruby

找一个索引查看器,看有没有创建好索引

@tylerlong 我的 Sunspot.config.solr.url 指向 http://localhost:8982/solr 所以我尝试了 http://localhost:8982/solr/?q=ruby 可是是个一般的前导画面(有连结指向 admin)

@uudui 我有试过 lukeall 不过还不知道要怎样找 Model A 的 43232 号资料,好像无法这样搜寻。请问你知道这怎样用或是有用过其他的查看器吗?

search 里面应该是用 fulltext 吧,你在 console 里面用的是 keyword

Post.search { fulltext 'blah' }

@quakewang 这两个是 alias 所以是一样的。

@tylerlong 会回传一个包含搜索字串的 xml:<response><lst name="responseHeader"><int name="status">0</int><int name="QTime">9</int><lst name="params"><str name="q">ruby</str></lst></lst><result name="response" numFound="0" start="0"/></response> 这样代表?

#5 楼 @lulalala 可能和你在 index analyzer 里面添加的 EdgeNGramFilterFactory 有关系,导致相邻分词结果的 index position 改变,试试看在 analyzer type="query"添加:

<filter class="solr.PositionFilterFactory" />

#8 楼 @quakewang 抱歉耍笨了,我现在才知道要 http://localhost:8982/solr/select/?q=content_text:恐惧,传回 4 项。用“恐惧 研”或是“恐惧研究”“恐惧 研究”就完全没有东西。跟今日的 rails conosle 结果完全不同。我下周再看看你说的方式,谢谢~

#3 楼 @lulalala 不好意思,回晚了,正好最近在将项目中优化 solr 搜索,我用的也是 lukeall 索引查看器,我觉得完全满足需求,其他的没用过了。。。。

#8 楼 @quakewang 谢谢,真的是这个问题,我完全不知道 position 会有这样子的影响。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号