1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>4.11. Query expansion — Groonga v10.1.1-31-g1e46ba6 documentation</title>
<link rel="stylesheet" href="../_static/groonga.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.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="next" title="5. Server" href="../server.html" />
<link rel="prev" title="4.10. Let’s create micro-blog" href="micro_blog.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/query_expansion.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="../server.html" title="5. Server"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="micro_blog.html" title="4.10. Let’s create micro-blog"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="../tutorial.html" accesskey="U"><span class="section-number">4. </span>Tutorial</a> »</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4.11. </span>Query expansion</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="query-expansion">
<h1><span class="section-number">4.11. </span>Query expansion<a class="headerlink" href="#query-expansion" title="Permalink to this headline">¶</a></h1>
<p>Groonga accepts <code class="docutils literal notranslate"><span class="pre">query_expander</span></code> parameter for <a class="reference internal" href="../reference/commands/select.html"><span class="doc">select</span></a> command.
It enables you to extend your query string.</p>
<p>For example, if user searches “theatre” instead of “theater”,
query expansion enables to return search results of “theatre OR theater”.
This kind of way reduces search leakages. This is what really user wants.</p>
<div class="section" id="preparation">
<h2><span class="section-number">4.11.1. </span>Preparation<a class="headerlink" href="#preparation" title="Permalink to this headline">¶</a></h2>
<p>To use query expansion, you need to create table which stores documents, synonym table which stores query string and replacement string.
In synonym table, primary key represents original string, the column of ShortText represents modified string.</p>
<p>Let’s create document table and synonym table.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Doc TABLE_PAT_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Doc body COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Term TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Term Doc_body COLUMN_INDEX|WITH_POSITION Doc body
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Synonym TABLE_PAT_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Synonym body COLUMN_VECTOR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Doc
[
{"_key": "001", "body": "Play all night in this theater."},
{"_key": "002", "body": "theatre is British spelling."},
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
load --table Synonym
[
{"_key": "theater", "body": ["theater", "theatre"]},
{"_key": "theatre", "body": ["theater", "theatre"]},
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
</pre></div>
</div>
<p>In this case, it doesn’t occur search leakage because it creates synonym table which accepts “theatre” and “theater” as query string.</p>
</div>
<div class="section" id="search">
<h2><span class="section-number">4.11.2. </span>Search<a class="headerlink" href="#search" title="Permalink to this headline">¶</a></h2>
<p>Then, let’s use prepared synonym table.
First, use select command without <code class="docutils literal notranslate"><span class="pre">query_expander</span></code> parameter.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Doc --match_columns body --query "theater"
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 1
# ],
# [
# [
# "_id",
# "UInt32"
# ],
# [
# "_key",
# "ShortText"
# ],
# [
# "body",
# "ShortText"
# ]
# ],
# [
# 1,
# "001",
# "Play all night in this theater."
# ]
# ]
# ]
# ]
select Doc --match_columns body --query "theatre"
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 1
# ],
# [
# [
# "_id",
# "UInt32"
# ],
# [
# "_key",
# "ShortText"
# ],
# [
# "body",
# "ShortText"
# ]
# ],
# [
# 2,
# "002",
# "theatre is British spelling."
# ]
# ]
# ]
# ]
</pre></div>
</div>
<p>Above query returns the record which completely equal to query string.</p>
<p>Then, use <code class="docutils literal notranslate"><span class="pre">query_expander</span></code> parameter against <code class="docutils literal notranslate"><span class="pre">body</span></code> column of <code class="docutils literal notranslate"><span class="pre">Synonym</span></code> table.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Doc --match_columns body --query "theater" --query_expander Synonym.body
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 2
# ],
# [
# [
# "_id",
# "UInt32"
# ],
# [
# "_key",
# "ShortText"
# ],
# [
# "body",
# "ShortText"
# ]
# ],
# [
# 1,
# "001",
# "Play all night in this theater."
# ],
# [
# 2,
# "002",
# "theatre is British spelling."
# ]
# ]
# ]
# ]
select Doc --match_columns body --query "theatre" --query_expander Synonym.body
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# [
# [
# [
# 2
# ],
# [
# [
# "_id",
# "UInt32"
# ],
# [
# "_key",
# "ShortText"
# ],
# [
# "body",
# "ShortText"
# ]
# ],
# [
# 1,
# "001",
# "Play all night in this theater."
# ],
# [
# 2,
# "002",
# "theatre is British spelling."
# ]
# ]
# ]
# ]
</pre></div>
</div>
<p>In which cases, query string is replaced to “(theater OR theatre)”, thus synonym is considered for full text search.</p>
</div>
</div>
<div class="clearer"></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="#">4.11. Query expansion</a><ul>
<li><a class="reference internal" href="#preparation">4.11.1. Preparation</a></li>
<li><a class="reference internal" href="#search">4.11.2. Search</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="micro_blog.html"
title="previous chapter"><span class="section-number">4.10. </span>Let’s create micro-blog</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../server.html"
title="next chapter"><span class="section-number">5. </span>Server</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#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="../server.html" title="5. Server"
>next</a> |</li>
<li class="right" >
<a href="micro_blog.html" title="4.10. Let’s create micro-blog"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="../tutorial.html" ><span class="section-number">4. </span>Tutorial</a> »</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4.11. </span>Query expansion</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2009-2021, Brazil, Inc.
</div>
</body>
</html>
|