Kouhei Sutou
null+****@clear*****
Wed Apr 19 18:26:26 JST 2017
Kouhei Sutou 2017-04-19 18:26:26 +0900 (Wed, 19 Apr 2017) New Revision: cf5bfc45dc91bbee43ef9e230d1ea1d3463900ee https://github.com/groonga/groonga.org/commit/cf5bfc45dc91bbee43ef9e230d1ea1d3463900ee Message: Add new files Added files: docs/reference/functions/in_records.html docs/sources/reference/functions/in_records.txt ja/docs/reference/functions/in_records.html ja/docs/sources/reference/functions/in_records.txt Added: docs/reference/functions/in_records.html (+379 -0) 100644 =================================================================== --- /dev/null +++ docs/reference/functions/in_records.html 2017-04-19 18:26:26 +0900 (7d79d83) @@ -0,0 +1,379 @@ +<!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" lang="en"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + + <title>7.14.10. in_records — Groonga v7.0.2 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: '7.0.2', + 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="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="Groonga v7.0.2 documentation" href="../../index.html" /> + <link rel="up" title="7.14. Function" href="../function.html" /> + <link rel="next" title="7.14.11. in_values" href="in_values.html" /> + <link rel="prev" title="7.14.9. html_untag" href="html_untag.html" /> + <meta property="fb:page_id" content="201193596592346" /><!-- groonga --> + <meta property="fb:admins" content="664204556" /><!-- kouhei.sutou --> + <meta property="og:type" content="product" /> + <meta property="og:image" content="http://groonga.org/images/logos/groonga-icon-full-size.png" /> + <meta property="og:site_name" content="groonga" /> + + <link rel="stylesheet" href="/css/sphinx.css" type="text/css" /> + </head> + + <body role="document"> +<div class="header"> + <h1 class="title"> + <a id="top-link" href="../../../"> + <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="facebook-buttons"> + <fb:like href="http://www.facebook.com/pages/groonga/201193596592346" + layout="standard" + width="290"></fb:like> + </div> + <div class="other-language-links"> + + <ul> + <li><a href="../../../ja/docs/reference/functions/in_records.html">日本語</a></li> + </ul> + </div> +</div> + + + <div class="related" role="navigation" aria-label="related navigation"> + <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="in_values.html" title="7.14.11. in_values" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="html_untag.html" title="7.14.9. html_untag" + accesskey="P">previous</a> |</li> + <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v7.0.2 documentation</a> »</li> + <li class="nav-item nav-item-1"><a href="../../reference.html" >7. Reference manual</a> »</li> + <li class="nav-item nav-item-2"><a href="../function.html" accesskey="U">7.14. Function</a> »</li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <div class="section" id="in-records"> +<h1>7.14.10. <code class="docutils literal"><span class="pre">in_records</span></code><a class="headerlink" href="#in-records" title="Permalink to this headline">¶</a></h1> +<div class="section" id="summary"> +<h2>7.14.10.1. Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2> +<div class="versionadded"> +<p><span class="versionmodified">New in version 7.0.2.</span></p> +</div> +<p>You can use <code class="docutils literal"><span class="pre">in_records</span></code> for using an existing table as condition patterns. Each record in the existing table is treated as a condition pattern.</p> +<p>You may be able to reduce multiple queries to only one query by <code class="docutils literal"><span class="pre">in_records</span></code>.</p> +<p><code class="docutils literal"><span class="pre">in_records</span></code> is similar to <a class="reference internal" href="sub_filter.html"><span class="doc">sub_filter</span></a>. Here are differences of them:</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">sub_filter</span></code> requires a reference column to condition table but <code class="docutils literal"><span class="pre">in_records</span></code> doesn't require.</li> +<li><code class="docutils literal"><span class="pre">sub_filter</span></code> requires an index column for the reference column but <code class="docutils literal"><span class="pre">in_records</span></code> doesn't require.</li> +<li><code class="docutils literal"><span class="pre">sub_filter</span></code> can use all logical operations but <code class="docutils literal"><span class="pre">in_records</span></code> can use only AND logical operation in one pattern.</li> +<li><code class="docutils literal"><span class="pre">sub_filter</span></code> can use only the value of one reference column for condition but <code class="docutils literal"><span class="pre">in_records</span></code> can use one or more values for condition. You can use multiple columns, functions and so on for multiple values.</li> +<li><code class="docutils literal"><span class="pre">sub_filter</span></code> uses index search but <code class="docutils literal"><span class="pre">in_records</span></code> uses sequential search.</li> +</ul> +</div></blockquote> +</div> +<div class="section" id="syntax"> +<span id="in-records-syntax"></span><h2>7.14.10.2. Syntax<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h2> +<p><code class="docutils literal"><span class="pre">in_records</span></code> has four or more parameters:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>in_records(condition_table, + value1, mode1, condition_column_name1, + ..., + valueN, modeN, condition_column_nameN) +</pre></div> +</div> +</div> +<div class="section" id="usage"> +<span id="in-records-usage"></span><h2>7.14.10.3. Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2> +<p>Here is a schema definition and sample data.</p> +<p>Sample schema:</p> +<p>Execution example:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>table_create Tags TABLE_PAT_KEY ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +table_create Conditions TABLE_PAT_KEY ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Conditions user_pattern COLUMN_SCALAR ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Conditions tag COLUMN_SCALAR Tags +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Conditions max_length COLUMN_SCALAR UInt32 +# [[0, 1337566253.89858, 0.000355720520019531], true] +table_create Memos TABLE_HASH_KEY ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Memos user COLUMN_SCALAR ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Memos tag COLUMN_SCALAR Tags +# [[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><span></span>load --table Memos +[ +{"_key": "Groonga is fast", "user": "alice", "tag": "groonga"}, +{"_key": "Mroonga is fast", "user": "alice", "tag": "mroonga"}, +{"_key": "Groonga is very good!", "user": "alice", "tag": "groonga"}, +{"_key": "Droonga is fast", "user": "david", "tag": "droonga"}, +{"_key": "Groonga is a HTTP server", "user": "david", "tag": "groonga"} +] +# [[0, 1337566253.89858, 0.000355720520019531], 5] +</pre></div> +</div> +<p>Sample conditions:</p> +<p>Execution example:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>load --table Conditions +[ +{"_key": "lic + groonga", "user_pattern": "lic", "tag": "groonga", max_length: 20}, +{"_key": "dav + droonga", "user_pattern": "dav", "tag": "droonga", max_length: 50} +] +# [[0, 1337566253.89858, 0.000355720520019531], 2] +</pre></div> +</div> +<p>Here is a simple usage of <code class="docutils literal"><span class="pre">in_records</span></code> that searches by records in <code class="docutils literal"><span class="pre">Conditions</span></code> table. Each record is used as a condition:</p> +<p>Execution example:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>plugin_register functions/string +# [[0, 1337566253.89858, 0.000355720520019531], true] +select \ + --table Memos \ + --filter 'in_records(Conditions, \ + user, "@", "user_pattern", \ + tag, "==", "tag", \ + string_length(_key), "<=", "max_length")' \ + --sort_by _id \ + --output_columns _key,user,tag +# [ +# [ +# 0, +# 1337566253.89858, +# 0.000355720520019531 +# ], +# [ +# [ +# [ +# 2 +# ], +# [ +# [ +# "_key", +# "ShortText" +# ], +# [ +# "user", +# "ShortText" +# ], +# [ +# "tag", +# "Tags" +# ] +# ], +# [ +# "Groonga is fast", +# "alice", +# "groonga" +# ], +# [ +# "Droonga is fast", +# "david", +# "droonga" +# ] +# ] +# ] +# ] +</pre></div> +</div> +<p>The <code class="docutils literal"><span class="pre">filter</span></code> tries the following three conditions for each record:</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">Memos.user</span></code> matches (<code class="docutils literal"><span class="pre">@</span></code>) <code class="docutils literal"><span class="pre">Conditions.user_pattern</span></code>.</li> +<li><code class="docutils literal"><span class="pre">Memos.tag</span></code> equals (<code class="docutils literal"><span class="pre">==</span></code>) <code class="docutils literal"><span class="pre">Conditions.tag</span></code>.</li> +<li>The number of characters in <code class="docutils literal"><span class="pre">Memos._key</span></code> is less than or equals to <code class="docutils literal"><span class="pre">Conditions.max_length</span></code>.</li> +</ul> +</div></blockquote> +<p>If at least one record in <code class="docutils literal"><span class="pre">Conditions</span></code> table returns true for the all three conditions, the record in <code class="docutils literal"><span class="pre">Memos</span></code> is matched.</p> +<p>The first record in <code class="docutils literal"><span class="pre">Conditions</span></code> table use the following conditions:</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">Memos.user</span></code> has <code class="docutils literal"><span class="pre">"lic"</span></code> substring.</li> +<li><code class="docutils literal"><span class="pre">Memos.tag</span></code> is <code class="docutils literal"><span class="pre">"groonga"</span></code>.</li> +<li>The number of characters in <code class="docutils literal"><span class="pre">Memos._key</span></code> is less than or equals to <code class="docutils literal"><span class="pre">20</span></code>.</li> +</ul> +</div></blockquote> +<p>This condition matches the following records:</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">{"_key":</span> <span class="pre">"Groonga</span> <span class="pre">is</span> <span class="pre">fast",</span> <span class="pre">"user":</span> <span class="pre">"alice",</span> <span class="pre">"tag":</span> <span class="pre">"groonga"}</span></code></li> +</ul> +</div></blockquote> +<p>The second record in <code class="docutils literal"><span class="pre">Conditions</span></code> table use the following conditions:</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">Memos.user</span></code> has <code class="docutils literal"><span class="pre">"dav"</span></code> substring.</li> +<li><code class="docutils literal"><span class="pre">Memos.tag</span></code> is <code class="docutils literal"><span class="pre">"droonga"</span></code>.</li> +<li>The number of characters in <code class="docutils literal"><span class="pre">Memos._key</span></code> is less than or equals to <code class="docutils literal"><span class="pre">50</span></code>.</li> +</ul> +</div></blockquote> +<p>This condition matches the following records:</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">{"_key":</span> <span class="pre">"Droonga</span> <span class="pre">is</span> <span class="pre">fast",</span> <span class="pre">"user":</span> <span class="pre">"david",</span> <span class="pre">"tag":</span> <span class="pre">"droonga"}</span></code></li> +</ul> +</div></blockquote> +<p>The result has the all above records.</p> +</div> +<div class="section" id="parameters"> +<span id="in-records-parameters"></span><h2>7.14.10.4. Parameters<a class="headerlink" href="#parameters" title="Permalink to this headline">¶</a></h2> +<p><code class="docutils literal"><span class="pre">in_records</span></code> requires four or more parameters.</p> +<div class="section" id="required-parameters"> +<span id="in-records-required-parameters"></span><h3>7.14.10.4.1. Required parameters<a class="headerlink" href="#required-parameters" title="Permalink to this headline">¶</a></h3> +<p><code class="docutils literal"><span class="pre">condition_table</span></code> and tuples of <code class="docutils literal"><span class="pre">value</span></code>, <code class="docutils literal"><span class="pre">mode_name</span></code> and <code class="docutils literal"><span class="pre">condition_column_name</span></code> are required. You can specify multiple tuples of <code class="docutils literal"><span class="pre">value</span></code>, <code class="docutils literal"><span class="pre">mode_name</span></code> and <code class="docutils literal"><span class="pre">condition_column_name</span></code></p> +<div class="section" id="condition-table"> +<span id="in-records-condition-table"></span><h4>7.14.10.4.1.1. <code class="docutils literal"><span class="pre">condition_table</span></code><a class="headerlink" href="#condition-table" title="Permalink to this headline">¶</a></h4> +<p>Specifies a table that has conditions as its records.</p> +</div> +</div> +<div class="section" id="value"> +<span id="in-records-value"></span><h3>7.14.10.4.2. <code class="docutils literal"><span class="pre">value</span></code><a class="headerlink" href="#value" title="Permalink to this headline">¶</a></h3> +<p>Specifies a value to be compared.</p> +</div> +<div class="section" id="mode-name"> +<span id="in-records-mode-name"></span><h3>7.14.10.4.3. <code class="docutils literal"><span class="pre">mode_name</span></code><a class="headerlink" href="#mode-name" title="Permalink to this headline">¶</a></h3> +<p>Specifies a mode name that specifies how to compare <a class="reference internal" href="#in-records-value"><span class="std std-ref">value</span></a> with a value of <a class="reference internal" href="#in-records-condition-column-name"><span class="std std-ref">condition_column_name</span></a>.</p> +<p>See <a class="reference internal" href="query.html#query-default-mode"><span class="std std-ref">default_mode</span></a> for available mode names. All mode names except <code class="docutils literal"><span class="pre">NEAR</span></code>, <code class="docutils literal"><span class="pre">SIMILAR</span></code> and <code class="docutils literal"><span class="pre">SUFFIX</span></code> are supported.</p> +</div> +<div class="section" id="condition-column-name"> +<span id="in-records-condition-column-name"></span><h3>7.14.10.4.4. <code class="docutils literal"><span class="pre">condition_column_name</span></code><a class="headerlink" href="#condition-column-name" title="Permalink to this headline">¶</a></h3> +<p>Specifies a column name of <a class="reference internal" href="#in-records-condition-table"><span class="std std-ref">condition_table</span></a> to be used as condition.</p> +</div> +<div class="section" id="optional-parameter"> +<span id="in-records-optional-parameters"></span><h3>7.14.10.4.5. Optional parameter<a class="headerlink" href="#optional-parameter" title="Permalink to this headline">¶</a></h3> +<p>There are no optional parameter.</p> +</div> +</div> +<div class="section" id="return-value"> +<h2>7.14.10.5. Return value<a class="headerlink" href="#return-value" title="Permalink to this headline">¶</a></h2> +<p><code class="docutils literal"><span class="pre">in_records</span></code> returns whether the record is matched one of records of the specified condition table or not.</p> +<p>If the record is matched, it returns <code class="docutils literal"><span class="pre">true</span></code>. Otherwise, it returns <code class="docutils literal"><span class="pre">false</span></code>.</p> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference internal" href="#">7.14.10. <code class="docutils literal"><span class="pre">in_records</span></code></a><ul> +<li><a class="reference internal" href="#summary">7.14.10.1. Summary</a></li> +<li><a class="reference internal" href="#syntax">7.14.10.2. Syntax</a></li> +<li><a class="reference internal" href="#usage">7.14.10.3. Usage</a></li> +<li><a class="reference internal" href="#parameters">7.14.10.4. Parameters</a><ul> +<li><a class="reference internal" href="#required-parameters">7.14.10.4.1. Required parameters</a><ul> +<li><a class="reference internal" href="#condition-table">7.14.10.4.1.1. <code class="docutils literal"><span class="pre">condition_table</span></code></a></li> +</ul> +</li> +<li><a class="reference internal" href="#value">7.14.10.4.2. <code class="docutils literal"><span class="pre">value</span></code></a></li> +<li><a class="reference internal" href="#mode-name">7.14.10.4.3. <code class="docutils literal"><span class="pre">mode_name</span></code></a></li> +<li><a class="reference internal" href="#condition-column-name">7.14.10.4.4. <code class="docutils literal"><span class="pre">condition_column_name</span></code></a></li> +<li><a class="reference internal" href="#optional-parameter">7.14.10.4.5. Optional parameter</a></li> +</ul> +</li> +<li><a class="reference internal" href="#return-value">7.14.10.5. Return value</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="html_untag.html" + title="previous chapter">7.14.9. <code class="docutils literal"><span class="pre">html_untag</span></code></a></p> + <h4>Next topic</h4> + <p class="topless"><a href="in_values.html" + title="next chapter">7.14.11. <code class="docutils literal"><span class="pre">in_values</span></code></a></p> + <div role="note" aria-label="source link"> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../sources/reference/functions/in_records.txt" + rel="nofollow">Show Source</a></li> + </ul> + </div> +<div id="searchbox" style="display: none" role="search"> + <h3>Quick search</h3> + <form class="search" action="../../search.html" method="get"> + <div><input type="text" name="q" /></div> + <div><input type="submit" value="Go" /></div> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> +<script type="text/javascript">$('#searchbox').show(0);</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="related" role="navigation" aria-label="related navigation"> + <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="in_values.html" title="7.14.11. in_values" + >next</a> |</li> + <li class="right" > + <a href="html_untag.html" title="7.14.9. html_untag" + >previous</a> |</li> + <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v7.0.2 documentation</a> »</li> + <li class="nav-item nav-item-1"><a href="../../reference.html" >7. Reference manual</a> »</li> + <li class="nav-item nav-item-2"><a href="../function.html" >7.14. Function</a> »</li> + </ul> + </div> + <div class="footer" role="contentinfo"> + © Copyright 2009-2017, Brazil, Inc. + </div> + <script src="http://connect.facebook.net/en_US/all.js"></script> + + <script> + FB.init({ + appId : null, + status : true, // check login status + cookie : true, // enable cookies to allow the server to access the session + xfbml : true // parse XFBML + }); + </script> + </body> + +</html> \ No newline at end of file Added: docs/sources/reference/functions/in_records.txt (+195 -0) 100644 =================================================================== --- /dev/null +++ docs/sources/reference/functions/in_records.txt 2017-04-19 18:26:26 +0900 (eea5cce) @@ -0,0 +1,195 @@ +.. -*- rst -*- + +.. highlightlang:: none + +.. groonga-command +.. database: functions_in_records + +``in_records`` +============== + +Summary +------- + +.. versionadded:: 7.0.2 + +You can use ``in_records`` for using an existing table as condition patterns. Each record in the existing table is treated as a condition pattern. + +You may be able to reduce multiple queries to only one query by ``in_records``. + +``in_records`` is similar to :doc:`sub_filter`. Here are differences of them: + + * ``sub_filter`` requires a reference column to condition table but ``in_records`` doesn't require. + + * ``sub_filter`` requires an index column for the reference column but ``in_records`` doesn't require. + + * ``sub_filter`` can use all logical operations but ``in_records`` can use only AND logical operation in one pattern. + + * ``sub_filter`` can use only the value of one reference column for condition but ``in_records`` can use one or more values for condition. You can use multiple columns, functions and so on for multiple values. + + * ``sub_filter`` uses index search but ``in_records`` uses sequential search. + +.. _in-records-syntax: + +Syntax +------ + +``in_records`` has four or more parameters:: + + in_records(condition_table, + value1, mode1, condition_column_name1, + ..., + valueN, modeN, condition_column_nameN) + +.. _in-records-usage: + +Usage +----- + +Here is a schema definition and sample data. + +Sample schema: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_setup_schema.log +.. table_create Tags TABLE_PAT_KEY ShortText +.. +.. table_create Conditions TABLE_PAT_KEY ShortText +.. column_create Conditions user_pattern COLUMN_SCALAR ShortText +.. column_create Conditions tag COLUMN_SCALAR Tags +.. column_create Conditions max_length COLUMN_SCALAR UInt32 +.. +.. table_create Memos TABLE_HASH_KEY ShortText +.. column_create Memos user COLUMN_SCALAR ShortText +.. column_create Memos tag COLUMN_SCALAR Tags + +Sample data: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_setup_data.log +.. load --table Memos +.. [ +.. {"_key": "Groonga is fast", "user": "alice", "tag": "groonga"}, +.. {"_key": "Mroonga is fast", "user": "alice", "tag": "mroonga"}, +.. {"_key": "Groonga is very good!", "user": "alice", "tag": "groonga"}, +.. {"_key": "Droonga is fast", "user": "david", "tag": "droonga"}, +.. {"_key": "Groonga is a HTTP server", "user": "david", "tag": "groonga"} +.. ] + +Sample conditions: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_setup_conditions.log +.. load --table Conditions +.. [ +.. {"_key": "lic + groonga", "user_pattern": "lic", "tag": "groonga", max_length: 20}, +.. {"_key": "dav + droonga", "user_pattern": "dav", "tag": "droonga", max_length: 50} +.. ] + +Here is a simple usage of ``in_records`` that searches by records in ``Conditions`` table. Each record is used as a condition: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_search.log +.. plugin_register functions/string +.. select \ +.. --table Memos \ +.. --filter 'in_records(Conditions, \ +.. user, "@", "user_pattern", \ +.. tag, "==", "tag", \ +.. string_length(_key), "<=", "max_length")' \ +.. --sort_by _id \ +.. --output_columns _key,user,tag + +The ``filter`` tries the following three conditions for each record: + + * ``Memos.user`` matches (``@``) ``Conditions.user_pattern``. + + * ``Memos.tag`` equals (``==``) ``Conditions.tag``. + + * The number of characters in ``Memos._key`` is less than or equals to ``Conditions.max_length``. + +If at least one record in ``Conditions`` table returns true for the all three conditions, the record in ``Memos`` is matched. + +The first record in ``Conditions`` table use the following conditions: + + * ``Memos.user`` has ``"lic"`` substring. + + * ``Memos.tag`` is ``"groonga"``. + + * The number of characters in ``Memos._key`` is less than or equals to ``20``. + +This condition matches the following records: + + * ``{"_key": "Groonga is fast", "user": "alice", "tag": "groonga"}`` + +The second record in ``Conditions`` table use the following conditions: + + * ``Memos.user`` has ``"dav"`` substring. + + * ``Memos.tag`` is ``"droonga"``. + + * The number of characters in ``Memos._key`` is less than or equals to ``50``. + +This condition matches the following records: + + * ``{"_key": "Droonga is fast", "user": "david", "tag": "droonga"}`` + +The result has the all above records. + +.. _in-records-parameters: + +Parameters +---------- + +``in_records`` requires four or more parameters. + +.. _in-records-required-parameters: + +Required parameters +^^^^^^^^^^^^^^^^^^^ + +``condition_table`` and tuples of ``value``, ``mode_name`` and ``condition_column_name`` are required. You can specify multiple tuples of ``value``, ``mode_name`` and ``condition_column_name`` + +.. _in-records-condition-table: + +``condition_table`` +""""""""""""""""""" + +Specifies a table that has conditions as its records. + +.. _in-records-value: + +``value`` +^^^^^^^^^ + +Specifies a value to be compared. + +.. _in-records-mode-name: + +``mode_name`` +^^^^^^^^^^^^^ + +Specifies a mode name that specifies how to compare :ref:`in-records-value` with a value of :ref:`in-records-condition-column-name`. + +See :ref:`query-default-mode` for available mode names. All mode names except ``NEAR``, ``SIMILAR`` and ``SUFFIX`` are supported. + +.. _in-records-condition-column-name: + +``condition_column_name`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Specifies a column name of :ref:`in-records-condition-table` to be used as condition. + +.. _in-records-optional-parameters: + +Optional parameter +^^^^^^^^^^^^^^^^^^ + +There are no optional parameter. + +Return value +------------ + +``in_records`` returns whether the record is matched one of records of the specified condition table or not. + +If the record is matched, it returns ``true``. Otherwise, it returns ``false``. Added: ja/docs/reference/functions/in_records.html (+394 -0) 100644 =================================================================== --- /dev/null +++ ja/docs/reference/functions/in_records.html 2017-04-19 18:26:26 +0900 (de1870d) @@ -0,0 +1,394 @@ +<!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" lang="ja"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + + <title>7.14.10. in_records — Groonga v7.0.2ドキュメント</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: '7.0.2', + 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="index" title="索引" href="../../genindex.html" /> + <link rel="search" title="検索" href="../../search.html" /> + <link rel="top" title="Groonga v7.0.2ドキュメント" href="../../index.html" /> + <link rel="up" title="7.14. 関数" href="../function.html" /> + <link rel="next" title="7.14.11. in_values" href="in_values.html" /> + <link rel="prev" title="7.14.9. html_untag" href="html_untag.html" /> + <meta property="fb:page_id" content="201193596592346" /><!-- groonga --> + <meta property="fb:admins" content="664204556" /><!-- kouhei.sutou --> + <meta property="og:type" content="product" /> + <meta property="og:image" content="http://groonga.org/images/logos/groonga-icon-full-size.png" /> + <meta property="og:site_name" content="groonga" /> + + <link rel="stylesheet" href="/css/sphinx.css" type="text/css" /> + </head> + + <body role="document"> +<div class="header"> + <h1 class="title"> + <a id="top-link" href="../../../"> + <span class="project">groonga</span> + <span class="separator">-</span> + <span class="description">オープンソースのカラムストア機能付き全文検索エンジン</span> + </a> + </h1> + + <div class="facebook-buttons"> + <fb:like href="http://www.facebook.com/pages/groonga/201193596592346" + layout="standard" + width="290"></fb:like> + </div> + <div class="other-language-links"> + + <ul> + <li><a href="../../../../docs/reference/functions/in_records.html">English</a></li> + </ul> + </div> +</div> + + + <div class="related" role="navigation" aria-label="related navigation"> + <h3>ナビゲーション</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../genindex.html" title="総合索引" + accesskey="I">索引</a></li> + <li class="right" > + <a href="in_values.html" title="7.14.11. in_values" + accesskey="N">次へ</a> |</li> + <li class="right" > + <a href="html_untag.html" title="7.14.9. html_untag" + accesskey="P">前へ</a> |</li> + <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v7.0.2ドキュメント</a> »</li> + <li class="nav-item nav-item-1"><a href="../../reference.html" >7. リファレンスマニュアル</a> »</li> + <li class="nav-item nav-item-2"><a href="../function.html" accesskey="U">7.14. 関数</a> »</li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <div class="section" id="in-records"> +<h1>7.14.10. <code class="docutils literal"><span class="pre">in_records</span></code><a class="headerlink" href="#in-records" title="このヘッドラインへのパーマリンク">¶</a></h1> +<div class="section" id="summary"> +<h2>7.14.10.1. 概要<a class="headerlink" href="#summary" title="このヘッドラインへのパーマリンク">¶</a></h2> +<div class="versionadded"> +<p><span class="versionmodified">バージョン 7.0.2 で追加.</span></p> +</div> +<p><code class="docutils literal"><span class="pre">in_records</span></code> を使うと既存のテーブルを条件のパターンとして使うことができます。テーブル内の各レコードがそれぞれ条件のパターンになります。</p> +<p><code class="docutils literal"><span class="pre">in_records</span></code> を使うと複数のクエリーを1つのクエリーにできるかもしれません。</p> +<p><code class="docutils literal"><span class="pre">in_records</span></code> は <a class="reference internal" href="sub_filter.html"><span class="doc">sub_filter</span></a> に似ています。2つの違いは次の通りです。</p> +<blockquote> +<div><ul class="simple"> +<li><p class="first"><code class="docutils literal"><span class="pre">sub_filter</span></code> では条件テーブルを参照するカラムが必須ですが、 <code class="docutils literal"><span class="pre">in_records</span></code> では必要ありません。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">sub_filter</span></code> では上述の参照カラム用のインデックスカラムが必須ですが、 <code class="docutils literal"><span class="pre">in_records</span></code> ではインデックスカラムは必要ありません。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">sub_filter</span></code> ではすべての論理演算を使えますが、 <code class="docutils literal"><span class="pre">in_records</span></code> では1つのパターン内でAND論理演算しか使えません。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">sub_filter</span></code> では条件に1つの参照カラムの値しか使えませんが、 <code class="docutils literal"><span class="pre">in_records</span></code> では条件に1つ以上の値を使えます。複数の値を指定するために複数のカラムや関数などを使えます。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">sub_filter</span></code> ではインデックスサーチを使いますが、 <code class="docutils literal"><span class="pre">in_records</span></code> ではシーケンシャルサーチを使います。</p> +</li> +</ul> +</div></blockquote> +</div> +<div class="section" id="syntax"> +<span id="in-records-syntax"></span><h2>7.14.10.2. 構文<a class="headerlink" href="#syntax" title="このヘッドラインへのパーマリンク">¶</a></h2> +<p><code class="docutils literal"><span class="pre">in_records</span></code> には4つ以上のパラメーターがあります。:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>in_records(condition_table, + value1, mode1, condition_column_name1, + ..., + valueN, modeN, condition_column_nameN) +</pre></div> +</div> +</div> +<div class="section" id="usage"> +<span id="in-records-usage"></span><h2>7.14.10.3. 使い方<a class="headerlink" href="#usage" title="このヘッドラインへのパーマリンク">¶</a></h2> +<p>使い方を示すために使うスキーマ定義とサンプルデータは以下の通りです。</p> +<p>サンプルスキーマ:</p> +<p>実行例:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>table_create Tags TABLE_PAT_KEY ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +table_create Conditions TABLE_PAT_KEY ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Conditions user_pattern COLUMN_SCALAR ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Conditions tag COLUMN_SCALAR Tags +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Conditions max_length COLUMN_SCALAR UInt32 +# [[0, 1337566253.89858, 0.000355720520019531], true] +table_create Memos TABLE_HASH_KEY ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Memos user COLUMN_SCALAR ShortText +# [[0, 1337566253.89858, 0.000355720520019531], true] +column_create Memos tag COLUMN_SCALAR Tags +# [[0, 1337566253.89858, 0.000355720520019531], true] +</pre></div> +</div> +<p>サンプルデータ:</p> +<p>実行例:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>load --table Memos +[ +{"_key": "Groonga is fast", "user": "alice", "tag": "groonga"}, +{"_key": "Mroonga is fast", "user": "alice", "tag": "mroonga"}, +{"_key": "Groonga is very good!", "user": "alice", "tag": "groonga"}, +{"_key": "Droonga is fast", "user": "david", "tag": "droonga"}, +{"_key": "Groonga is a HTTP server", "user": "david", "tag": "groonga"} +] +# [[0, 1337566253.89858, 0.000355720520019531], 5] +</pre></div> +</div> +<p>サンプル条件:</p> +<p>実行例:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>load --table Conditions +[ +{"_key": "lic + groonga", "user_pattern": "lic", "tag": "groonga", max_length: 20}, +{"_key": "dav + droonga", "user_pattern": "dav", "tag": "droonga", max_length: 50} +] +# [[0, 1337566253.89858, 0.000355720520019531], 2] +</pre></div> +</div> +<p>以下は <code class="docutils literal"><span class="pre">Conditions</span></code> テーブル内のレコードで検索をする <code class="docutils literal"><span class="pre">in_records</span></code> の使用例です。各レコードを条件として使います。</p> +<p>実行例:</p> +<div class="highlight-none"><div class="highlight"><pre><span></span>plugin_register functions/string +# [[0, 1337566253.89858, 0.000355720520019531], true] +select \ + --table Memos \ + --filter 'in_records(Conditions, \ + user, "@", "user_pattern", \ + tag, "==", "tag", \ + string_length(_key), "<=", "max_length")' \ + --sort_by _id \ + --output_columns _key,user,tag +# [ +# [ +# 0, +# 1337566253.89858, +# 0.000355720520019531 +# ], +# [ +# [ +# [ +# 2 +# ], +# [ +# [ +# "_key", +# "ShortText" +# ], +# [ +# "user", +# "ShortText" +# ], +# [ +# "tag", +# "Tags" +# ] +# ], +# [ +# "Groonga is fast", +# "alice", +# "groonga" +# ], +# [ +# "Droonga is fast", +# "david", +# "droonga" +# ] +# ] +# ] +# ] +</pre></div> +</div> +<p>この <code class="docutils literal"><span class="pre">filter</span></code> は各レコードに対して次の3つの条件で絞り込みます。</p> +<blockquote> +<div><ul class="simple"> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos.user</span></code> が <code class="docutils literal"><span class="pre">Conditions.user_pattern</span></code> にマッチ( <code class="docutils literal"><span class="pre">@</span></code> )するか。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos.tag</span></code> は <code class="docutils literal"><span class="pre">Conditions.tag</span></code> と等しい( <code class="docutils literal"><span class="pre">==</span></code> )か。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos._key</span></code> の文字数が <code class="docutils literal"><span class="pre">Conditions.max_length</span></code> 以下か。</p> +</li> +</ul> +</div></blockquote> +<p><code class="docutils literal"><span class="pre">Conditions</span></code> テーブル内の少なくとも1つのレコードがこれら3つの条件すべてで真を返せば <code class="docutils literal"><span class="pre">Memos</span></code> テーブルのそのレコードはマッチします。</p> +<p><code class="docutils literal"><span class="pre">Conditions</span></code> テーブルの最初のレコードは次の条件を使います。</p> +<blockquote> +<div><ul class="simple"> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos.user</span></code> には部分文字列として <code class="docutils literal"><span class="pre">"lic"</span></code> がある。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos.tag</span></code> は <code class="docutils literal"><span class="pre">"groonga"</span></code> である。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos._key</span></code> の文字数が <code class="docutils literal"><span class="pre">20</span></code> 以下である。</p> +</li> +</ul> +</div></blockquote> +<p>この条件は次のレコードにマッチします。</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">{"_key":</span> <span class="pre">"Groonga</span> <span class="pre">is</span> <span class="pre">fast",</span> <span class="pre">"user":</span> <span class="pre">"alice",</span> <span class="pre">"tag":</span> <span class="pre">"groonga"}</span></code></li> +</ul> +</div></blockquote> +<p><code class="docutils literal"><span class="pre">Conditions</span></code> テーブルの2つめのレコードは次の条件を使います。</p> +<blockquote> +<div><ul class="simple"> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos.user</span></code> には部分文字列として <code class="docutils literal"><span class="pre">"dav"</span></code> がある。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos.tag</span></code> は <code class="docutils literal"><span class="pre">"droonga"</span></code> である。</p> +</li> +<li><p class="first"><code class="docutils literal"><span class="pre">Memos._key</span></code> の文字数が <code class="docutils literal"><span class="pre">50</span></code> 以下である。</p> +</li> +</ul> +</div></blockquote> +<p>この条件は次のレコードにマッチします。</p> +<blockquote> +<div><ul class="simple"> +<li><code class="docutils literal"><span class="pre">{"_key":</span> <span class="pre">"Droonga</span> <span class="pre">is</span> <span class="pre">fast",</span> <span class="pre">"user":</span> <span class="pre">"david",</span> <span class="pre">"tag":</span> <span class="pre">"droonga"}</span></code></li> +</ul> +</div></blockquote> +<p>検索結果には前述のすべてのレコードが含まれます。</p> +</div> +<div class="section" id="parameters"> +<span id="in-records-parameters"></span><h2>7.14.10.4. 引数<a class="headerlink" href="#parameters" title="このヘッドラインへのパーマリンク">¶</a></h2> +<p><code class="docutils literal"><span class="pre">in_records</span></code> には4つ以上のパラメーターが必須です。</p> +<div class="section" id="required-parameters"> +<span id="in-records-required-parameters"></span><h3>7.14.10.4.1. 必須引数<a class="headerlink" href="#required-parameters" title="このヘッドラインへのパーマリンク">¶</a></h3> +<p><code class="docutils literal"><span class="pre">condition_table</span></code> と「 <code class="docutils literal"><span class="pre">value</span></code> 、 <code class="docutils literal"><span class="pre">mode_name</span></code> 、 <code class="docutils literal"><span class="pre">condition_column_name</span></code> 」のセットです。「 <code class="docutils literal"><span class="pre">value</span></code> 、 <code class="docutils literal"><span class="pre">mode_name</span></code> 、 <code class="docutils literal"><span class="pre">condition_column_name</span></code> 」のセットは複数回指定できます。</p> +<div class="section" id="condition-table"> +<span id="in-records-condition-table"></span><h4>7.14.10.4.1.1. <code class="docutils literal"><span class="pre">condition_table</span></code><a class="headerlink" href="#condition-table" title="このヘッドラインへのパーマリンク">¶</a></h4> +<p>レコードとして条件が入っているテーブルを指定します。</p> +</div> +</div> +<div class="section" id="value"> +<span id="in-records-value"></span><h3>7.14.10.4.2. <code class="docutils literal"><span class="pre">value</span></code><a class="headerlink" href="#value" title="このヘッドラインへのパーマリンク">¶</a></h3> +<p>比較対象の値を指定します。</p> +</div> +<div class="section" id="mode-name"> +<span id="in-records-mode-name"></span><h3>7.14.10.4.3. <code class="docutils literal"><span class="pre">mode_name</span></code><a class="headerlink" href="#mode-name" title="このヘッドラインへのパーマリンク">¶</a></h3> +<p><a class="reference internal" href="#in-records-value"><span class="std std-ref">value</span></a> と <a class="reference internal" href="#in-records-condition-column-name"><span class="std std-ref">condition_column_name</span></a> の値の比較方法(モード名)を指定します。</p> +<p>利用可能なモード名は <a class="reference internal" href="query.html#query-default-mode"><span class="std std-ref">default_mode</span></a> を見てください。 <code class="docutils literal"><span class="pre">NEAR</span></code> 、 <code class="docutils literal"><span class="pre">SIMILAR</span></code> と <code class="docutils literal"><span class="pre">SUFFIX</span></code> 以外のすべてのモード名をサポートしています。</p> +</div> +<div class="section" id="condition-column-name"> +<span id="in-records-condition-column-name"></span><h3>7.14.10.4.4. <code class="docutils literal"><span class="pre">condition_column_name</span></code><a class="headerlink" href="#condition-column-name" title="このヘッドラインへのパーマリンク">¶</a></h3> +<p>条件として使う <a class="reference internal" href="#in-records-condition-table"><span class="std std-ref">condition_table</span></a> のカラム名を指定します。</p> +</div> +<div class="section" id="optional-parameter"> +<span id="in-records-optional-parameters"></span><h3>7.14.10.4.5. 省略可能引数<a class="headerlink" href="#optional-parameter" title="このヘッドラインへのパーマリンク">¶</a></h3> +<p>省略可能な引数はありません。</p> +</div> +</div> +<div class="section" id="return-value"> +<h2>7.14.10.5. 戻り値<a class="headerlink" href="#return-value" title="このヘッドラインへのパーマリンク">¶</a></h2> +<p><code class="docutils literal"><span class="pre">in_records</span></code> は対象レコードが指定した条件テーブル内の1つ以上のレコード(パターン)にマッチするかどうかを返します。</p> +<p>もし該当レコードがマッチすれば、 <code class="docutils literal"><span class="pre">true</span></code> を返します。そうでなければ <code class="docutils literal"><span class="pre">false</span></code> を返します。</p> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">目次</a></h3> + <ul> +<li><a class="reference internal" href="#">7.14.10. <code class="docutils literal"><span class="pre">in_records</span></code></a><ul> +<li><a class="reference internal" href="#summary">7.14.10.1. 概要</a></li> +<li><a class="reference internal" href="#syntax">7.14.10.2. 構文</a></li> +<li><a class="reference internal" href="#usage">7.14.10.3. 使い方</a></li> +<li><a class="reference internal" href="#parameters">7.14.10.4. 引数</a><ul> +<li><a class="reference internal" href="#required-parameters">7.14.10.4.1. 必須引数</a><ul> +<li><a class="reference internal" href="#condition-table">7.14.10.4.1.1. <code class="docutils literal"><span class="pre">condition_table</span></code></a></li> +</ul> +</li> +<li><a class="reference internal" href="#value">7.14.10.4.2. <code class="docutils literal"><span class="pre">value</span></code></a></li> +<li><a class="reference internal" href="#mode-name">7.14.10.4.3. <code class="docutils literal"><span class="pre">mode_name</span></code></a></li> +<li><a class="reference internal" href="#condition-column-name">7.14.10.4.4. <code class="docutils literal"><span class="pre">condition_column_name</span></code></a></li> +<li><a class="reference internal" href="#optional-parameter">7.14.10.4.5. 省略可能引数</a></li> +</ul> +</li> +<li><a class="reference internal" href="#return-value">7.14.10.5. 戻り値</a></li> +</ul> +</li> +</ul> + + <h4>前のトピックへ</h4> + <p class="topless"><a href="html_untag.html" + title="前の章へ">7.14.9. <code class="docutils literal"><span class="pre">html_untag</span></code></a></p> + <h4>次のトピックへ</h4> + <p class="topless"><a href="in_values.html" + title="次の章へ">7.14.11. <code class="docutils literal"><span class="pre">in_values</span></code></a></p> + <div role="note" aria-label="source link"> + <h3>このページ</h3> + <ul class="this-page-menu"> + <li><a href="../../sources/reference/functions/in_records.txt" + rel="nofollow">ソースコードを表示(英語)</a></li> + </ul> + </div> +<div id="searchbox" style="display: none" role="search"> + <h3>クイック検索</h3> + <form class="search" action="../../search.html" method="get"> + <div><input type="text" name="q" /></div> + <div><input type="submit" value="検索" /></div> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> +</div> +<script type="text/javascript">$('#searchbox').show(0);</script> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="related" role="navigation" aria-label="related navigation"> + <h3>ナビゲーション</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../../genindex.html" title="総合索引" + >索引</a></li> + <li class="right" > + <a href="in_values.html" title="7.14.11. in_values" + >次へ</a> |</li> + <li class="right" > + <a href="html_untag.html" title="7.14.9. html_untag" + >前へ</a> |</li> + <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v7.0.2ドキュメント</a> »</li> + <li class="nav-item nav-item-1"><a href="../../reference.html" >7. リファレンスマニュアル</a> »</li> + <li class="nav-item nav-item-2"><a href="../function.html" >7.14. 関数</a> »</li> + </ul> + </div> + <div class="footer" role="contentinfo"> + © Copyright 2009-2017, Brazil, Inc. + </div> + <script src="http://connect.facebook.net/ja_JP/all.js"></script> + + <script> + FB.init({ + appId : null, + status : true, // check login status + cookie : true, // enable cookies to allow the server to access the session + xfbml : true // parse XFBML + }); + </script> + </body> + +</html> \ No newline at end of file Added: ja/docs/sources/reference/functions/in_records.txt (+195 -0) 100644 =================================================================== --- /dev/null +++ ja/docs/sources/reference/functions/in_records.txt 2017-04-19 18:26:26 +0900 (eea5cce) @@ -0,0 +1,195 @@ +.. -*- rst -*- + +.. highlightlang:: none + +.. groonga-command +.. database: functions_in_records + +``in_records`` +============== + +Summary +------- + +.. versionadded:: 7.0.2 + +You can use ``in_records`` for using an existing table as condition patterns. Each record in the existing table is treated as a condition pattern. + +You may be able to reduce multiple queries to only one query by ``in_records``. + +``in_records`` is similar to :doc:`sub_filter`. Here are differences of them: + + * ``sub_filter`` requires a reference column to condition table but ``in_records`` doesn't require. + + * ``sub_filter`` requires an index column for the reference column but ``in_records`` doesn't require. + + * ``sub_filter`` can use all logical operations but ``in_records`` can use only AND logical operation in one pattern. + + * ``sub_filter`` can use only the value of one reference column for condition but ``in_records`` can use one or more values for condition. You can use multiple columns, functions and so on for multiple values. + + * ``sub_filter`` uses index search but ``in_records`` uses sequential search. + +.. _in-records-syntax: + +Syntax +------ + +``in_records`` has four or more parameters:: + + in_records(condition_table, + value1, mode1, condition_column_name1, + ..., + valueN, modeN, condition_column_nameN) + +.. _in-records-usage: + +Usage +----- + +Here is a schema definition and sample data. + +Sample schema: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_setup_schema.log +.. table_create Tags TABLE_PAT_KEY ShortText +.. +.. table_create Conditions TABLE_PAT_KEY ShortText +.. column_create Conditions user_pattern COLUMN_SCALAR ShortText +.. column_create Conditions tag COLUMN_SCALAR Tags +.. column_create Conditions max_length COLUMN_SCALAR UInt32 +.. +.. table_create Memos TABLE_HASH_KEY ShortText +.. column_create Memos user COLUMN_SCALAR ShortText +.. column_create Memos tag COLUMN_SCALAR Tags + +Sample data: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_setup_data.log +.. load --table Memos +.. [ +.. {"_key": "Groonga is fast", "user": "alice", "tag": "groonga"}, +.. {"_key": "Mroonga is fast", "user": "alice", "tag": "mroonga"}, +.. {"_key": "Groonga is very good!", "user": "alice", "tag": "groonga"}, +.. {"_key": "Droonga is fast", "user": "david", "tag": "droonga"}, +.. {"_key": "Groonga is a HTTP server", "user": "david", "tag": "groonga"} +.. ] + +Sample conditions: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_setup_conditions.log +.. load --table Conditions +.. [ +.. {"_key": "lic + groonga", "user_pattern": "lic", "tag": "groonga", max_length: 20}, +.. {"_key": "dav + droonga", "user_pattern": "dav", "tag": "droonga", max_length: 50} +.. ] + +Here is a simple usage of ``in_records`` that searches by records in ``Conditions`` table. Each record is used as a condition: + +.. groonga-command +.. include:: ../../example/reference/functions/in_records/usage_search.log +.. plugin_register functions/string +.. select \ +.. --table Memos \ +.. --filter 'in_records(Conditions, \ +.. user, "@", "user_pattern", \ +.. tag, "==", "tag", \ +.. string_length(_key), "<=", "max_length")' \ +.. --sort_by _id \ +.. --output_columns _key,user,tag + +The ``filter`` tries the following three conditions for each record: + + * ``Memos.user`` matches (``@``) ``Conditions.user_pattern``. + + * ``Memos.tag`` equals (``==``) ``Conditions.tag``. + + * The number of characters in ``Memos._key`` is less than or equals to ``Conditions.max_length``. + +If at least one record in ``Conditions`` table returns true for the all three conditions, the record in ``Memos`` is matched. + +The first record in ``Conditions`` table use the following conditions: + + * ``Memos.user`` has ``"lic"`` substring. + + * ``Memos.tag`` is ``"groonga"``. + + * The number of characters in ``Memos._key`` is less than or equals to ``20``. + +This condition matches the following records: + + * ``{"_key": "Groonga is fast", "user": "alice", "tag": "groonga"}`` + +The second record in ``Conditions`` table use the following conditions: + + * ``Memos.user`` has ``"dav"`` substring. + + * ``Memos.tag`` is ``"droonga"``. + + * The number of characters in ``Memos._key`` is less than or equals to ``50``. + +This condition matches the following records: + + * ``{"_key": "Droonga is fast", "user": "david", "tag": "droonga"}`` + +The result has the all above records. + +.. _in-records-parameters: + +Parameters +---------- + +``in_records`` requires four or more parameters. + +.. _in-records-required-parameters: + +Required parameters +^^^^^^^^^^^^^^^^^^^ + +``condition_table`` and tuples of ``value``, ``mode_name`` and ``condition_column_name`` are required. You can specify multiple tuples of ``value``, ``mode_name`` and ``condition_column_name`` + +.. _in-records-condition-table: + +``condition_table`` +""""""""""""""""""" + +Specifies a table that has conditions as its records. + +.. _in-records-value: + +``value`` +^^^^^^^^^ + +Specifies a value to be compared. + +.. _in-records-mode-name: + +``mode_name`` +^^^^^^^^^^^^^ + +Specifies a mode name that specifies how to compare :ref:`in-records-value` with a value of :ref:`in-records-condition-column-name`. + +See :ref:`query-default-mode` for available mode names. All mode names except ``NEAR``, ``SIMILAR`` and ``SUFFIX`` are supported. + +.. _in-records-condition-column-name: + +``condition_column_name`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Specifies a column name of :ref:`in-records-condition-table` to be used as condition. + +.. _in-records-optional-parameters: + +Optional parameter +^^^^^^^^^^^^^^^^^^ + +There are no optional parameter. + +Return value +------------ + +``in_records`` returns whether the record is matched one of records of the specified condition table or not. + +If the record is matched, it returns ``true``. Otherwise, it returns ``false``. -------------- next part -------------- HTML����������������������������...Download