1

私はsolrとEdgeNGramを使用してオートコンプリート機能に取り組んでおり、多値フィールドを作成します

ここにschema.xmlの詳細があります

.....

<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <!--tokenizer class="solr.KeywordTokenizerFactory"/-->
    <!--tokenizer class="solr.NGramTokenizerFactory" minGramSize="2" maxGramSize="50"/-->
    <tokenizer class="solr.WhitespaceTokenizerFactory" minGramSize="2" maxGramSize="50"/>
    <filter class="solr.LowerCaseFilterFactory"/>
   <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
 </analyzer>
 <analyzer type="query">
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
   <filter class="solr.LowerCaseFilterFactory"/>
 </analyzer>
</fieldType>

.......

<dynamicField name="*_ac" type="autocomplete" indexed="true"  stored="true" multiValued="true" />

それが私がユーザーモデルを宣言する方法です

class User < ActiveRecord::Base attr_accessible :email, :name

searchable do text :email text :name autocomplete :text_ac, :as => :text_ac, :multiple => true do [self.email,self.name] end end

終わり

そして、私が探しているのは、「ヒット」値を取得する方法です

私がsolrをクエリしているとき

Sunspot.search(User, Post) do with(:user_id, 1);
 adjust_solr_params do |p| p[:q] = 'text_ac:"some s"'; p[:fq] = '' end 
end.results

インスタンスを取得できます (ユーザー、投稿)

、しかし、ヒットした値を取得するにはどうすればよいですか - 複数値フィールドの正確な行 - 配列の要素

4

0 に答える 0