| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: indexing |
| 5 |
|
| 6 |
Indexing |
| 7 |
======== |
| 8 |
|
| 9 |
Groonga supports both online index construction and offline |
| 10 |
index construction since 2.0.0. |
| 11 |
|
| 12 |
.. _online-index-construction: |
| 13 |
|
| 14 |
Online index construction |
| 15 |
------------------------- |
| 16 |
|
| 17 |
In online index construction, registered documents can be |
| 18 |
searchable quickly while indexing. But indexing requires |
| 19 |
more cost rather than indexing by offline index |
| 20 |
construction. |
| 21 |
|
| 22 |
Online index construction is suitable for a search system |
| 23 |
that values freshness. For example, a search system for |
| 24 |
tweets, news, blog posts and so on will value |
| 25 |
freshness. Online index construction can make fresh |
| 26 |
documents searchable and keep searchable while indexing. |
| 27 |
|
| 28 |
.. _offline-index-construction: |
| 29 |
|
| 30 |
Offline index construction |
| 31 |
-------------------------- |
| 32 |
|
| 33 |
In offline index construction, indexing cost is less than |
| 34 |
indexing cost by online index construction. Indexing time |
| 35 |
will be shorter. Index will be smaller. Resources required |
| 36 |
for indexing will be smaller. But a registering document |
| 37 |
cannot be searchable until all registered documents are |
| 38 |
indexed. |
| 39 |
|
| 40 |
Offline index construction is suitable for a search system |
| 41 |
that values less required resources. If a search system |
| 42 |
doesn't value freshness, offline index construction will be |
| 43 |
suitable. For example, a reference manual search system |
| 44 |
doesn't value freshness because a reference manual will be |
| 45 |
updated only at a release. |
| 46 |
|
| 47 |
How to use |
| 48 |
---------- |
| 49 |
|
| 50 |
Groonga uses online index construction by default. We |
| 51 |
register a document, we can search it quickly. |
| 52 |
|
| 53 |
Groonga uses offline index construction by adding an index |
| 54 |
to a column that already has data. |
| 55 |
|
| 56 |
We define a schema: |
| 57 |
|
| 58 |
.. groonga-command |
| 59 |
.. include:: ../example/reference/indexing-schema.log |
| 60 |
.. table_create Tweets TABLE_NO_KEY |
| 61 |
.. column_create Tweets content COLUMN_SCALAR ShortText |
| 62 |
.. table_create Lexicon TABLE_HASH_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 63 |
|
| 64 |
We register data: |
| 65 |
|
| 66 |
.. groonga-command |
| 67 |
.. include:: ../example/reference/indexing-data.log |
| 68 |
.. load --table Tweets |
| 69 |
.. [ |
| 70 |
.. {"content":"Hello!"}, |
| 71 |
.. {"content":"I just start it!"}, |
| 72 |
.. {"content":"I'm sleepy... Have a nice day... Good night..."} |
| 73 |
.. ] |
| 74 |
|
| 75 |
We can search with sequential search when we don't have index: |
| 76 |
|
| 77 |
.. groonga-command |
| 78 |
.. include:: ../example/reference/indexing-search-without-index.log |
| 79 |
.. select Tweets --match_columns content --query 'good nice' |
| 80 |
|
| 81 |
We create index for ``Tweets.content``. Already registered |
| 82 |
data in ``Tweets.content`` are indexed by offline index |
| 83 |
construction: |
| 84 |
|
| 85 |
.. groonga-command |
| 86 |
.. include:: ../example/reference/indexing-offline-index-construction.log |
| 87 |
.. column_create Lexicon tweet COLUMN_INDEX|WITH_POSITION Tweets content |
| 88 |
|
| 89 |
.. tip:: |
| 90 |
|
| 91 |
We can create an index in parallel by adding |
| 92 |
``--n_workers -1``. For example:: |
| 93 |
|
| 94 |
column_create Lexicon tweet COLUMN_INDEX|WITH_POSITION Tweets content --n_workers -1 |
| 95 |
|
| 96 |
We search with index. We get a matched record: |
| 97 |
|
| 98 |
.. groonga-command |
| 99 |
.. include:: ../example/reference/indexing-search-after-offline-index-construction.log |
| 100 |
.. select Tweets --match_columns content --query 'good nice' |
| 101 |
|
| 102 |
We register data again. They are indexed by online index |
| 103 |
construction: |
| 104 |
|
| 105 |
.. groonga-command |
| 106 |
.. include:: ../example/reference/indexing-online-index-construction.log |
| 107 |
.. load --table Tweets |
| 108 |
.. [ |
| 109 |
.. {"content":"Good morning! Nice day."}, |
| 110 |
.. {"content":"Let's go shopping."} |
| 111 |
.. ] |
| 112 |
|
| 113 |
We can also get newly registered records by searching: |
| 114 |
|
| 115 |
.. groonga-command |
| 116 |
.. include:: ../example/reference/indexing-search-after-online-index-construction.log |
| 117 |
.. select Tweets --match_columns content --query 'good nice' |