File: index.html

package info (click to toggle)
groonga 11.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,576 kB
  • sloc: ansic: 801,209; javascript: 62,121; ruby: 46,206; cpp: 33,790; xml: 24,951; yacc: 13,333; sh: 7,776; python: 3,266; makefile: 2,315; perl: 133
file content (559 lines) | stat: -rw-r--r-- 20,534 bytes parent folder | download
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559


<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>4.6. Tag search and reverse resolution of reference relationships &#8212; 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="4.7. match_columns parameter" href="match_columns.html" />
    <link rel="prev" title="4.5. Drilldown" href="drilldown.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/index.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="match_columns.html" title="4.7. match_columns parameter"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="drilldown.html" title="4.5. Drilldown"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../tutorial.html" accesskey="U"><span class="section-number">4. </span>Tutorial</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">4.6. </span>Tag search and reverse resolution of reference relationships</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="tag-search-and-reverse-resolution-of-reference-relationships">
<h1><span class="section-number">4.6. </span>Tag search and reverse resolution of reference relationships<a class="headerlink" href="#tag-search-and-reverse-resolution-of-reference-relationships" title="Permalink to this headline">¶</a></h1>
<p>As you know, Groonga supports to store array in column which refers other table.
In fact, you can do tag search by using array data which refers other table.</p>
<p>Tag search is very fast because Groonga use inverted index as data structure.</p>
<div class="section" id="tag-search">
<h2><span class="section-number">4.6.1. </span>Tag search<a class="headerlink" href="#tag-search" title="Permalink to this headline">¶</a></h2>
<p>Let’s consider to create a search engine for an web site to share movies. Each movie may be associated with multiple keywords which represents the content of movie.</p>
<p>Let’s create tables for movie information, then search the movies.</p>
<p>First, create the <code class="docutils literal notranslate"><span class="pre">Video</span></code> table which stores movie information. the <code class="docutils literal notranslate"><span class="pre">Video</span></code> table has two columns. the <code class="docutils literal notranslate"><span class="pre">title</span></code> column stores title of the movie. the <code class="docutils literal notranslate"><span class="pre">tags</span></code> column stores multiple tag information in reference Tag table.</p>
<p>Next, create the <code class="docutils literal notranslate"><span class="pre">Tag</span></code> table which stores tag information. the <code class="docutils literal notranslate"><span class="pre">Tag</span></code> table has one column. The tag string is stored as primary key, then <code class="docutils literal notranslate"><span class="pre">index_tags</span></code> stores indexes for tags column of Video table.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create --name Video --flags TABLE_HASH_KEY --key_type UInt32
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create --name Tag --flags TABLE_HASH_KEY --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table Video --name title --flags COLUMN_SCALAR --type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table Video --name tags --flags COLUMN_VECTOR --type Tag
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table Tag --name index_tags --flags COLUMN_INDEX --type Video --source tags
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Video
[
{&quot;_key&quot;:1,&quot;title&quot;:&quot;Soccer 2010&quot;,&quot;tags&quot;:[&quot;Sports&quot;,&quot;Soccer&quot;]},
{&quot;_key&quot;:2,&quot;title&quot;:&quot;Zenigata Kinjirou&quot;,&quot;tags&quot;:[&quot;Variety&quot;,&quot;Money&quot;]},
{&quot;_key&quot;:3,&quot;title&quot;:&quot;groonga Demo&quot;,&quot;tags&quot;:[&quot;IT&quot;,&quot;Server&quot;,&quot;groonga&quot;]},
{&quot;_key&quot;:4,&quot;title&quot;:&quot;Moero!! Ultra Baseball&quot;,&quot;tags&quot;:[&quot;Sports&quot;,&quot;Baseball&quot;]},
{&quot;_key&quot;:5,&quot;title&quot;:&quot;Hex Gone!&quot;,&quot;tags&quot;:[&quot;Variety&quot;,&quot;Quiz&quot;]},
{&quot;_key&quot;:6,&quot;title&quot;:&quot;Pikonyan 1&quot;,&quot;tags&quot;:[&quot;Animation&quot;,&quot;Pikonyan&quot;]},
{&quot;_key&quot;:7,&quot;title&quot;:&quot;Draw 8 Month&quot;,&quot;tags&quot;:[&quot;Animation&quot;,&quot;Raccoon&quot;]},
{&quot;_key&quot;:8,&quot;title&quot;:&quot;K.O.&quot;,&quot;tags&quot;:[&quot;Animation&quot;,&quot;Music&quot;]}
]
# [[0, 1337566253.89858, 0.000355720520019531], 8]
</pre></div>
</div>
<p>After creating indexed column, you can do full-text search very fast. The indexed column is also automatically updated when stored data is refreshed.</p>
<p>List up the movies that specific keywords are given.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select --table Video --query tags:@Variety --output_columns _key,title
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Zenigata Kinjirou&quot;
#       ],
#       [
#         5,
#         &quot;Hex Gone!&quot;
#       ]
#     ]
#   ]
# ]
select --table Video --query tags:@Sports --output_columns _key,title
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;Soccer 2010&quot;
#       ],
#       [
#         4,
#         &quot;Moero!! Ultra Baseball&quot;
#       ]
#     ]
#   ]
# ]
select --table Video --query tags:@Animation --output_columns _key,title
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         6,
#         &quot;Pikonyan 1&quot;
#       ],
#       [
#         7,
#         &quot;Draw 8 Month&quot;
#       ],
#       [
#         8,
#         &quot;K.O.&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>You can search by tags such as “Variety”, “Sports” and “Animation”.</p>
</div>
<div class="section" id="reverse-resolution-of-reference-relationships">
<h2><span class="section-number">4.6.2. </span>Reverse resolution of reference relationships<a class="headerlink" href="#reverse-resolution-of-reference-relationships" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports indexes for reverse resolution among tables. Tag search is one of concrete examples.</p>
<p>For example, you can search friendships by reverse resolution in social networking site.</p>
<p>Following example shows how to create <code class="docutils literal notranslate"><span class="pre">User</span></code> table which stores user information, <code class="docutils literal notranslate"><span class="pre">username</span></code> column which stores user name, <code class="docutils literal notranslate"><span class="pre">friends</span></code> column which stores list of user’s friends in array, <code class="docutils literal notranslate"><span class="pre">index_friends</span></code> column as indexed column.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create --name User --flags TABLE_HASH_KEY --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table User --name username --flags COLUMN_SCALAR --type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table User --name friends --flags COLUMN_VECTOR --type User
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table User --name index_friends --flags COLUMN_INDEX --type User --source friends
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table User
[
{&quot;_key&quot;:&quot;ken&quot;,&quot;username&quot;:&quot;健作&quot;,&quot;friends&quot;:[&quot;taro&quot;,&quot;jiro&quot;,&quot;tomo&quot;,&quot;moritapo&quot;]}
{&quot;_key&quot;:&quot;moritapo&quot;,&quot;username&quot;:&quot;森田&quot;,&quot;friends&quot;:[&quot;ken&quot;,&quot;tomo&quot;]}
{&quot;_key&quot;:&quot;taro&quot;,&quot;username&quot;:&quot;ぐるんが太郎&quot;,&quot;friends&quot;:[&quot;jiro&quot;,&quot;tomo&quot;]}
{&quot;_key&quot;:&quot;jiro&quot;,&quot;username&quot;:&quot;ぐるんが次郎&quot;,&quot;friends&quot;:[&quot;taro&quot;,&quot;tomo&quot;]}
{&quot;_key&quot;:&quot;tomo&quot;,&quot;username&quot;:&quot;トモちゃん&quot;,&quot;friends&quot;:[&quot;ken&quot;,&quot;hana&quot;]}
{&quot;_key&quot;:&quot;hana&quot;,&quot;username&quot;:&quot;花子&quot;,&quot;friends&quot;:[&quot;ken&quot;,&quot;taro&quot;,&quot;jiro&quot;,&quot;moritapo&quot;,&quot;tomo&quot;]}
]
# [[0, 1337566253.89858, 0.000355720520019531], 6]
</pre></div>
</div>
<p>Let’s show list of users who contains specified user in friend list.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select --table User --query friends:@tomo --output_columns _key,username
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         5
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;username&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         &quot;ken&quot;,
#         &quot;健作&quot;
#       ],
#       [
#         &quot;taro&quot;,
#         &quot;ぐるんが太郎&quot;
#       ],
#       [
#         &quot;jiro&quot;,
#         &quot;ぐるんが次郎&quot;
#       ],
#       [
#         &quot;moritapo&quot;,
#         &quot;森田&quot;
#       ],
#       [
#         &quot;hana&quot;,
#         &quot;花子&quot;
#       ]
#     ]
#   ]
# ]
select --table User --query friends:@jiro --output_columns _key,username
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;username&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         &quot;ken&quot;,
#         &quot;健作&quot;
#       ],
#       [
#         &quot;taro&quot;,
#         &quot;ぐるんが太郎&quot;
#       ],
#       [
#         &quot;hana&quot;,
#         &quot;花子&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>Then drilldown the count which shows user is listed as friend.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select --table User --limit 0 --drilldown friends
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         6
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;friends&quot;,
#           &quot;User&quot;
#         ],
#         [
#           &quot;index_friends&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;username&quot;,
#           &quot;ShortText&quot;
#         ]
#       ]
#     ],
#     [
#       [
#         6
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;taro&quot;,
#         3
#       ],
#       [
#         &quot;jiro&quot;,
#         3
#       ],
#       [
#         &quot;tomo&quot;,
#         5
#       ],
#       [
#         &quot;moritapo&quot;,
#         2
#       ],
#       [
#         &quot;ken&quot;,
#         3
#       ],
#       [
#         &quot;hana&quot;,
#         1
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>As you can see, it shows the results which follows reverse resolution of reference relationship.</p>
</div>
<div class="section" id="geo-location-search-with-index">
<h2><span class="section-number">4.6.3. </span>Geo location search with index<a class="headerlink" href="#geo-location-search-with-index" title="Permalink to this headline">¶</a></h2>
<p>Groonga supports to add indexes to the column which stores geo location information.
Groonga is very fast because it use such indexes against the column which contains geo location information to search enormous number of records.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create --name GeoSite --flags TABLE_HASH_KEY --key_type ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table GeoSite --name location --type WGS84GeoPoint
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create --name GeoIndex --flags TABLE_PAT_KEY --key_type WGS84GeoPoint
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create --table GeoIndex --name index_point --type GeoSite --flags COLUMN_INDEX --source location
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table GeoSite
[
 {&quot;_key&quot;:&quot;http://example.org/&quot;,&quot;location&quot;:&quot;128452975x503157902&quot;},
 {&quot;_key&quot;:&quot;http://example.net/&quot;,&quot;location&quot;:&quot;128487316x502920929&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
select --table GeoSite --filter &#39;geo_in_circle(location, &quot;128515259x503187188&quot;, 5000)&#39; --output_columns _key,location
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ]
#       ],
#       [
#         &quot;http://example.org/&quot;,
#         &quot;128452975x503157902&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>These indexes are also used when sorting the records with geo location search.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select --table GeoSite --filter &#39;geo_in_circle(location, &quot;128515259x503187188&quot;, 50000)&#39; --output_columns _key,location,_score --sort_keys &#39;-geo_distance(location, &quot;128515259x503187188&quot;)&#39; --scorer &#39;_score = geo_distance(location, &quot;128515259x503187188&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://example.org/&quot;,
#         &quot;128452975x503157902&quot;,
#         2054
#       ],
#       [
#         &quot;http://example.net/&quot;,
#         &quot;128487316x502920929&quot;,
#         6720
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</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.6. Tag search and reverse resolution of reference relationships</a><ul>
<li><a class="reference internal" href="#tag-search">4.6.1. Tag search</a></li>
<li><a class="reference internal" href="#reverse-resolution-of-reference-relationships">4.6.2. Reverse resolution of reference relationships</a></li>
<li><a class="reference internal" href="#geo-location-search-with-index">4.6.3. Geo location search with index</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="drilldown.html"
                        title="previous chapter"><span class="section-number">4.5. </span>Drilldown</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="match_columns.html"
                        title="next chapter"><span class="section-number">4.7. </span>match_columns parameter</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="match_columns.html" title="4.7. match_columns parameter"
             >next</a> |</li>
        <li class="right" >
          <a href="drilldown.html" title="4.5. Drilldown"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../tutorial.html" ><span class="section-number">4. </span>Tutorial</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">4.6. </span>Tag search and reverse resolution of reference relationships</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2009-2021, Brazil, Inc.
    </div>
  </body>
</html>