1

別のモジュールから特定のモデルの設定とマッピングを追加したいと考えています。それは可能ですか?はいの場合、これを行う方法を教えてください。私はこれを試しました:

記事のモデル:

class Article < ActiveRecord::Base
  include SearchArticle
end

新しいモジュール:

module SearchArticle

  include Tire::Model::Search
  settings :analyzer => {
            :custom_analyzer => {
              'tokenizer' => 'uax_url_email'
            }
    } do
    mapping do
      indexes :name, :boost => 10
      indexes :email, :analyzer => 'custom_analyzer', :boost => 10
    end
  end

end

しかし、インデックスは作成されていません。次のエラーが表示されます。

[2012-10-16 11:42:38,023][WARN ][cluster.metadata         ] [Inza] [search_article] failed to create
org.elasticsearch.index.mapper.MapperParsingException: mapping [search_article]
at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:262)
at org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:208)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

Caused by: org.elasticsearch.index.mapper.MapperParsingException: Analyzer [custom_analyzer] not found for field [email]
at org.elasticsearch.index.mapper.core.TypeParsers.parseField(TypeParsers.java:76)
at org.elasticsearch.index.mapper.core.StringFieldMapper$TypeParser.parse(StringFieldMapper.java:124)
at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:261)
at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:217)
at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:161)
at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:364)
at org.elasticsearch.index.mapper.MapperService.add(MapperService.java:186)
at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:259)
... 4 more
4

2 に答える 2

3

はい、それは可能ですが、私が質問で行った方法ではありません。タイヤの宝石の所有者であるKarmiが提案した答えは次のとおりです。

完全な回答については、これを参照してください

module Searchable

  def self.included(base)

    p "Included in #{base}"

    base.class_eval do
      include Tire::Model::Search

      tire do
        mapping do
          indexes :title,   type: 'string', analyzer: 'snowball'
        end
      end
    end
  end
end

class Article < ActiveRecord::Base
  include Searchable
end
于 2012-10-17T02:51:49.237 に答える
0
module SearchArticle
  include Tire::Model::Search
  include ActiveSupport::Concern

  included do
    settings :analyzer => {
                :custom_analyzer => {
                  'tokenizer' => 'uax_url_email'
                }
        } do
        mapping do
          indexes :name, :boost => 10
          indexes :email, :analyzer => 'custom_analyzer', :boost => 10
        end
     end
  end
end
于 2012-10-16T12:04:16.103 に答える