0

在 Rails 应用程序中,我开始使用 sunspot => https://github.com/sunspot/sunspot/blob/master/README.md

一切都很顺利,直到我注意到这一点(取自 rails-console):

1.9.3p194 :002 > MyModel.search{fulltext "leon"}.results
=> [#<MyModel id: 16, name: "Leon">]
1.9.3p194 :003 > MyModel.search{fulltext "león"}.results
=> [#<MyModel id: 18, name: "León">]

我怎样才能告诉系统不要区分“leon”和“león”(我想要像 search{fulltext "leon"} => [#MyModel id: 16 ... , #MyModel id: 18... ])

我一直在寻找这个问题,并且每次都发现相同的响应:

使用 Gemfile 中的这一行,同时 rsolr 的下一个版本:gem 'rsolr', :git => "https://github.com/mwmitchell/rsolr.git"

谢谢

4

3 回答 3

1

感谢您的回复。至少我昨晚用另一个想法解决了这个问题,我从http://codeshooter.wordpress.com/2011/01/13/full-text-search-in-in-rails-with-sunspot-和-solr/

这个想法在Restaurant.rb

text :name do 
  self.name.my_normalize
end

和功能

to_s.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/,'').downcase

该行适用于 "äáàÁÄÀ" --- "aaaaaa" 之类的字符串

于 2012-08-22T09:57:42.553 回答
1

in the schema.xml you need to add a character filter as described in AnalyzersTokenizersTokenFilters for example:

<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>

and in the you should have mapping-ISOLatin1Accent.txt you should have entries that will map the unicode byte sequence to a asci character sequence. You can see an example here mapping-ISOLatin1Accent.txt

于 2012-08-21T16:13:22.773 回答
0

您需要在 Solr(应用程序,而不是 gem)配置文件中进行更改。Solr 被“嵌入”在 gem 中,但您可以访问它的配置,就像它是单独安装的一样。查看 Solr 文档。

于 2012-08-21T15:59:00.177 回答