0

我使用 Sunspot Rails 发现了一个非常奇怪的错误,其中一些关键字被忽略/不匹配。

如果你去这里:

http://www.ycn.org/showcase/portfolios

并搜索“Owen”,您将返回两条记录。

http://www.ycn.org/showcase/portfolios?utf8=%E2%9C%93&keywords=owen

但是,如果您输入“Davey”,您将不会返回任何匹配项,尽管这应该匹配“Owen Davey”。“欧文戴维”包含在同一字段中。

为什么会这样?

在我的模型中:

  searchable do
text :name, :boost => 2.0
text :url
text :description
boolean :is_published
integer :city_id, :references => City
text :city_name, :more_like_this => true do |portfolio|
  portfolio.city.name if portfolio.city.present?
end
integer :country_id, :references => Country do |portfolio|
  portfolio.city.country.id if portfolio.city.present? && portfolio.city.country.present?
end
text :country_name, :more_like_this => true do |portfolio|
  portfolio.country.name if portfolio.city.present? && portfolio.city.country.present?
end
integer :discipline_ids, :references => Discipline, :multiple => true
text :discipline_names, :more_like_this => true do |portfolio|
  portfolio.disciplines.map { |discipline| discipline.name }
end
integer :tag_ids, :references => Tag, :multiple => true
text :tag_names, :more_like_this => true do |portfolio|
  portfolio.tags.map { |tag| tag.name }
end
integer :portfolio_edit_ids, :references => PortfolioEdit, :multiple => true
text :portfolio_edit_titles, :more_like_this => true do |portfolio|
  portfolio.portfolio_edits.map { |edit| edit.title }
end
string :sort_name do
  name.downcase
end

结尾

在我的控制器中:

search = Sunspot.search(Portfolio) do |query|

query.keywords params[:keywords], :fields => [:name, :url, :description] if params[:keywords].present?

end

我的 schema.xml

   <?xml version="1.0" encoding="UTF-8"?>

<schema name="sunspot" version="1.0">
  <types>

    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="string" class="solr.StrField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="tdouble" class="solr.TrieDoubleField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="rand" class="solr.RandomSortField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="text" class="solr.TextField" omitNorms="false">
      <analyzer type="index">
          <tokenizer class="solr.StandardTokenizerFactory"/>
          <filter class="solr.StandardFilterFactory"/>
          <filter class="solr.LowerCaseFilterFactory"/>
          <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15"/>
        </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.PorterStemFilterFactory"/>
        <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="true"/>
      </analyzer>
    </fieldType>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="boolean" class="solr.BoolField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="date" class="solr.DateField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="sdouble" class="solr.SortableDoubleField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="sfloat" class="solr.SortableFloatField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="sint" class="solr.SortableIntField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="slong" class="solr.SortableLongField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="tint" class="solr.TrieIntField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="tfloat" class="solr.TrieFloatField" omitNorms="true"/>
    <!-- *** This fieldType is used by Sunspot! *** -->
    <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true"/>
  </types>
  <fields>

    <!-- *** This field is used by Sunspot! *** -->
    <field name="id" stored="true" type="string" multiValued="false" indexed="true"/>
    <!-- *** This field is used by Sunspot! *** -->
    <field name="type" stored="false" type="string" multiValued="true" indexed="true"/>
    <!-- *** This field is used by Sunspot! *** -->
    <field name="class_name" stored="false" type="string" multiValued="false" indexed="true"/>
    <!-- *** This field is used by Sunspot! *** -->
    <field name="text" stored="false" type="string" multiValued="true" indexed="true"/>
    <!-- *** This field is used by Sunspot! *** -->
    <field name="lat" stored="true" type="tdouble" multiValued="false" indexed="true"/>
    <!-- *** This field is used by Sunspot! *** -->
    <field name="lng" stored="true" type="tdouble" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="random_*" stored="false" type="rand" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="_local*" stored="false" type="tdouble" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_text" stored="false" type="text" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_texts" stored="true" type="text" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_b" stored="false" type="boolean" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_bm" stored="false" type="boolean" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_bs" stored="true" type="boolean" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_bms" stored="true" type="boolean" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_d" stored="false" type="date" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_dm" stored="false" type="date" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ds" stored="true" type="date" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_dms" stored="true" type="date" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_e" stored="false" type="sdouble" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_em" stored="false" type="sdouble" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_es" stored="true" type="sdouble" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ems" stored="true" type="sdouble" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_f" stored="false" type="sfloat" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_fm" stored="false" type="sfloat" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_fs" stored="true" type="sfloat" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_fms" stored="true" type="sfloat" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_i" stored="false" type="sint" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_im" stored="false" type="sint" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_is" stored="true" type="sint" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ims" stored="true" type="sint" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_l" stored="false" type="slong" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_lm" stored="false" type="slong" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ls" stored="true" type="slong" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_lms" stored="true" type="slong" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_s" stored="false" type="string" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_sm" stored="false" type="string" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ss" stored="true" type="string" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_sms" stored="true" type="string" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_it" stored="false" type="tint" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_itm" stored="false" type="tint" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_its" stored="true" type="tint" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_itms" stored="true" type="tint" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ft" stored="false" type="tfloat" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ftm" stored="false" type="tfloat" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_fts" stored="true" type="tfloat" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ftms" stored="true" type="tfloat" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_dt" stored="false" type="tdate" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_dtm" stored="false" type="tdate" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_dts" stored="true" type="tdate" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_dtms" stored="true" type="tdate" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_textv" stored="false" termVectors="true" type="text" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_textsv" stored="true" termVectors="true" type="text" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_et" stored="false" termVectors="true" type="tdouble" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_etm" stored="false" termVectors="true" type="tdouble" multiValued="true" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_ets" stored="true" termVectors="true" type="tdouble" multiValued="false" indexed="true"/>
    <!-- *** This dynamicField is used by Sunspot! *** -->
    <dynamicField name="*_etms" stored="true" termVectors="true" type="tdouble" multiValued="true" indexed="true"/>
  </fields>

  <uniqueKey>id</uniqueKey>
  <!-- field for the QueryParser to use when an explicit fieldname is absent -->
  <defaultSearchField>text</defaultSearchField>
  <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
  <solrQueryParser defaultOperator="AND"/>

</schema>
4

1 回答 1

1

Mayby try my schema.xml?

https://gist.github.com/xdsemx/5038249

I had a similar problem

于 2013-07-26T14:42:08.227 回答