0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

more_like_thisを使った検索

Posted at

検索Query

{
    "query": {
        "more_like_this" : {
            "fields" : ["title", "photos.description"],
            "like" : "ライダー",
            "min_term_freq" : 1,
            "max_query_terms" : 12
        }
    }
}

前の資料にはidsというパラメータがあったようですが、最新のドキュメント見たらなかったので、その辺りの仕様が変わったのでしょうかね。

テストデータ

 76       let(:album1) { create(:album, title: '映画仮面ライダーとホゲホゲ星人の戦い', user: user) }
 77       let(:photo1_1) { create(:photo, description: 'ホゲホゲ星人との場面1です。これは仮面ライダーがXXしているところです',
 78                               album: album1, user: user) }
 79       let(:photo1_2) { create(:photo, description: 'ホゲホゲ星人との場面2',
 80                                album: album1, user: user) }
 81       let(:album2) { create(:album, title: 'ターミネータVS仮面ライダー', user: user) }
 82       let(:album3) { create(:album, title: '鉄仮面のライダー', user: user) }
 83       let(:album4) { create(:album, title: 'ライダーが仮面を被ったら', user: user) }
 84       let(:album5) { create(:album, title: '仮面を被ったライダーの写真', user: user) }
 85       let(:photo5_1) { create(:photo, description: 'ライダーの写真',
 86                               album: album5, user: user) }
 87       let(:album6) { create(:album, title: 'ライダーの写真集', user: user) }
 88       let(:photo6_1) { create(:photo, description: '仮面をつけたライダーも写ってます',
 89                               album: album6, user: user) }
 90

結果

keywordを「ライダー」で検索した場合

鉄仮面のライダー: 0.6458774
ライダーが仮面を被ったら: 0.6458774
ライダーの写真集: 0.6458774
仮面を被ったライダーの写真: 0.5764006
映画仮面ライダーとホゲホゲ星人の戦い: 0.43577272
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?