Sophie

Sophie

distrib > Fedora > 18 > x86_64 > media > updates > by-pkgid > e450e7f3d6075c4a54de19e68d38177f > files > 348

groonga-doc-3.0.5-1.fc18.x86_64.rpm


<!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>4.8. パトリシア木による前方一致検索 &mdash; 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="4. Tutorial" href="../tutorial.html" />
    <link rel="next" title="4.9. 全文検索の語彙表に対する追加情報" href="lexicon.html" />
    <link rel="prev" title="4.7. match_columnsパラメータ" href="match_columns.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/tutorial/patricia_trie.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="lexicon.html" title="4.9. 全文検索の語彙表に対する追加情報"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="match_columns.html" title="4.7. match_columnsパラメータ"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">groonga v3.0.5 documentation</a> &raquo;</li>
          <li><a href="../tutorial.html" accesskey="U">4. Tutorial</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="id1">
<h1>4.8. パトリシア木による前方一致検索<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1>
<p>groongaのテーブルは、テーブル作成時にパトリシア木オプションを指定すると、前方一致検索を行うことができます。また、追加のオプションを指定することにより、主キーの後方一致検索をも行うことができます。</p>
<div class="section" id="id2">
<h2>4.8.1. 主キーによる前方一致検索<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>table_createコマンドのflagsオプションにTABLE_PAT_KEYを指定することで、主キーによる前方一致検索ができるようになります。</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>table_create --name PatPrefix --flags TABLE_PAT_KEY --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table PatPrefix
[
{&quot;_key&quot;:&quot;ひろゆき&quot;},
{&quot;_key&quot;:&quot;まろゆき&quot;},
{&quot;_key&quot;:&quot;ひろあき&quot;},
{&quot;_key&quot;:&quot;ゆきひろ&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 4]
select --table PatPrefix --query _key:^ひろ
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;ひろゆき&quot;
#       ],
#       [
#         3,
#         &quot;ひろあき&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>4.8.2. 主キーによる後方一致検索<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>table_createコマンドのflagsオプションにTABLE_PAT_KEYとKEY_WITH_SISを指定することで、主キーによる前方一致検索・後方一致検索の両方が可能となります。</p>
<p>KEY_WITH_SISフラグを付与すると、データを追加する際に後方一致用のレコードも追加されてしまいます。そのため、単純に検索すると、元のレコードに加えて自動的に追加されたレコードまでヒットしてしまいます。元のレコードのみ検索するために、一工夫必要になります。</p>
<p>例えば、元のレコードと自動的に追加されたレコードとの区別をつけるために、元のレコードであることを示すoriginalカラムを追加して、検索時にはoriginalカラムが <tt class="docutils literal"><span class="pre">true</span></tt> も検索条件に加えます。 <tt class="docutils literal"><span class="pre">--query</span></tt> オプションでは <tt class="docutils literal"><span class="pre">Bool</span></tt> 型の値を直感的に指定することができないので <tt class="docutils literal"><span class="pre">--filter</span></tt> オプションを使っていることに注意してください。</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>table_create --name PatSuffix --flags TABLE_PAT_KEY|KEY_WITH_SIS --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table PatSuffix --name original --type Bool
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table PatSuffix
[
{&quot;_key&quot;:&quot;ひろゆき&quot;,&quot;original&quot;:true},
{&quot;_key&quot;:&quot;まろゆき&quot;,&quot;original&quot;:true},
{&quot;_key&quot;:&quot;ひろあき&quot;,&quot;original&quot;:true},
{&quot;_key&quot;:&quot;ゆきひろ&quot;,&quot;original&quot;:true}
]
# [[0, 1337566253.89858, 0.000355720520019531], 4]
select --table PatSuffix --query _key:$ゆき
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         4
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;original&quot;,
#           &quot;Bool&quot;
#         ]
#       ],
#       [
#         3,
#         &quot;ゆき&quot;,
#         false
#       ],
#       [
#         2,
#         &quot;ろゆき&quot;,
#         false
#       ],
#       [
#         5,
#         &quot;まろゆき&quot;,
#         true
#       ],
#       [
#         1,
#         &quot;ひろゆき&quot;,
#         true
#       ]
#     ]
#   ]
# ]
select --table PatSuffix --filter &#39;_key @$ &quot;ゆき&quot; &amp;&amp; original == true&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;original&quot;,
#           &quot;Bool&quot;
#         ]
#       ],
#       [
#         5,
#         &quot;まろゆき&quot;,
#         true
#       ],
#       [
#         1,
#         &quot;ひろゆき&quot;,
#         true
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</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="#">4.8. パトリシア木による前方一致検索</a><ul>
<li><a class="reference internal" href="#id2">4.8.1. 主キーによる前方一致検索</a></li>
<li><a class="reference internal" href="#id3">4.8.2. 主キーによる後方一致検索</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="match_columns.html"
                        title="previous chapter">4.7. match_columnsパラメータ</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="lexicon.html"
                        title="next chapter">4.9. 全文検索の語彙表に対する追加情報</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/tutorial/patricia_trie.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="lexicon.html" title="4.9. 全文検索の語彙表に対する追加情報"
             >next</a> |</li>
        <li class="right" >
          <a href="match_columns.html" title="4.7. match_columnsパラメータ"
             >previous</a> |</li>
        <li><a href="../index.html">groonga v3.0.5 documentation</a> &raquo;</li>
          <li><a href="../tutorial.html" >4. Tutorial</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2013, Brazil, Inc.
    </div>
  </body>
</html>