[groonga-dev,03349] Re: highlight_htmlについて教えてください。

Back to archive index

Hiroyuki Sato hiroy****@gmail*****
2015年 7月 8日 (水) 17:30:07 JST


佐藤です。

ひとまずRuby側でハイライトをするようにしました。
しかしノーマライズを考慮していないので、検索文字がgroongaで
titleやintruductionに「Goroonga」とかあった場合はハイライトされません。

groonga側でできるといいなと思います。なにか良い方法があれば教えて下さい。


余談ですがhighlight_html次のようなクエリを投げると
title, introductionそれぞれのhaskell, groongaがハイライトされますね。
そういう動作なのだと思いますが動作としては次のようなものかなと思っておりました。

 titleは、Groongaがハイライトされる
 intruductionは、Haskellがハイライトされる

select --output_columns
'_key,highlight_html(title),highlight_html(introduction)' --table Book
--query 'title:@Groonga OR introduction:@haskell' --command_version 2

groonga /tmp/aa.db < /tmp/bb | jq .

[

  [

    0,

    1436343998.75183,

    0.0034492015838623

  ],

  [

    [

      [

        4

      ],

      [

        [

          "_key",

          "ShortText"

        ],

        [

          "highlight_html",

          "null"

        ],

        [

          "highlight_html",

          "null"

        ]

      ],

      [

        "ISBN2",

        "<span class=\"keyword\">Groonga</span>入門",

        "決定版<span class=\"keyword\">Groonga</span>入門書"

      ],

      [

        "ISBN6",

        "Learning <span class=\"keyword\">Groonga</span>",

        "Self study series"

      ],

      [

        "ISBN1",

        "<span class=\"keyword\">Haskell</span>入門",

        "決定版<span class=\"keyword\">Haskell</span>入門書"

      ],

      [

        "ISBN7",

        "<span class=\"keyword\">Haskell</span> programmingtutorial",

        "<span class=\"keyword\">Haskell</span> <span
class=\"keyword\">haskell</span> <span
class=\"keyword\">haskell</span>"

      ]

    ]

  ]

]





2015年7月6日 11:51 Hiroyuki Sato <hiroy****@gmail*****>:
> 佐藤です。
> highlight_htmlについて教えてください。
>
> ・問題点
>  (1) groonga-clientで二つのカラムに対してhightlight_htmlを使った場合
>   (2) どちらか一つのカラムしか出力されない。
>
> ・質問
>   (1) 二つのカラムとして取り扱う方法を知りたい。
>   (2) SQLのasのようなカラムに別名をつけることは可能でしょうか?
>
> ・目的
>  (1) Groongaで検索してマッチした文字列にタグをつけたい。
>  (2) highlight_htmlにこだわってはいない。
>  (3) highlight_fullは指定するパラメータが多かったのでhightlight_htmlを使用
>
> ・例とするテーブル
>  (1) 書籍テーブル
>   (2) title(タイトル),introduction(紹介文)という二つの文字列を保持している。
>
> ・検索クエリ
>   (1) 検索対象: タイトル、紹介文のいずれかに指定した文字列がある場合
>
> よろしくお願いします。
>
> # 本テーブル
> table_create --name Book --flags TABLE_HASH_KEY --key_type ShortText
> column_create --table Book --name title --type ShortText
> column_create --table Book --name introduction --type ShortText
>
> # インデックス作成
> table_create --name BookKeyword --flags TABLE_PAT_KEY|KEY_NORMALIZE
> --key_type ShortText --default_tokenizer TokenMecab
> column_create --table BookKeyword --name title_index --flags
> COLUMN_INDEX|WITH_POSITION --type Book --source title
> column_create --table BookKeyword --name introduction_index --flags
> COLUMN_INDEX|WITH_POSITION --type Book --source introduction
>
> load --table Book
> [
> {"_key":"ISBN1","title":"Haskell入門","introduction":"決定版Haskell入門書"},
> {"_key":"ISBN2","title":"Groonga入門","introduction":"決定版Groonga入門書"},
> {"_key":"ISBN3","title":"できるErlang","introductin":"だれでもErlangが書けるようになる"},
> {"_key":"ISBN4","title":"Go言語入門","introduction":"Rob Pikeによる入門書"},
> {"_key":"ISBN5","title":"三日でできるScala","introduction":"ひとりでできるシリーズ"},
> {"_key":"ISBN6","title":"Learning Groonga","introduction":"Self study series"}
> {"_key":"ISBN7","title":"Haskell programming
> tutorial","introduction":"Haskell haskell haskell"}
> ]
>
>
> rubyスクリプト
>
> require 'groonga/client'
> require 'pp'
>
> client = Groonga::Client.open({:host => 'localhost',
>                                :port => 10041,
>                                :protocol => 'http'})
>
> ret = client.select({:table => 'Book',
>                :query => 'groonga',
>                :match_columns => 'title,introduction',
> #               :output_columns => 'title,introduction',
>                :output_columns =>
> 'highlight_html(title),highlight_html(introduction)',
>                :command_version => 2})
>
>
> if( ret.kind_of?(Groonga::Client::Response::Error) )
>   puts ret.to_s
>   exit 1
> end
>
>
> ret.records.each do |r|
>   pp r
> end
>
>
>
> highlight_htmlなしの場合
>
> ruby t.rb
> {"title"=>"Groonga入門", "introduction"=>"決定版Groonga入門書"}
> {"title"=>"Learning Groonga", "introduction"=>"Self study series"}
>
>
> highlight_htmlあり場合
>
> {"highlight_html"=>"決定版<span class=\"keyword\">Groonga</span>入門書"}
> {"highlight_html"=>"Self study series"}
>
>
> --
> Hiroyuki Sato



-- 
Hiroyuki Sato



groonga-dev メーリングリストの案内
Back to archive index