ElasticSearchの同義語-Rails

キャノンモイヤー

Elasticsearch-railsgemでRubyon Railsを使用しており、同義語フィルターを使用しようとしています。私はガイダンスのためにここに投稿された質問に従いました(私の実装は同義語の部分を除いて期待どおりに機能します):

https://github.com/elastic/elasticsearch-rails/issues/63

これが私のコードです:

settings index: { number_of_shards: 1 },
    analysis: {
  filter: {
    synonym: {
      type: "synonym",
      ignore_case: true,
      synonyms:[
        "roller,wheel"
      ]
    }
  },
  analyzer: {
    synonym: {
      tokenizer: "whitespace",
      filter: ["synonym", "lowercase", "stop", "snowball"]
    }
  }
} do
  mappings dynamic: 'false' do
    indexes :name, analyzer: 'synonym'
    indexes :status, analyzer: 'english'
    #indexes :description, analyzer: 'english' 
    indexes :part_number, analyzer: 'english'
    indexes :text, analyzer: 'english'
    indexes :normal_model, type: 'nested' do
      indexes :name, analyzer: 'english'
      indexes :number, analyzer: 'english'
      indexes :machine_type, analyzer: 'english'

      indexes :normal_brand, type: 'nested' do
        indexes :name, analyzer: 'english'
      end
    end
  end
end

これが私のコントローラーアクションで検索する私のコードです:

 @products = Product.search(
        query: { 
          query_string: {
           #query: "*manual* AND status:\"Disabled\""
           #fields: ["normal_model.name", "normal_brand.name"],
            query: "*#{params[:q]}* AND status:\"Viewable On Website & Backend\""

            #query:  "*" + params[:q]+ "*"
          }
        }
      )

名前フィールドが「wheel」に設定されているレコードがありますが、「roller」を検索すると、結果が0になり、エラーは発生しません。この時点で、「wheel」という名前のレコードを取得する予定です。また、インデックスを完全に削除し、インデックスが削除されてインデックスが再作成されたことを確認して、インデックスの問題に直面していないことを確認しました。現時点ではどうしたらよいかわかりません。どんな助けでもいただければ幸いです。

また、これが私のas_indexed_jsonメソッドです

def as_indexed_json(options={})
    as_json(
        only: [:name, :description, :part_number, :url_key, :image, :price, :shipping, :warranty, :eta, :status, :sku],
        include: { 
            normal_model: { only: [:name, :number, :machine_type],
                include: { 
                    normal_brand: { only: :name}
                }
            }
        }
    )
 end

ありがとう

更新:

また、コントローラーの検索アクションに次のコード(以下の回答で提案)を追加してみました。

fields: ['name', '_all'],
query: "#{params[:q]} AND status:\"Viewable On Website & Backend\""

検索アクションで元のコードの代わりにこのコードを配置しましたが、「ローラー」という単語を検索しても結果が得られませんでした。「wheel」を検索していくつかの結果を取得することはできますが、指定された同義語ではうまくいきません。

更新:

これは、製品名フィールドに「wheel」という単語が含まれているドキュメントの1つです。

{
  "_index" : "products",
  "_type" : "product",
  "_id" : "288374",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "name" : "wheel",
    "description" : "This is the O.E.M. wheel for the Spirit CE800 Elliptical with a model number 800049.",
    "shipping" : null,
    "sku" : "58511",
    "eta" : "3 to 5 Business Days",
    "warranty" : "1 Year",
    "part_number" : "N/A",
    "url_key" : "spirit-ce800-elliptical-model-800049-lubricant",
    "price" : 19.99,
    "image" : "noimage-main_20837.jpg",
    "status" : "Viewable On Website & Backend",
    "normal_model" : {
      "name" : "CE800",
      "number" : "800049",
      "machine_type" : "Elliptical",
      "normal_brand" : {
        "name" : "Spirit"
      }
    }
  }
}

更新:

これが私の製品マッピングです

{
  "products" : {
    "mappings" : {
      "product" : {
        "dynamic" : "false",
        "properties" : {
          "name" : {
            "type" : "text",
            "analyzer" : "synonym"
          },
          "normal_model" : {
            "type" : "nested",
            "properties" : {
              "machine_type" : {
                "type" : "text",
                "analyzer" : "english"
              },
              "name" : {
                "type" : "text",
                "analyzer" : "english"
              },
              "normal_brand" : {
                "type" : "nested",
                "properties" : {
                  "name" : {
                    "type" : "text",
                    "analyzer" : "english"
                  }
                }
              },
              "number" : {
                "type" : "text",
                "analyzer" : "english"
              }
            }
          },
          "part_number" : {
            "type" : "text",
            "analyzer" : "english"
          },
          "status" : {
            "type" : "text",
            "analyzer" : "english"
          },
          "text" : {
            "type" : "text",
            "analyzer" : "english"
          }
        }
      }
    }
  }
}
ジュリアン・タッシン

クエリでは、_allフィールドを検索しています。(query_stringのデフォルトの動作)。

シノニムアナライザーを使用するには、名前フィールドでも検索する必要があります。このような :

  @products = Product.search(
    query: { 
      query_string: {
       fields: ['name', '_all'],
       query: "#{params[:q]} AND status:\"Viewable On Website & Backend\""
      }
    }
  )

params[:q]「roller」が含まれている場合「wheel」という単語を含むレコードを取得します

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

TOP 一覧

  1. 1

    三項演算子良い練習の代わりとしてOptional.ofNullableを使用していますか?

  2. 2

    STSでループプロセス「クラスパス通知の送信」のループを停止する方法

  3. 3

    Spring Boot Filter is not getting invoked if remove @component in fitler class

  4. 4

    セレンのモデルダイアログからテキストを抽出するにはどうすればよいですか?

  5. 5

    tkinterウィンドウを閉じてもPythonプログラムが終了しない

  6. 6

    Ansibleで複数行のシェルスクリプトを実行する方法

  7. 7

    Python / SciPyのピーク検出アルゴリズム

  8. 8

    画像変更コードを実行してもボタンの画像が変更されない

  9. 9

    ビュー用にサイズ変更した後の画像の高さと幅を取得する方法

  10. 10

    VisualStudioコードの特異点/ドッカー画像でPythonインタープリターを使用するにはどうすればよいですか?

  11. 11

    Three.js indexed BufferGeometry vs. InstancedBufferGeometry

  12. 12

    __init__。pyファイルの整理中に循環インポートエラーが発生しました

  13. 13

    二次導関数を数値計算するときの大きな誤差

  14. 14

    値間の一致を見つける最も簡単な方法は何ですか

  15. 15

    androidsoongビルドシステムによるネイティブコードカバレッジ

  16. 16

    Reactでclsxを使用する方法

  17. 17

    How to access json value by key value in freemarker?

  18. 18

    エンティティIDを含む@RequestBody属性をSpringの対応するエンティティに変換します

  19. 19

    PyTesseractを使用した背景色のため、スクリーンショットからテキストを読み取ることができません

  20. 20

    Using Angular's UI-router, how can we make sure the new version of the html partial views are used, rather than the cached version?

  21. 21

    symfonyエラーサーバーが404NotFoundを返しました

ホットタグ

アーカイブ