Kouhei Sutou
null+****@clear*****
Tue Nov 24 19:22:24 JST 2015
Kouhei Sutou 2015-11-24 19:22:24 +0900 (Tue, 24 Nov 2015) New Revision: 7ca7f82266ba76e271b108ae1352b2147bbe5fce https://github.com/groonga/groonga/commit/7ca7f82266ba76e271b108ae1352b2147bbe5fce Message: doc: add prefix_rk_search() Added files: doc/source/example/reference/functions/prefix_rk_search/usage_add_no_reading_completion_target.log doc/source/example/reference/functions/prefix_rk_search/usage_loose_completion.log doc/source/example/reference/functions/prefix_rk_search/usage_prefix_rk_only_completion.log doc/source/example/reference/functions/prefix_rk_search/usage_prefix_search_combined_completion.log doc/source/example/reference/functions/prefix_rk_search/usage_setup_completion.log doc/source/example/reference/functions/prefix_rk_search/usage_setup_loose_completion.log doc/source/example/reference/functions/prefix_rk_search/usage_simple.log doc/source/reference/functions/prefix_rk_search.rst Copied files: doc/source/example/reference/functions/prefix_rk_search/usage_setup.log (from doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log) Modified files: doc/files.am doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log doc/source/reference/operations/prefix_rk_search.rst Modified: doc/files.am (+10 -0) =================================================================== --- doc/files.am 2015-11-24 18:46:19 +0900 (7f5a9f9) +++ doc/files.am 2015-11-24 19:22:24 +0900 (c063385) @@ -334,6 +334,7 @@ absolute_source_files = \ $(top_srcdir)/doc/source/example/reference/normalizers/example-table-create.log \ $(top_srcdir)/doc/source/example/reference/normalizers/normalizer-auto.log \ $(top_srcdir)/doc/source/example/reference/normalizers/normalizer-nfkc51.log \ + $(top_srcdir)/doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log \ $(top_srcdir)/doc/source/example/reference/regular_expression/anchor_z.log \ $(top_srcdir)/doc/source/example/reference/regular_expression/character_class_characters.log \ $(top_srcdir)/doc/source/example/reference/regular_expression/character_class_range.log \ @@ -686,6 +687,7 @@ absolute_source_files = \ $(top_srcdir)/doc/source/reference/functions/html_untag.rst \ $(top_srcdir)/doc/source/reference/functions/in_values.rst \ $(top_srcdir)/doc/source/reference/functions/now.rst \ + $(top_srcdir)/doc/source/reference/functions/prefix_rk_search.rst \ $(top_srcdir)/doc/source/reference/functions/query.rst \ $(top_srcdir)/doc/source/reference/functions/rand.rst \ $(top_srcdir)/doc/source/reference/functions/snippet_html.rst \ @@ -699,6 +701,7 @@ absolute_source_files = \ $(top_srcdir)/doc/source/reference/normalizers.rst \ $(top_srcdir)/doc/source/reference/operations.rst \ $(top_srcdir)/doc/source/reference/operations/geolocation_search.rst \ + $(top_srcdir)/doc/source/reference/operations/prefix_rk_search.rst \ $(top_srcdir)/doc/source/reference/output.rst \ $(top_srcdir)/doc/source/reference/query_expanders.rst \ $(top_srcdir)/doc/source/reference/query_expanders/tsv.rst \ @@ -1093,6 +1096,7 @@ source_files_relative_from_doc_dir = \ source/example/reference/normalizers/example-table-create.log \ source/example/reference/normalizers/normalizer-auto.log \ source/example/reference/normalizers/normalizer-nfkc51.log \ + source/example/reference/operations/prefix_rk_search/usage_register_kana.log \ source/example/reference/regular_expression/anchor_z.log \ source/example/reference/regular_expression/character_class_characters.log \ source/example/reference/regular_expression/character_class_range.log \ @@ -1445,6 +1449,7 @@ source_files_relative_from_doc_dir = \ source/reference/functions/html_untag.rst \ source/reference/functions/in_values.rst \ source/reference/functions/now.rst \ + source/reference/functions/prefix_rk_search.rst \ source/reference/functions/query.rst \ source/reference/functions/rand.rst \ source/reference/functions/snippet_html.rst \ @@ -1458,6 +1463,7 @@ source_files_relative_from_doc_dir = \ source/reference/normalizers.rst \ source/reference/operations.rst \ source/reference/operations/geolocation_search.rst \ + source/reference/operations/prefix_rk_search.rst \ source/reference/output.rst \ source/reference/query_expanders.rst \ source/reference/query_expanders/tsv.rst \ @@ -1782,6 +1788,7 @@ html_files_relative_from_locale_dir = \ html/_sources/reference/functions/html_untag.txt \ html/_sources/reference/functions/in_values.txt \ html/_sources/reference/functions/now.txt \ + html/_sources/reference/functions/prefix_rk_search.txt \ html/_sources/reference/functions/query.txt \ html/_sources/reference/functions/rand.txt \ html/_sources/reference/functions/snippet_html.txt \ @@ -1795,6 +1802,7 @@ html_files_relative_from_locale_dir = \ html/_sources/reference/normalizers.txt \ html/_sources/reference/operations.txt \ html/_sources/reference/operations/geolocation_search.txt \ + html/_sources/reference/operations/prefix_rk_search.txt \ html/_sources/reference/output.txt \ html/_sources/reference/query_expanders.txt \ html/_sources/reference/query_expanders/tsv.txt \ @@ -2019,6 +2027,7 @@ html_files_relative_from_locale_dir = \ html/reference/functions/html_untag.html \ html/reference/functions/in_values.html \ html/reference/functions/now.html \ + html/reference/functions/prefix_rk_search.html \ html/reference/functions/query.html \ html/reference/functions/rand.html \ html/reference/functions/snippet_html.html \ @@ -2032,6 +2041,7 @@ html_files_relative_from_locale_dir = \ html/reference/normalizers.html \ html/reference/operations.html \ html/reference/operations/geolocation_search.html \ + html/reference/operations/prefix_rk_search.html \ html/reference/output.html \ html/reference/query_expanders.html \ html/reference/query_expanders/tsv.html \ Added: doc/source/example/reference/functions/prefix_rk_search/usage_add_no_reading_completion_target.log (+7 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_add_no_reading_completion_target.log 2015-11-24 19:22:24 +0900 (841a9aa) @@ -0,0 +1,7 @@ +Execution example:: + + load --table Items + [ + {"_key": "nihon", "readings": []} + ] + # [[0, 1337566253.89858, 0.000355720520019531], 1] Added: doc/source/example/reference/functions/prefix_rk_search/usage_loose_completion.log (+38 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_loose_completion.log 2015-11-24 19:22:24 +0900 (b5bf93c) @@ -0,0 +1,38 @@ +Execution example:: + + select LooseItems \ + --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"nIhO\\")") || \ + _key @^ "nIhO"' \ + --output_columns '_key,label' + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 2 + # ], + # [ + # [ + # "_key", + # "ShortText" + # ], + # [ + # "label", + # "ShortText" + # ] + # ], + # [ + # "日本", + # "日本" + # ], + # [ + # "nihon", + # "日本" + # ] + # ] + # ] + # ] Added: doc/source/example/reference/functions/prefix_rk_search/usage_prefix_rk_only_completion.log (+40 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_prefix_rk_only_completion.log 2015-11-24 19:22:24 +0900 (fedd321) @@ -0,0 +1,40 @@ +Execution example:: + + select Items \ + --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"niho\\")")' + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 1 + # ], + # [ + # [ + # "_id", + # "UInt32" + # ], + # [ + # "_key", + # "ShortText" + # ], + # [ + # "readings", + # "Readings" + # ] + # ], + # [ + # 1, + # "日本", + # [ + # "ニホン", + # "ニッポン" + # ] + # ] + # ] + # ] + # ] Added: doc/source/example/reference/functions/prefix_rk_search/usage_prefix_search_combined_completion.log (+46 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_prefix_search_combined_completion.log 2015-11-24 19:22:24 +0900 (662bbec) @@ -0,0 +1,46 @@ +Execution example:: + + select Items \ + --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"niho\\")") || \ + _key @^ "niho"' + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 2 + # ], + # [ + # [ + # "_id", + # "UInt32" + # ], + # [ + # "_key", + # "ShortText" + # ], + # [ + # "readings", + # "Readings" + # ] + # ], + # [ + # 1, + # "日本", + # [ + # "ニホン", + # "ニッポン" + # ] + # ], + # [ + # 4, + # "nihon", + # [] + # ] + # ] + # ] + # ] Copied: doc/source/example/reference/functions/prefix_rk_search/usage_setup.log (+1 -1) 76% =================================================================== --- doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log 2015-11-24 18:46:19 +0900 (d03aeaf) +++ doc/source/example/reference/functions/prefix_rk_search/usage_setup.log 2015-11-24 19:22:24 +0900 (d76bf0a) @@ -1,6 +1,6 @@ Execution example:: - table_create Readings TABLE_PAT_KEY ShortText + table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto # [[0, 1337566253.89858, 0.000355720520019531], true] load --table Readings [ Added: doc/source/example/reference/functions/prefix_rk_search/usage_setup_completion.log (+15 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_setup_completion.log 2015-11-24 19:22:24 +0900 (a9f3374) @@ -0,0 +1,15 @@ +Execution example:: + + table_create Items TABLE_HASH_KEY ShortText + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create Items readings COLUMN_VECTOR Readings + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create Readings items_index COLUMN_INDEX Items readings + # [[0, 1337566253.89858, 0.000355720520019531], true] + load --table Items + [ + {"_key": "日本", "readings": ["ニホン", "ニッポン"]}, + {"_key": "ローマ字", "readings": ["ローマジ"]}, + {"_key": "漢字", "readings": ["カンジ"]} + ] + # [[0, 1337566253.89858, 0.000355720520019531], 3] Added: doc/source/example/reference/functions/prefix_rk_search/usage_setup_loose_completion.log (+18 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_setup_loose_completion.log 2015-11-24 19:22:24 +0900 (8687697) @@ -0,0 +1,18 @@ +Execution example:: + + table_create LooseItems TABLE_HASH_KEY ShortText --normalizer NormalizerAuto + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create LooseItems label COLUMN_SCALAR ShortText + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create LooseItems readings COLUMN_VECTOR Readings + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create Readings loose_items_index COLUMN_INDEX LooseItems readings + # [[0, 1337566253.89858, 0.000355720520019531], true] + load --table LooseItems + [ + {"_key": "日本", "label": "日本", "readings": ["ニホン", "ニッポン"]}, + {"_key": "ローマ字", "label": "ローマ字", "readings": ["ローマジ"]}, + {"_key": "漢字", "label": "漢字", "readings": ["カンジ"]}, + {"_key": "Nihon", "label": "日本", "readings": []} + ] + # [[0, 1337566253.89858, 0.000355720520019531], 4] Added: doc/source/example/reference/functions/prefix_rk_search/usage_simple.log (+35 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/functions/prefix_rk_search/usage_simple.log 2015-11-24 19:22:24 +0900 (46afbd7) @@ -0,0 +1,35 @@ +Execution example:: + + select Readings --filter 'prefix_rk_search(_key, "ni")' + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 2 + # ], + # [ + # [ + # "_id", + # "UInt32" + # ], + # [ + # "_key", + # "ShortText" + # ] + # ], + # [ + # 2, + # "ニッポン" + # ], + # [ + # 1, + # "ニホン" + # ] + # ] + # ] + # ] Modified: doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log (+1 -1) =================================================================== --- doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log 2015-11-24 18:46:19 +0900 (d03aeaf) +++ doc/source/example/reference/operations/prefix_rk_search/usage_register_kana.log 2015-11-24 19:22:24 +0900 (d76bf0a) @@ -1,6 +1,6 @@ Execution example:: - table_create Readings TABLE_PAT_KEY ShortText + table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto # [[0, 1337566253.89858, 0.000355720520019531], true] load --table Readings [ Added: doc/source/reference/functions/prefix_rk_search.rst (+160 -0) 100644 =================================================================== --- /dev/null +++ doc/source/reference/functions/prefix_rk_search.rst 2015-11-24 19:22:24 +0900 (180951d) @@ -0,0 +1,160 @@ +.. -*- rst -*- + +.. highlightlang:: none + +.. groonga-command +.. database: functions_prefix_rk_search + +``prefix_rk_search()`` +====================== + +Summary +------- + +``prefix_rk_search()`` selects records by +:doc:`/reference/operations/prefix_rk_search`. + +You need to create :ref:`table-pat-key` for prefix RK search. + +You can't use ``prefix_rk_search()`` for sequential scan. It's a +selector only procedure. + +Syntax +------ + +``prefix_rk_search`` requires two arguments. They are ``column`` and +``query``:: + + prefix_rk_search(column, query) + +The first argument ``column`` must be ``_key`` for now. + +The first argument ``query`` must be string. + +Usage +----- + +Here are a schema definition and sample data to show usage: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_setup.log +.. table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +.. load --table Readings +.. [ +.. {"_key": "ニホン"}, +.. {"_key": "ニッポン"}, +.. {"_key": "ローマジ"} +.. ] + +Here is the simple usage of ``prefix_rk_search()`` function which +selects ``ニホン`` and ``ニッポン`` by ``ni``: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_simple.log +.. select Readings --filter 'prefix_rk_search(_key, "ni")' + +You can implement :doc:`/reference/suggest/completion` like feature by +combining :doc:`sub_filter`. + +Create a table that has candidates of completion as records. Each +records have zero or more readings. They are stored into ``Readings`` +table. Don't forget define an index column for ``Items.readings`` in +``Readings`` table. The index column is needed for :doc:`sub_filter`: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_setup_completion.log +.. table_create Items TABLE_HASH_KEY ShortText +.. column_create Items readings COLUMN_VECTOR Readings +.. +.. column_create Readings items_index COLUMN_INDEX Items readings +.. +.. load --table Items +.. [ +.. {"_key": "日本", "readings": ["ニホン", "ニッポン"]}, +.. {"_key": "ローマ字", "readings": ["ローマジ"]}, +.. {"_key": "漢字", "readings": ["カンジ"]} +.. ] + +You can find ``日本`` record in ``Items`` table by ``niho``. Because +prefix RK search with ``niho`` selects ``ニホン`` reading and ``ニホン`` +reading is one of readings of ``ニホン`` record: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_prefix_rk_only_completion.log +.. select Items \ +.. --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"niho\\")")' + +You need to combine :ref:`script-syntax-prefix-search-operator` to +support no reading completion targets. + +Add one no reading completion target: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_add_no_reading_completion_target.log +.. load --table Items +.. [ +.. {"_key": "nihon", "readings": []} +.. ] + +Combine :ref:`script-syntax-prefix-search-operator` to +support no reading completion targets: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_prefix_search_combined_completion.log +.. select Items \ +.. --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"niho\\")") || \ +.. _key @^ "niho"' + +Normally, you want to use case insensitive search for completion. Use +``--normalizer NormalizerAuto`` and ``label`` column for the case: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_setup_loose_completion.log +.. table_create LooseItems TABLE_HASH_KEY ShortText --normalizer NormalizerAuto +.. column_create LooseItems label COLUMN_SCALAR ShortText +.. column_create LooseItems readings COLUMN_VECTOR Readings +.. +.. column_create Readings loose_items_index COLUMN_INDEX LooseItems readings +.. +.. load --table LooseItems +.. [ +.. {"_key": "日本", "label": "日本", "readings": ["ニホン", "ニッポン"]}, +.. {"_key": "ローマ字", "label": "ローマ字", "readings": ["ローマジ"]}, +.. {"_key": "漢字", "label": "漢字", "readings": ["カンジ"]}, +.. {"_key": "Nihon", "label": "日本", "readings": []} +.. ] + +Use ``LooseItems.label`` for display: + +.. groonga-command +.. include:: ../../example/reference/functions/prefix_rk_search/usage_loose_completion.log +.. select LooseItems \ +.. --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"nIhO\\")") || \ +.. _key @^ "nIhO"' \ +.. --output_columns '_key,label' + +Parameters +---------- + +There are two required parameter, ``column`` and ``query``. + +``column`` +^^^^^^^^^^ + +Always specifies ``_key`` for now. + +``query`` +^^^^^^^^^ + +Specifies a query in romaji, katakana or hiragana as string. + +Return value +------------ + +``prefix_rk_search()`` function returns matched records. + +See also +-------- + +* :doc:`/reference/operations/prefix_rk_search` +* :doc:`/reference/commands/sub_filter` Modified: doc/source/reference/operations/prefix_rk_search.rst (+1 -1) =================================================================== --- doc/source/reference/operations/prefix_rk_search.rst 2015-11-24 18:46:19 +0900 (be44887) +++ doc/source/reference/operations/prefix_rk_search.rst 2015-11-24 19:22:24 +0900 (f687f70) @@ -43,7 +43,7 @@ You need to put kana in katakana to ``TABLE_PAT_KEY`` as key: .. groonga-command .. include:: ../../example/reference/operations/prefix_rk_search/usage_register_kana.log -.. table_create Readings TABLE_PAT_KEY ShortText +.. table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto .. load --table Readings .. [ .. {"_key": "ニホン"}, -------------- next part -------------- HTML����������������������������...다운로드