Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带轮胎的弹性搜索';t包括带有STI型号的自定义分析仪_Ruby On Rails_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Tire_Sti - Fatal编程技术网 elasticsearch,tire,sti,Ruby On Rails,elasticsearch,Tire,Sti" /> elasticsearch,tire,sti,Ruby On Rails,elasticsearch,Tire,Sti" />

Ruby on rails 带轮胎的弹性搜索';t包括带有STI型号的自定义分析仪

Ruby on rails 带轮胎的弹性搜索';t包括带有STI型号的自定义分析仪,ruby-on-rails,elasticsearch,tire,sti,Ruby On Rails,elasticsearch,Tire,Sti,我有一个STI模型,我想用ElasticSearch和Tire进行搜索。我遇到的问题是,当Tire创建映射时,它似乎忽略了第二个模型的自定义分析器。下面是我的模型的一个例子 class Account < ActiveRecord::Base attr_accessible :name, :type include Tire::Model::Search include Tire::Model::Callbacks tire.settings :analysis =&g

我有一个STI模型,我想用ElasticSearch和Tire进行搜索。我遇到的问题是,当Tire创建映射时,它似乎忽略了第二个模型的自定义分析器。下面是我的模型的一个例子

class Account < ActiveRecord::Base
  attr_accessible :name, :type

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.settings :analysis => {
          :analyzer => {
          "custom_search_analyzer" => {
              "tokenizer" => "keyword",
              "filter" => "lowercase"
          },
          "custom_index_analyzer" => {
              "tokenizer" => "keyword",
              "filter" => ["lowercase","substring"]
          }
      },
      :filter => {
          :substring => {
              "type" => "nGram",
              "min_gram" => 1,
              "max_gram" => 20
          }
      }
  } do
    mapping do
      indexes :id, :type => 'integer', :include_in_all => false
      indexes :name, :type => 'string', :search_analyzer => :custom_search_analyzer,     :index_analyzer=>:custom_index_analyzer
    end
  end

  def to_indexed_json
    hash = {}
    hash[:id] = id
    hash[:name] = name
    hash.to_json
  end
end

class StandardAccount < Account
  tire.index_name 'accounts'
end

class SuperAccount < Account
  tire.index_name 'accounts'
end
我得到:

{
  "accounts" : {
    "account" : {
      "properties" : {
        "id" : {
          "type" : "integer",
          "include_in_all" : false
        },
        "name" : {
          "type" : "string",
          "index_analyzer" : "custom_index_analyzer",
          "search_analyzer" : "custom_search_analyzer"
        }
      }
    },
    "standard_account" : { 
      "properties" : {
        "id" : {
          "type" : "long"
        }
        "name" : {
          "type" : "string"
        }
      }
    },
    "super_account" : {
      "properties" : {
        "id" : {
          "type" : "long"
        }
        "name" : {
          "type" : "string"
        }
      }
    }
  }
}

即使我将映射声明移动到继承的类中,似乎也只有创建的第一个模型能够获取额外的选项。我可以通过ElasticSearch手动创建索引,但我想知道是否有办法用Tire来创建索引?或者我的某些设置不正确

您可能已经找到了答案,但我认为这可能会帮助您或其他有相同问题的人:

-弗拉德

{
  "accounts" : {
    "account" : {
      "properties" : {
        "id" : {
          "type" : "integer",
          "include_in_all" : false
        },
        "name" : {
          "type" : "string",
          "index_analyzer" : "custom_index_analyzer",
          "search_analyzer" : "custom_search_analyzer"
        }
      }
    },
    "standard_account" : { 
      "properties" : {
        "id" : {
          "type" : "long"
        }
        "name" : {
          "type" : "string"
        }
      }
    },
    "super_account" : {
      "properties" : {
        "id" : {
          "type" : "long"
        }
        "name" : {
          "type" : "string"
        }
      }
    }
  }
}