<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>8.11.10. sub_filter — groonga v3.0.5ドキュメント</title> <link rel="stylesheet" href="../../_static/groonga.css" type="text/css" /> <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../../', VERSION: '3.0.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../../_static/jquery.js"></script> <script type="text/javascript" src="../../_static/underscore.js"></script> <script type="text/javascript" src="../../_static/doctools.js"></script> <script type="text/javascript" src="../../_static/translations.js"></script> <link rel="shortcut icon" href="../../_static/favicon.ico"/> <link rel="top" title="groonga v3.0.5ドキュメント" href="../../index.html" /> <link rel="up" title="8.11. 関数" href="../function.html" /> <link rel="next" title="8.12. インデックス構築" href="../indexing.html" /> <link rel="prev" title="8.11.9. snippet_html" href="snippet_html.html" /> </head> <body> <div class="header"> <h1 class="title"> <a id="top-link" href="../../index.html"> <span class="project">groonga</span> <span class="separator">-</span> <span class="description">オープンソースのカラムストア機能付き全文検索エンジン</span> </a> </h1> <div class="other-language-links"> <ul> <li><a href="../../../../en/html/reference/functions/sub_filter.html"><img src="../../_static/us.png" alt="English">English page</a></li> </ul> </div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="総合索引" accesskey="I">索引</a></li> <li class="right" > <a href="../indexing.html" title="8.12. インデックス構築" accesskey="N">次へ</a> |</li> <li class="right" > <a href="snippet_html.html" title="8.11.9. snippet_html" accesskey="P">前へ</a> |</li> <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../function.html" accesskey="U">8.11. 関数</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="sub-filter"> <h1>8.11.10. sub_filter<a class="headerlink" href="#sub-filter" title="このヘッドラインへのパーマリンク">¶</a></h1> <div class="section" id="summary"> <h2>8.11.10.1. 概要<a class="headerlink" href="#summary" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> は <tt class="docutils literal"><span class="pre">filter_string</span></tt> を <tt class="docutils literal"><span class="pre">scope</span></tt> のコンテキストで評価します。</p> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> は <a class="reference internal" href="../commands/select.html"><em>select</em></a> コマンドの <tt class="docutils literal"><span class="pre">--filter</span></tt> 内でのみ指定できます。</p> </div> <div class="section" id="syntax"> <h2>8.11.10.2. 構文<a class="headerlink" href="#syntax" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> は2つの引数が必要です。 <tt class="docutils literal"><span class="pre">scope</span></tt> と <tt class="docutils literal"><span class="pre">filter_string</span></tt> です。</p> <div class="highlight-none"><div class="highlight"><pre>sub_filter(scope, filter_string) </pre></div> </div> </div> <div class="section" id="usage"> <h2>8.11.10.3. 使い方<a class="headerlink" href="#usage" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>使い方を示すために使うスキーマ定義とサンプルデータは以下の通りです。</p> <p>サンプルスキーマ:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create Comment TABLE_PAT_KEY UInt32 # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Comment name COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Comment content COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] table_create Blog TABLE_PAT_KEY ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Blog title COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Blog content COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Blog comments COLUMN_VECTOR Comment # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Comment blog_comment_index COLUMN_INDEX Blog comments # [[0, 1337566253.89858, 0.000355720520019531], true] table_create Lexicon TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Lexicon comment_content COLUMN_INDEX|WITH_POSITION Comment content # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Lexicon comment_name COLUMN_INDEX|WITH_POSITION Comment name # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Lexicon blog_content COLUMN_INDEX|WITH_POSITION Blog content # [[0, 1337566253.89858, 0.000355720520019531], true] </pre></div> </div> <p>サンプルデータ:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>load --table Comment [ {"_key": 1, "name": "A", "content": "groonga"}, {"_key": 2, "name": "B", "content": "groonga"}, {"_key": 3, "name": "C", "content": "rroonga"}, {"_key": 4, "name": "A", "content": "mroonga"}, ] # [[0, 1337566253.89858, 0.000355720520019531], 4] load --table Blog [ {"_key": "groonga's blog", "content": "content of groonga's blog", comments: [1, 2, 3]}, {"_key": "mroonga's blog", "content": "content of mroonga's blog", comments: [2, 3, 4]}, {"_key": "rroonga's blog", "content": "content of rroonga's blog", comments: [3]}, ] # [[0, 1337566253.89858, 0.000355720520019531], 3] </pre></div> </div> <dl class="docutils"> <dt>ブログのエントリを抽出する <tt class="docutils literal"><span class="pre">sub_filter</span></tt> 関数の使用例です。</dt> <dd><p class="first last">ユーザー'A'のコメント</p> </dd> </dl> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Blog --output_columns _key --filter "comments.name @ \"A\" && comments.content @ \"groonga\"" # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ] # ], # [ # "groonga's blog" # ], # [ # "mroonga's blog" # ] # ] # ] # ] </pre></div> </div> <p>上記のクエリを実行すると、"groonga's blog"だけでなく、"mroonga's blog"もマッチします。ユーザー"A"は"mroonga's blog"に対しては"groonga"に言及していないので、これは意図していない結果です。</p> <p>sub_filterなしでは、以下の条件が満たされます。</p> <ul class="simple"> <li><p class="first">すくなくとも一つはユーザー"A"がコメントしたレコードがある。</p> </li> <li><p class="first">すくなくとも一つは"groonga"について言及したレコードがある。</p> </li> </ul> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Blog --output_columns _key --filter 'sub_filter(comments, "name @ \\"A\\" && content @ \\"groonga\\"")' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ] # ], # [ # "groonga's blog" # ] # ] # ] # ] </pre></div> </div> <p>一方、上記のクエリは意図した結果を返します。これは、sub_filterの引数がcommentsカラムのコンテキストで評価されるからです。</p> <p>sub_filterは以下の条件が満たされていることを要求します。</p> <ul class="simple"> <li><p class="first">ユーザー"A"が"groonga"について言及しているレコードがある。</p> </li> </ul> </div> <div class="section" id="parameters"> <h2>8.11.10.4. 引数<a class="headerlink" href="#parameters" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>必須引数は二つあります。 <tt class="docutils literal"><span class="pre">scope</span></tt> と <tt class="docutils literal"><span class="pre">filter_string</span></tt> です。</p> <div class="section" id="scope"> <h3>8.11.10.4.1. <tt class="docutils literal"><span class="pre">scope</span></tt><a class="headerlink" href="#scope" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>It specifies a column of the table that is specified by <tt class="docutils literal"><span class="pre">table</span></tt> parameter in <tt class="docutils literal"><span class="pre">select</span></tt>. <tt class="docutils literal"><span class="pre">filter_string</span></tt> is evaluated in the column context. It means that <tt class="docutils literal"><span class="pre">filter_string</span></tt> is evaluated like <tt class="docutils literal"><span class="pre">select</span> <span class="pre">--table</span> <span class="pre">TYPE_OF_THE_COLUMN</span> <span class="pre">--filter</span> <span class="pre">FILTER_STRING</span></tt>.</p> <p>The specified column type must be a table. In other words, the column type must be reference type.</p> <p><tt class="docutils literal"><span class="pre">select</span></tt> コマンドの <tt class="docutils literal"><span class="pre">table</span></tt> 引数については <em class="xref std std-ref">select-table</em> を参照してください。</p> </div> <div class="section" id="filter-string"> <h3>8.11.10.4.2. <tt class="docutils literal"><span class="pre">filter_string</span></tt><a class="headerlink" href="#filter-string" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><a class="reference internal" href="../grn_expr/script_syntax.html"><em>スクリプト構文</em></a> の検索条件を指定します。これは <tt class="docutils literal"><span class="pre">scope</span></tt> のコンテキストで評価されます。</p> </div> </div> <div class="section" id="return-value"> <h2>8.11.10.5. 戻り値<a class="headerlink" href="#return-value" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> returns whether any record is matched or not. If one or more records are matched, it returns <tt class="docutils literal"><span class="pre">true</span></tt>. Otherwise, it returns <tt class="docutils literal"><span class="pre">false</span></tt>.</p> </div> <div class="section" id="see-also"> <h2>8.11.10.6. 参考<a class="headerlink" href="#see-also" title="このヘッドラインへのパーマリンク">¶</a></h2> <ul class="simple"> <li><a class="reference internal" href="../commands/select.html"><em>select</em></a></li> <li><a class="reference internal" href="../grn_expr/script_syntax.html"><em>スクリプト構文</em></a></li> </ul> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../../index.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">8.11.10. sub_filter</a><ul> <li><a class="reference internal" href="#summary">8.11.10.1. 概要</a></li> <li><a class="reference internal" href="#syntax">8.11.10.2. 構文</a></li> <li><a class="reference internal" href="#usage">8.11.10.3. 使い方</a></li> <li><a class="reference internal" href="#parameters">8.11.10.4. 引数</a><ul> <li><a class="reference internal" href="#scope">8.11.10.4.1. <tt class="docutils literal"><span class="pre">scope</span></tt></a></li> <li><a class="reference internal" href="#filter-string">8.11.10.4.2. <tt class="docutils literal"><span class="pre">filter_string</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#return-value">8.11.10.5. 戻り値</a></li> <li><a class="reference internal" href="#see-also">8.11.10.6. 参考</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="snippet_html.html" title="前の章へ">8.11.9. snippet_html</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="../indexing.html" title="次の章へ">8.12. インデックス構築</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../../_sources/reference/functions/sub_filter.txt" rel="nofollow">ソースコードを表示</a></li> </ul> <div id="searchbox" style="display: none"> <h3>クイック検索</h3> <form class="search" action="../../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="検索" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> モジュール、クラス、または関数名を入力してください </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="総合索引" >索引</a></li> <li class="right" > <a href="../indexing.html" title="8.12. インデックス構築" >次へ</a> |</li> <li class="right" > <a href="snippet_html.html" title="8.11.9. snippet_html" >前へ</a> |</li> <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../function.html" >8.11. 関数</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>