0

私は問題を解決するために数時間を費やしました。誰かが私を助けてくれることを願っています。

まず、構造を説明するためのコードを次に示します。

class Company < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

  attr_accessible :name, :website, :addresses_attributes

  has_many :addresses, dependent: :destroy
  accepts_nested_attributes_for :addresses, allow_destroy: true

  after_touch() { tire.update_index }

  include_root_in_json = false

  mapping do
    indexes :name, boost: 10
    indexes :addresses do
      indexes :street
    end
  end

  def self.search(params)
    s = tire.search(load: true) do

    query do
      boolean do
        must { string params[:query] } if params[:query]
        must { term "addresses.street", params[:location] } if params[:location]
      end
    end

    s.results
  end

  def to_indexed_json
    to_json( include: { addresses: { only: [:street] } } )
  end
end


class Address < ActiveRecord::Base
  # Attributes
  attr_accessible :street

  # Associations
  belongs_to :company, touch: true
end

特定のストリート名の会社を検索しようとすると(電話Company.search({location: 'example_street_name', query: 'example_name'})をかけても結果が得られません)。

インデックス作成は私には問題ないようです。それはリクエストの1つです:

curl -X POST "http://localhost:9200/companies/company/1351" -d '{
  "created_at": "2012-12-29T13:41:17Z",
  "name": "test name",
  "updated_at": "2012-12-29T13:41:17Z",
  "website": "text.website.com",
  "addresses": [
    {
      "street": "test street name"
    }
  ]
}'

結果を得るために私は多くのことを試みました。何も機能しませんでした。基本的なことを見逃したに違いないようです。

4

1 に答える 1

2

term分析されていない「addresses.street」フィールドのクエリを使用しているため、小文字などの値を渡す必要があります。

matchクエリを使用してみてください。

于 2012-12-30T09:51:51.840 に答える