須藤様
お世話になります。内山です。
pg_score についてはご教示をいただきありがとうございます。
一旦、単語の出現数でスコアリングするアルゴリズムにしているのですが、
使ってみて、単語の出現回数だけではなく、YouTube の視聴回数と単語の出現回数の
ハイブリッドなアルゴリズムを考えました。
〇単語の出現回数を100をマックスとして取得した値
〇YouTube の視聴回数を視聴回数の最大値を参考に100にノーマライズした値
の和でスコアリングしようとしています。教えていただいた
構文に似せて書くと
moovle=# WITH v AS ( SELECT id, content FROM subtitled WHERE content &@~
( 'algorithm', null, '{scorer_tf_at_most( $index, 100 )}', null )
::pgroonga_full_text_search_condition_with_scorers
ORDER BY pgroonga_score( tableoid, ctid) + vc / ( 3346800846 / 2 ) * 100 DESC
OFFSET 0 LIMIT 60) SELECT id, array_to_json( content ) as c from v;
ERROR: pgroonga: query-condition: failed to parse scorer: <Lexicon56822456_0.index>[0]:
<scorer_tf_at_most( $index>: Syntax error: <scorer_tf_at_most(
Lexicon56822456_0.index[0]||>
とエラーになります。
WITH v AS ( SELECT id, content FROM subtitled WHERE content &@~
( 'algorithm', null, '{scorer_tf_at_most( $index), 100 }', null )
::pgroonga_full_text_search_condition_with_scorers
ORDER BY pgroonga_score( tableoid, ctid) + vc / ( 3346800846 / 2 ) * 100 DESC
OFFSET 0 LIMIT 60) SELECT id, array_to_json( content ) as c from v;
これだと、エラーしないのですが、大丈夫でしょうか。
( 3346800846 / 2 ) * 100 は、最大値の 1/2 で、100 にノーマライズ
しています。最大値は 200 になる可能性があります。
ご意見をいただければ幸いです。よろしくお願いします。
-----Original Message-----
From: groonga-dev <groon****@lists*****> On Behalf Of Kouhei Sutou
Sent: Tuesday, January 8, 2019 7:38 PM
To: groon****@lists*****
Subject: [groonga-dev,04721] Re: PGroonga における検索スコア
須藤です。
In <000201d4a562$16ba6780$442f3680$@mirror.ocn.ne.jp>
"[groonga-dev,04720] PGroonga における検索スコア" on Sun, 6 Jan 2019 10:49:40 +0900,
<toshio_uchiy****@mirro*****> wrote:
> ここで、ORDER BY 句では、PostgreSQL の関数を使って検索語
> algorithm の出現回数を計算しています。
出現回数pgroonga_score()で得られるので次のようにしてみてくだ
さい。
with v AS
( SELECT id, content FROM subtitled WHERE content &@~ 'algorithm'
ORDER BY pgroonga_score(tableoid, ctid) DESC OFFSET 0 LIMIT 100 ) SELECT id, array_to_json( v.content ) FROM v;
> PGroonga でも、全文検索する文章に依存したスコアリング方法は
> ないでしょうか。ただし、content 列は text 型の配列です。
pgroonga_score()がそれです。
https://pgroonga.github.io/ja/reference/functions/pgroonga-score.html
スコアリング方法は次のように
pgroonga_full_text_search_condition_with_scorersを使うとカス
タマイズできます。これは3回以上出現してもそれ以上カウントし
ない例です。
content &@~ ('algorithm', null, 'scorer_tf_at_most($index, 3)', null):pgroonga_full_text_search_condition_with_scorers
参考:
* https://pgroonga.github.io/ja/reference/operators/query-v2.html
* http://groonga.org/ja/docs/reference/scorer.html
--
須藤 功平 <kou****@clear*****>
株式会社クリアコード <https://www.clear-code.com/>
Groongaベースの全文検索システムを総合サポート:
http://groonga.org/ja/support/
データ処理ツールの開発:
https://www.clear-code.com/blog/2018/7/11.html
_______________________________________________
groonga-dev mailing list
groon****@lists*****
https://lists.osdn.me/mailman/listinfo/groonga-dev