<!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 documentation</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> <link rel="shortcut icon" href="../../_static/favicon.ico"/> <link rel="top" title="groonga v3.0.5 documentation" href="../../index.html" /> <link rel="up" title="8.11. Function" href="../function.html" /> <link rel="next" title="8.12. Indexing" 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">An open-source fulltext search engine and column store.</span> </a> </h1> <div class="other-language-links"> <ul> <li><a href="../../../../ja/html/reference/functions/sub_filter.html"><img src="../../_static/jp.png" alt="日本語">日本語版はこちら</a></li> </ul> </div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../indexing.html" title="8.12. Indexing" accesskey="N">next</a> |</li> <li class="right" > <a href="snippet_html.html" title="8.11.9. snippet_html" accesskey="P">previous</a> |</li> <li><a href="../../index.html">groonga v3.0.5 documentation</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../function.html" accesskey="U">8.11. Function</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="Permalink to this headline">¶</a></h1> <div class="section" id="summary"> <h2>8.11.10.1. Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> evaluates <tt class="docutils literal"><span class="pre">filter_string</span></tt> in <tt class="docutils literal"><span class="pre">scope</span></tt> context.</p> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> can be used in only <tt class="docutils literal"><span class="pre">--filter</span></tt> in <a class="reference internal" href="../commands/select.html"><em>select</em></a>.</p> </div> <div class="section" id="syntax"> <h2>8.11.10.2. Syntax<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h2> <p><tt class="docutils literal"><span class="pre">sub_filter</span></tt> requires two arguments. They are <tt class="docutils literal"><span class="pre">scope</span></tt> and <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. Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2> <p>Here are a schema definition and sample data to show usage.</p> <p>Sample schema:</p> <p>Execution example:</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>Sample data:</p> <p>Execution example:</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>Here is the simple usage of <tt class="docutils literal"><span class="pre">sub_filter</span></tt> function which extracts the blog entry</dt> <dd>user 'A' commented out.</dd> </dl> <p>Execution example:</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>When executing the above query, not only "groonga's blog", but also "mroonga's blog". This is not what you want because user "A" does not mention "groonga" to "mroonga's blog".</p> <p>Without sub_filter, it means that following conditions are met.</p> <ul class="simple"> <li>There is at least one record that user "A" commented out.</li> <li>There is at least one record that mentioned about "groonga".</li> </ul> <p>Execution example:</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>On the other hand, executing the above query returns the intended result. Because the arguments of sub_filter is evaluated in comments column's context.</p> <p>It means that sub_filter requires the following condition is met.</p> <ul class="simple"> <li>There are the records that user "A" mentions about "groonga".</li> </ul> </div> <div class="section" id="parameters"> <h2>8.11.10.4. Parameters<a class="headerlink" href="#parameters" title="Permalink to this headline">¶</a></h2> <p>There are two required parameter, <tt class="docutils literal"><span class="pre">scope</span></tt> and <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="Permalink to this headline">¶</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>See <em class="xref std std-ref">select-table</em> about <tt class="docutils literal"><span class="pre">table</span></tt> parameter in <tt class="docutils literal"><span class="pre">select</span></tt>.</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="Permalink to this headline">¶</a></h3> <p>It specifies a search condition in <a class="reference internal" href="../grn_expr/script_syntax.html"><em>Script syntax</em></a>. It is evaluated in <tt class="docutils literal"><span class="pre">scope</span></tt> context.</p> </div> </div> <div class="section" id="return-value"> <h2>8.11.10.5. Return value<a class="headerlink" href="#return-value" title="Permalink to this headline">¶</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. See also<a class="headerlink" href="#see-also" title="Permalink to this headline">¶</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>Script syntax</em></a></li> </ul> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../../index.html">Table Of Contents</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. Summary</a></li> <li><a class="reference internal" href="#syntax">8.11.10.2. Syntax</a></li> <li><a class="reference internal" href="#usage">8.11.10.3. Usage</a></li> <li><a class="reference internal" href="#parameters">8.11.10.4. Parameters</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. Return value</a></li> <li><a class="reference internal" href="#see-also">8.11.10.6. See also</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="snippet_html.html" title="previous chapter">8.11.9. snippet_html</a></p> <h4>Next topic</h4> <p class="topless"><a href="../indexing.html" title="next chapter">8.12. Indexing</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../../_sources/reference/functions/sub_filter.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../indexing.html" title="8.12. Indexing" >next</a> |</li> <li class="right" > <a href="snippet_html.html" title="8.11.9. snippet_html" >previous</a> |</li> <li><a href="../../index.html">groonga v3.0.5 documentation</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../function.html" >8.11. Function</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>