7.15.11. html_untag
¶
7.15.11.1. 概要¶
html_untag
はHTMLタグをHTMLから除去したテキストを出力します。
html_untag
は output_columns で説明している --output_columns
で使います。
7.15.11.2. 構文¶
html_untag
は引数を一つだけとります。 それは html
です。
html_untag(html)
7.15.11.3. 必要条件¶
html_untag
を使うにはGroonga 3.0.5以降が必要です。
html_untag
を使うには コマンドバージョン 2以降を使う必要があります。
7.15.11.4. 使い方¶
使い方を示すために使うスキーマ定義とサンプルデータは以下の通りです。
サンプルスキーマ:
実行例:
table_create WebClips TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create WebClips content COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
サンプルデータ:
実行例:
load --table WebClips
[
{"_key": "http://groonga.org", "content": "groonga is <span class='emphasize'>fast</span>"},
{"_key": "http://mroonga.org", "content": "mroonga is <span class=\"emphasize\">fast</span>"},
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
カラムの本文からHTMLタグを除去する html_untag
関数の簡単な例はこちらです。
実行例:
select WebClips --output_columns "html_untag(content)" --command_version 2
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 2
# ],
# [
# [
# "html_untag",
# null
# ]
# ],
# [
# "groonga is fast"
# ],
# [
# "mroonga is fast"
# ]
# ]
# ]
# ]
上記クエリを実行すると、"class" 属性つきの "span" タグが除去されているのがわかります。html_untag
関数を使うのには --command_version 2
を指定しなければならないことに注意してください。
7.15.11.5. 引数¶
必須の引数は1つです。
7.15.11.5.1. html
¶
タグを取り除きたいHTMLを指定します。
7.15.11.6. 戻り値¶
html_untag
はHTMLテキストからHTMLタグを除去したタグなしのテキストを返します。