File: vector.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 (865 lines) | stat: -rw-r--r-- 35,648 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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865


<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>7.6.2. Vector column &#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="7.6.3. Pseudo column" href="pseudo.html" />
    <link rel="prev" title="7.6.1. Scalar column" href="scalar.html" /> 
  </head><body>
<div class="header">
  <h1 class="title">
    <a id="top-link" href="../../index.html">
      <span class="project">groonga</span>
      <span class="separator">-</span>
      <span class="description">An open-source fulltext search engine and column store.</span>
    </a>
  </h1>

  <div class="other-language-links">
    <ul>
      <li><a href="../../../../ja/html/reference/columns/vector.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="pseudo.html" title="7.6.3. Pseudo column"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="scalar.html" title="7.6.1. Scalar column"
             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="../../reference.html" ><span class="section-number">7. </span>Reference manual</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../column.html" accesskey="U"><span class="section-number">7.6. </span>Column</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">7.6.2. </span>Vector column</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="vector-column">
<h1><span class="section-number">7.6.2. </span>Vector column<a class="headerlink" href="#vector-column" title="Permalink to this headline">¶</a></h1>
<div class="section" id="summary">
<h2><span class="section-number">7.6.2.1. </span>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
<p>Vector column is a data store object. It can stores zero or more
scalar values. In short, scalar value is a single value such as number
and string. See <a class="reference internal" href="scalar.html"><span class="doc">Scalar column</span></a> about scalar value details.</p>
<p>One of vector column use cases is tags store. You can use a vector
column to store tag values.</p>
<p>You can use vector column as index search target in the same way as
scalar column. You can set weight for each element. The element that
has one or more weight is matched, the record has more score rather
than no weight case. It is a vector column specific feature. Vector
column that can store weight is called weight vector column.</p>
<p>You can also do full text search against each text element. But search
score is too high when weight is used. You should use full text search
with weight carefully.</p>
</div>
<div class="section" id="usage">
<h2><span class="section-number">7.6.2.2. </span>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>There are three vector column types:</p>
<blockquote>
<div><ul class="simple">
<li><p>Normal vector column</p></li>
<li><p>Reference vector column</p></li>
<li><p>Weight vector column</p></li>
</ul>
</div></blockquote>
<p>This section describes how to use these types.</p>
<div class="section" id="normal-vector-column">
<span id="id1"></span><h3><span class="section-number">7.6.2.2.1. </span>Normal vector column<a class="headerlink" href="#normal-vector-column" title="Permalink to this headline">¶</a></h3>
<p>Normal vector column stores zero or more scalar data. For example,
scalar data are number, string and so on.</p>
<p>A normal vector column can store the same type elements. You can’t mix
types. For example, you can’t store a number and a string in the same
normal vector column.</p>
<p>Normal vector column is useful when a record has multiple values with
a key. Tags are the most popular use case.</p>
<div class="section" id="how-to-create">
<h4><span class="section-number">7.6.2.2.1.1. </span>How to create<a class="headerlink" href="#how-to-create" title="Permalink to this headline">¶</a></h4>
<p>Use <a class="reference internal" href="../commands/column_create.html"><span class="doc">column_create</span></a> command to create a
normal vector column. The point is <code class="docutils literal notranslate"><span class="pre">COLUMN_VECTOR</span></code> flag:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Bookmarks TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Bookmarks tags COLUMN_VECTOR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
</pre></div>
</div>
<p>You can set zero or more tags to a bookmark.</p>
</div>
<div class="section" id="how-to-load">
<h4><span class="section-number">7.6.2.2.1.2. </span>How to load<a class="headerlink" href="#how-to-load" title="Permalink to this headline">¶</a></h4>
<p>You can load vector data by JSON array syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[ELEMENT1, ELEMENT2, ELEMENT3, ...]
</pre></div>
</div>
<p>Let’s load the following data:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">_key</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">tags</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">http://groonga.org/</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">[&quot;groonga&quot;]</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">http://mroonga.org/</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">[&quot;mroonga&quot;,</span> <span class="pre">&quot;mysql&quot;,</span> <span class="pre">&quot;groonga&quot;]</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">http://ranguba.org/</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">[&quot;ruby&quot;,</span> <span class="pre">&quot;groonga&quot;]</span></code></p></td>
</tr>
</tbody>
</table>
<p>Here is a command that loads the data:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>load --table Bookmarks
[
{&quot;_key&quot;: &quot;http://groonga.org/&quot;, &quot;tags&quot;: [&quot;groonga&quot;]},
{&quot;_key&quot;: &quot;http://mroonga.org/&quot;, &quot;tags&quot;: [&quot;mroonga&quot;, &quot;mysql&quot;, &quot;groonga&quot;]},
{&quot;_key&quot;: &quot;http://ranguba.org/&quot;, &quot;tags&quot;: [&quot;ruby&quot;, &quot;groonga&quot;]}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
</pre></div>
</div>
<p>The loaded data can be outputted as JSON array syntax:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;http://groonga.org/&quot;,
#         [
#           &quot;groonga&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;http://mroonga.org/&quot;,
#         [
#           &quot;mroonga&quot;,
#           &quot;mysql&quot;,
#           &quot;groonga&quot;
#         ]
#       ],
#       [
#         3,
#         &quot;http://ranguba.org/&quot;,
#         [
#           &quot;ruby&quot;,
#           &quot;groonga&quot;
#         ]
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="how-to-search">
<h4><span class="section-number">7.6.2.2.1.3. </span>How to search<a class="headerlink" href="#how-to-search" title="Permalink to this headline">¶</a></h4>
<p>You need to create an index to search normal vector column:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Tags TABLE_PAT_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Tags bookmark_index COLUMN_INDEX Bookmarks tags
# [[0, 1337566253.89858, 0.000355720520019531], true]
</pre></div>
</div>
<p>There is no vector column specific way. You can create an index like
a scalar column.</p>
<p>You can search an element in <code class="docutils literal notranslate"><span class="pre">tags</span></code> like full text search syntax.</p>
<p>With <a class="reference internal" href="../commands/select.html#select-match-columns"><span class="std std-ref">match_columns</span></a> and <a class="reference internal" href="../commands/select.html#select-query"><span class="std std-ref">query</span></a>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks --match_columns tags --query mysql --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://mroonga.org/&quot;,
#         [
#           &quot;mroonga&quot;,
#           &quot;mysql&quot;,
#           &quot;groonga&quot;
#         ],
#         1
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>You can also use weight in <a class="reference internal" href="../commands/select.html#select-match-columns"><span class="std std-ref">match_columns</span></a>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks --match_columns &#39;tags * 3&#39; --query mysql --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://mroonga.org/&quot;,
#         [
#           &quot;mroonga&quot;,
#           &quot;mysql&quot;,
#           &quot;groonga&quot;
#         ],
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>With <a class="reference internal" href="../commands/select.html#select-filter"><span class="std std-ref">filter</span></a>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks --filter &#39;tags @ &quot;msyql&quot;&#39; --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         0
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
</div>
<div class="section" id="reference-vector-column">
<span id="id2"></span><h3><span class="section-number">7.6.2.2.2. </span>Reference vector column<a class="headerlink" href="#reference-vector-column" title="Permalink to this headline">¶</a></h3>
<p>TODO</p>
<p>Reference vector column is space-efficient if there are many same
value elements. Reference vector column keeps reference record IDs not
value itself. Record ID is smaller than value itself.</p>
<div class="section" id="id3">
<h4><span class="section-number">7.6.2.2.2.1. </span>How to create<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h4>
<p>TODO</p>
</div>
<div class="section" id="id4">
<h4><span class="section-number">7.6.2.2.2.2. </span>How to load<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h4>
<p>TODO</p>
</div>
<div class="section" id="id5">
<h4><span class="section-number">7.6.2.2.2.3. </span>How to search<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h4>
<p>TODO</p>
</div>
</div>
<div class="section" id="weight-vector-column">
<span id="id6"></span><h3><span class="section-number">7.6.2.2.3. </span>Weight vector column<a class="headerlink" href="#weight-vector-column" title="Permalink to this headline">¶</a></h3>
<p>Weight vector column is similar to normal vector column. It can store
elements. It can also stores weights for them. Weight is degree of
importance of the element.</p>
<p>Weight is positive integer. <code class="docutils literal notranslate"><span class="pre">0</span></code> is the default weight. It means that
no weight.</p>
<p>If weight is one or larger, search score is increased by the
weight. If the weight is <code class="docutils literal notranslate"><span class="pre">0</span></code>, score is <code class="docutils literal notranslate"><span class="pre">1</span></code>. If the weight is
<code class="docutils literal notranslate"><span class="pre">10</span></code>, score is <code class="docutils literal notranslate"><span class="pre">11</span></code> (<code class="docutils literal notranslate"><span class="pre">=</span> <span class="pre">1</span> <span class="pre">+</span> <span class="pre">10</span></code>).</p>
<p>Weight vector column is useful for tuning search score. See also
<a class="reference internal" href="../commands/select.html#select-adjuster"><span class="std std-ref">adjuster</span></a>. You can increase search score of specific
records.</p>
<div class="section" id="limitations">
<h4><span class="section-number">7.6.2.2.3.1. </span>Limitations<a class="headerlink" href="#limitations" title="Permalink to this headline">¶</a></h4>
<p>There are some limitations for now. They will be resolved in the
future.</p>
<p>Here are limitations:</p>
<blockquote>
<div><ul class="simple">
<li><p>You need to use string representation for element value on load.
For example, you can’t use <code class="docutils literal notranslate"><span class="pre">29</span></code> for number 29. You need to use
<code class="docutils literal notranslate"><span class="pre">&quot;29&quot;</span></code> for number 29.</p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="id7">
<h4><span class="section-number">7.6.2.2.3.2. </span>How to create<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h4>
<p>Use <a class="reference internal" href="../commands/column_create.html"><span class="doc">column_create</span></a> command to create a
weight vector column. The point is <code class="docutils literal notranslate"><span class="pre">COLUMN_VECTOR|WITH_WEIGHT</span></code>
flags:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Bookmarks TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Bookmarks tags COLUMN_VECTOR|WITH_WEIGHT ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
</pre></div>
</div>
<p>If you don’t specify <code class="docutils literal notranslate"><span class="pre">WITH_WEIGHT</span></code> flag, it is just a normal vector
column.</p>
<p>You can set zero or more tags with weight to a bookmark.</p>
</div>
<div class="section" id="id8">
<h4><span class="section-number">7.6.2.2.3.3. </span>How to load<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h4>
<p>You can load vector data by JSON object syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>{&quot;ELEMENT1&quot;: WEIGHT1, &quot;ELEMENT2&quot;: WEIGHT2, &quot;ELEMENT3&quot;: WEIGHT3, ...}
</pre></div>
</div>
<p>Let’s load the following data:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">_key</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">tags</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">http://groonga.org/</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{&quot;groonga&quot;:</span> <span class="pre">100}</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">http://mroonga.org/</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{&quot;mroonga&quot;:</span> <span class="pre">100,</span> <span class="pre">&quot;mysql&quot;:</span> <span class="pre">50,</span> <span class="pre">&quot;groonga&quot;:</span> <span class="pre">10}</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">http://ranguba.org/</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{&quot;ruby&quot;:</span> <span class="pre">100,</span> <span class="pre">&quot;groonga&quot;:</span> <span class="pre">50}</span></code></p></td>
</tr>
</tbody>
</table>
<p>Here is a command that loads the data:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>load --table Bookmarks
[
{&quot;_key&quot;: &quot;http://groonga.org/&quot;,
 &quot;tags&quot;: {&quot;groonga&quot;: 100}},
{&quot;_key&quot;: &quot;http://mroonga.org/&quot;,
 &quot;tags&quot;: {&quot;mroonga&quot;: 100,
          &quot;mysql&quot;:   50,
          &quot;groonga&quot;: 10}},
{&quot;_key&quot;: &quot;http://ranguba.org/&quot;,
 &quot;tags&quot;: {&quot;ruby&quot;: 100,
          &quot;groonga&quot;: 50}}
]
# [[0, 1337566253.89858, 0.000355720520019531], 3]
</pre></div>
</div>
<p>The loaded data can be outputted as JSON object syntax:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;http://groonga.org/&quot;,
#         {
#           &quot;groonga&quot;: 100
#         }
#       ],
#       [
#         2,
#         &quot;http://mroonga.org/&quot;,
#         {
#           &quot;mroonga&quot;: 100,
#           &quot;groonga&quot;: 10,
#           &quot;mysql&quot;: 50
#         }
#       ],
#       [
#         3,
#         &quot;http://ranguba.org/&quot;,
#         {
#           &quot;ruby&quot;: 100,
#           &quot;groonga&quot;: 50
#         }
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="id9">
<h4><span class="section-number">7.6.2.2.3.4. </span>How to search<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h4>
<p>You need to create an index to search weight vector column. You don’t
forget to specify <code class="docutils literal notranslate"><span class="pre">WITH_WEIGHT</span></code> flag to <code class="docutils literal notranslate"><span class="pre">column_create</span></code>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Tags TABLE_PAT_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Tags bookmark_index COLUMN_INDEX|WITH_WEIGHT Bookmarks tags
# [[0, 1337566253.89858, 0.000355720520019531], true]
</pre></div>
</div>
<p>There is no weight vector column specific way except <code class="docutils literal notranslate"><span class="pre">WITH_WEIGHT</span></code>
flag. You can create an index like a scalar column.</p>
<p>You can search an element in <code class="docutils literal notranslate"><span class="pre">tags</span></code> like full text search syntax.</p>
<p>With <a class="reference internal" href="../commands/select.html#select-match-columns"><span class="std std-ref">match_columns</span></a> and <a class="reference internal" href="../commands/select.html#select-query"><span class="std std-ref">query</span></a>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks --match_columns tags --query groonga --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://groonga.org/&quot;,
#         {
#           &quot;groonga&quot;: 100
#         },
#         101
#       ],
#       [
#         &quot;http://mroonga.org/&quot;,
#         {
#           &quot;mroonga&quot;: 100,
#           &quot;groonga&quot;: 10,
#           &quot;mysql&quot;: 50
#         },
#         11
#       ],
#       [
#         &quot;http://ranguba.org/&quot;,
#         {
#           &quot;ruby&quot;: 100,
#           &quot;groonga&quot;: 50
#         },
#         51
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>You can also use weight in <a class="reference internal" href="../commands/select.html#select-match-columns"><span class="std std-ref">match_columns</span></a>. The score is
<code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">+</span> <span class="pre">weight_in_weight_vector)</span> <span class="pre">*</span> <span class="pre">weight_in_match_columns</span></code>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks --match_columns &#39;tags * 3&#39; --query groonga --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://groonga.org/&quot;,
#         {
#           &quot;groonga&quot;: 100
#         },
#         303
#       ],
#       [
#         &quot;http://mroonga.org/&quot;,
#         {
#           &quot;mroonga&quot;: 100,
#           &quot;groonga&quot;: 10,
#           &quot;mysql&quot;: 50
#         },
#         33
#       ],
#       [
#         &quot;http://ranguba.org/&quot;,
#         {
#           &quot;ruby&quot;: 100,
#           &quot;groonga&quot;: 50
#         },
#         153
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>With <a class="reference internal" href="../commands/select.html#select-filter"><span class="std std-ref">filter</span></a>:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks --filter &#39;tags @ &quot;groonga&quot;&#39; --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://groonga.org/&quot;,
#         {
#           &quot;groonga&quot;: 100
#         },
#         101
#       ],
#       [
#         &quot;http://mroonga.org/&quot;,
#         {
#           &quot;mroonga&quot;: 100,
#           &quot;groonga&quot;: 10,
#           &quot;mysql&quot;: 50
#         },
#         11
#       ],
#       [
#         &quot;http://ranguba.org/&quot;,
#         {
#           &quot;ruby&quot;: 100,
#           &quot;groonga&quot;: 50
#         },
#         51
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="how-to-apply-just-weight">
<h4><span class="section-number">7.6.2.2.3.5. </span>How to apply just weight<a class="headerlink" href="#how-to-apply-just-weight" title="Permalink to this headline">¶</a></h4>
<p>You can use weight in weight vector column to just increase search
score without changing a set of matched records.</p>
<p>Use <a class="reference internal" href="../commands/select.html#select-adjuster"><span class="std std-ref">adjuster</span></a> for the purpose:</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Bookmarks \
  --filter true \
  --adjuster &#39;tags @ &quot;mysql&quot; * 10 + tags @ &quot;groonga&quot; * 5&#39; \
  --output_columns _key,tags,_score
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;tags&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;http://groonga.org/&quot;,
#         {
#           &quot;groonga&quot;: 100
#         },
#         506
#       ],
#       [
#         &quot;http://mroonga.org/&quot;,
#         {
#           &quot;mroonga&quot;: 100,
#           &quot;groonga&quot;: 10,
#           &quot;mysql&quot;: 50
#         },
#         566
#       ],
#       [
#         &quot;http://ranguba.org/&quot;,
#         {
#           &quot;ruby&quot;: 100,
#           &quot;groonga&quot;: 50
#         },
#         256
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">select</span></code> command uses <code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">true</span></code>. So all records are
matched with score 1. Then it applies <code class="docutils literal notranslate"><span class="pre">--adjuster</span></code>. The adjuster
does the following:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">tags</span> <span class="pre">&#64;</span> <span class="pre">&quot;mysql&quot;</span> <span class="pre">*</span> <span class="pre">10</span></code> increases score by <code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">+</span> <span class="pre">weight)</span> <span class="pre">*</span> <span class="pre">10</span></code>
of records that has <code class="docutils literal notranslate"><span class="pre">&quot;mysql&quot;</span></code> tag.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">tags</span> <span class="pre">&#64;</span> <span class="pre">&quot;groonga&quot;</span> <span class="pre">*</span> <span class="pre">5</span></code> increases score by <code class="docutils literal notranslate"><span class="pre">(1</span> <span class="pre">+</span> <span class="pre">weight)</span> <span class="pre">*</span> <span class="pre">5</span></code>
of records that has <code class="docutils literal notranslate"><span class="pre">&quot;groonga&quot;</span></code> tag.</p></li>
</ul>
</div></blockquote>
<p>For example, record <code class="docutils literal notranslate"><span class="pre">&quot;http://mroonga.org/&quot;</span></code> has both <code class="docutils literal notranslate"><span class="pre">&quot;mysql&quot;</span></code> tag
and <code class="docutils literal notranslate"><span class="pre">&quot;groonga&quot;</span></code> tag. So its score is increased by <code class="docutils literal notranslate"><span class="pre">565</span></code> (<code class="docutils literal notranslate"><span class="pre">=</span>
<span class="pre">((1</span> <span class="pre">+</span> <span class="pre">50)</span> <span class="pre">*</span> <span class="pre">10)</span> <span class="pre">+</span> <span class="pre">((1</span> <span class="pre">+</span> <span class="pre">10)</span> <span class="pre">*</span> <span class="pre">5)</span> <span class="pre">=</span> <span class="pre">(51</span> <span class="pre">*</span> <span class="pre">10)</span> <span class="pre">+</span> <span class="pre">(11</span> <span class="pre">*</span> <span class="pre">5)</span> <span class="pre">=</span> <span class="pre">510</span> <span class="pre">+</span> <span class="pre">55</span></code>).
The search score is 1 by <code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">true</span></code> before applying
<code class="docutils literal notranslate"><span class="pre">--adjuster</span></code>. So the final search score is <code class="docutils literal notranslate"><span class="pre">566</span></code> (<code class="docutils literal notranslate"><span class="pre">=</span> <span class="pre">1</span> <span class="pre">+</span> <span class="pre">565</span></code>)
of record <code class="docutils literal notranslate"><span class="pre">&quot;http://mroonga.org/&quot;</span></code>.</p>
</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="#">7.6.2. Vector column</a><ul>
<li><a class="reference internal" href="#summary">7.6.2.1. Summary</a></li>
<li><a class="reference internal" href="#usage">7.6.2.2. Usage</a><ul>
<li><a class="reference internal" href="#normal-vector-column">7.6.2.2.1. Normal vector column</a><ul>
<li><a class="reference internal" href="#how-to-create">7.6.2.2.1.1. How to create</a></li>
<li><a class="reference internal" href="#how-to-load">7.6.2.2.1.2. How to load</a></li>
<li><a class="reference internal" href="#how-to-search">7.6.2.2.1.3. How to search</a></li>
</ul>
</li>
<li><a class="reference internal" href="#reference-vector-column">7.6.2.2.2. Reference vector column</a><ul>
<li><a class="reference internal" href="#id3">7.6.2.2.2.1. How to create</a></li>
<li><a class="reference internal" href="#id4">7.6.2.2.2.2. How to load</a></li>
<li><a class="reference internal" href="#id5">7.6.2.2.2.3. How to search</a></li>
</ul>
</li>
<li><a class="reference internal" href="#weight-vector-column">7.6.2.2.3. Weight vector column</a><ul>
<li><a class="reference internal" href="#limitations">7.6.2.2.3.1. Limitations</a></li>
<li><a class="reference internal" href="#id7">7.6.2.2.3.2. How to create</a></li>
<li><a class="reference internal" href="#id8">7.6.2.2.3.3. How to load</a></li>
<li><a class="reference internal" href="#id9">7.6.2.2.3.4. How to search</a></li>
<li><a class="reference internal" href="#how-to-apply-just-weight">7.6.2.2.3.5. How to apply just weight</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="scalar.html"
                        title="previous chapter"><span class="section-number">7.6.1. </span>Scalar column</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="pseudo.html"
                        title="next chapter"><span class="section-number">7.6.3. </span>Pseudo column</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="pseudo.html" title="7.6.3. Pseudo column"
             >next</a> |</li>
        <li class="right" >
          <a href="scalar.html" title="7.6.1. Scalar column"
             >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="../../reference.html" ><span class="section-number">7. </span>Reference manual</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../column.html" ><span class="section-number">7.6. </span>Column</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">7.6.2. </span>Vector column</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2009-2021, Brazil, Inc.
    </div>
  </body>
</html>