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

Back to archive index

Hiroyuki Sato hiroy****@gmail*****
2015年 7月 6日 (月) 11:51:46 JST


佐藤です。
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



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