Skip to main content
Ctrl+K
Groonga v15.0.9 documentation - Home Groonga v15.0.9 documentation - Home
  • GitHub
  • Twitter
  • Blog
  • GitHub
  • Twitter
  • Blog

Section Navigation

  • 7.1. Executables
    • 7.1.1. grndb
    • 7.1.2. grnslap
    • 7.1.3. groonga executable file
    • 7.1.4. groonga-benchmark
    • 7.1.5. groonga-httpd
    • 7.1.6. Groonga HTTP server
    • 7.1.7. groonga-suggest-create-dataset
    • 7.1.8. groonga-suggest-httpd
    • 7.1.9. groonga-suggest-learner
  • 7.2. Output
  • 7.3. Command
    • 7.3.1. Command version
    • 7.3.2. Parallel execution
    • 7.3.3. Output format
    • 7.3.4. Output trace log
    • 7.3.5. Pretty print
    • 7.3.6. Request ID
    • 7.3.7. Request timeout
    • 7.3.8. Return code
      • 7.3.8.3.1. -2: GRN_OPERATION_NOT_PERMITTED
      • 7.3.8.3.2. -3: GRN_NO_SUCH_FILE_OR_DIRECTORY
      • 7.3.8.3.3. -6: GRN_INPUT_OUTPUT_ERROR
      • 7.3.8.3.4. -13: GRN_NOT_ENOUGH_SPACE
      • 7.3.8.3.5. -22: GRN_INVALID_ARGUMENT
      • 7.3.8.3.6. -34: GRN_RESOURCE_DEADLOCK_AVOIDED
    • 7.3.9. cache_limit
    • 7.3.10. check
    • 7.3.11. clearlock
    • 7.3.12. column_copy
    • 7.3.13. column_create
    • 7.3.14. column_list
    • 7.3.15. column_remove
    • 7.3.16. column_rename
    • 7.3.17. config_delete
    • 7.3.18. config_get
    • 7.3.19. config_set
    • 7.3.20. database_unmap
    • 7.3.21. define_selector
    • 7.3.22. defrag
    • 7.3.23. delete
    • 7.3.24. dump
    • 7.3.25. index_column_diff
    • 7.3.26. io_flush
    • 7.3.27. load
    • 7.3.28. lock_acquire
    • 7.3.29. lock_clear
    • 7.3.30. lock_release
    • 7.3.31. log_level
    • 7.3.32. log_put
    • 7.3.33. log_reopen
    • 7.3.34. logical_count
    • 7.3.35. logical_parameters
    • 7.3.36. logical_range_filter
    • 7.3.37. logical_select
    • 7.3.38. logical_shard_list
    • 7.3.39. logical_table_remove
    • 7.3.40. normalize
    • 7.3.41. normalizer_list
    • 7.3.42. object_exist
    • 7.3.43. object_inspect
    • 7.3.44. object_list
    • 7.3.45. object_remove
    • 7.3.46. plugin_register
    • 7.3.47. plugin_unregister
    • 7.3.48. query_expand
    • 7.3.49. quit
    • 7.3.50. range_filter
    • 7.3.51. reference_acquire
    • 7.3.52. reference_release
    • 7.3.53. register
    • 7.3.54. reindex
    • 7.3.55. request_cancel
    • 7.3.56. ruby_eval
    • 7.3.57. schema
    • 7.3.58. select
    • 7.3.59. shutdown
    • 7.3.60. status
    • 7.3.61. suggest
    • 7.3.62. table_copy
    • 7.3.63. table_create
    • 7.3.64. table_list
    • 7.3.65. table_remove
    • 7.3.66. table_rename
    • 7.3.67. table_tokenize
    • 7.3.68. thread_dump
    • 7.3.69. thread_limit
    • 7.3.70. tokenize
    • 7.3.71. tokenizer_list
    • 7.3.72. truncate
  • 7.4. Data types
  • 7.5. Tables
  • 7.6. Column
    • 7.6.2.1. Scalar column
    • 7.6.2.2. Vector column
    • 7.6.2.3. Pseudo column
    • 7.6.3.1. Index column
  • 7.7. Normalizers
    • 7.7.2.1. NormalizerAuto
    • 7.7.2.2. NormalizerNFKC
    • 7.7.2.3. NormalizerNFKC100
    • 7.7.2.4. NormalizerNFKC121
    • 7.7.2.5. NormalizerNFKC130
    • 7.7.2.6. NormalizerNFKC150
    • 7.7.2.7. NormalizerNFKC51
    • 7.7.2.8. NormalizerTable
  • 7.8. Tokenizers
    • 7.8.1. Summary
    • 7.8.2. TokenBigram
    • 7.8.3. TokenBigramIgnoreBlank
    • 7.8.4. TokenBigramIgnoreBlankSplitSymbol
    • 7.8.5. TokenBigramIgnoreBlankSplitSymbolAlpha
    • 7.8.6. TokenBigramIgnoreBlankSplitSymbolAlphaDigit
    • 7.8.7. TokenBigramSplitSymbol
    • 7.8.8. TokenBigramSplitSymbolAlpha
    • 7.8.9. TokenBigramSplitSymbolAlphaDigit
    • 7.8.10. TokenDelimit
    • 7.8.11. TokenDelimitNull
    • 7.8.12. TokenMecab
    • 7.8.13. TokenNgram
    • 7.8.14. TokenPattern
    • 7.8.15. TokenRegexp
    • 7.8.16. TokenTable
    • 7.8.17. TokenTrigram
    • 7.8.18. TokenUnigram
  • 7.9. Token filters
    • 7.9.1. Summary
    • 7.9.2. TokenFilterNFKC
    • 7.9.3. TokenFilterNFKC100
    • 7.9.4. TokenFilterNFKC150
    • 7.9.5. TokenFilterStem
    • 7.9.6. TokenFilterStopWord
  • 7.10. Query expanders
    • 7.10.1. QueryExpanderTSV
  • 7.11. Scorer
    • 7.11.3.1. scorer_tf_at_most
    • 7.11.3.2. scorer_tf_idf
  • 7.12. Cast
  • 7.13. grn_expr
    • 7.13.1. Query syntax
    • 7.13.2. Script syntax
  • 7.14. Regular expression
  • 7.15. Function
    • 7.15.1. between
    • 7.15.2. cast_loose
    • 7.15.3. edit_distance
    • 7.15.4. escalate
    • 7.15.5. fuzzy_search
    • 7.15.6. geo_distance
    • 7.15.7. geo_in_circle
    • 7.15.8. geo_in_rectangle
    • 7.15.9. highlight
    • 7.15.10. highlight_full
    • 7.15.11. highlight_html
    • 7.15.12. html_untag
    • 7.15.13. in_records
    • 7.15.14. in_values
    • 7.15.15. language_model_vectorize
    • 7.15.16. math_abs
    • 7.15.17. now
    • 7.15.18. number_classify
    • 7.15.19. prefix_rk_search
    • 7.15.20. query
    • 7.15.21. query_parallel_or
    • 7.15.22. rand
    • 7.15.23. snippet
    • 7.15.24. snippet_html
    • 7.15.25. string_length
    • 7.15.26. string_slice
    • 7.15.27. string_substring
    • 7.15.28. sub_filter
    • 7.15.29. time_classify_day
    • 7.15.30. time_classify_day_of_week
    • 7.15.31. time_classify_hour
    • 7.15.32. time_classify_minute
    • 7.15.33. time_classify_month
    • 7.15.34. time_classify_second
    • 7.15.35. time_classify_week
    • 7.15.36. time_classify_year
    • 7.15.37. vector_find
    • 7.15.38. vector_new
    • 7.15.39. vector_size
    • 7.15.40. vector_slice
  • 7.16. Window function
    • 7.16.1. record_number
    • 7.16.2. window_count
    • 7.16.3. window_rank
    • 7.16.4. window_record_number
    • 7.16.5. window_sum
  • 7.17. Operations
    • 7.17.1. Geolocation search
    • 7.17.2. Prefix RK search
  • 7.18. Configuration
  • 7.19. Alias
  • 7.20. Suggest
    • 7.20.1. Introduction
    • 7.20.2. Completion
    • 7.20.3. Correction
    • 7.20.4. Suggestion
  • 7.21. Indexing
  • 7.22. Sharding
  • 7.23. Language model
  • 7.24. Log
  • 7.25. Tuning
  • 7.26. API
    • 7.26.1. Overview
    • 7.26.2. Global configurations
    • 7.26.3. Plugin
    • 7.26.4. grn_cache
    • 7.26.5. grn_column
    • 7.26.6. grn_command_version
    • 7.26.7. grn_content_type
    • 7.26.8. grn_ctx
    • 7.26.9. grn_db
    • 7.26.10. grn_encoding
    • 7.26.11. grn_expr
    • 7.26.12. grn_geo
    • 7.26.13. grn_hook
    • 7.26.14. grn_ii
    • 7.26.15. grn_index_cursor
    • 7.26.16. grn_info
    • 7.26.17. grn_inspect
    • 7.26.18. grn_match_escalation
    • 7.26.19. grn_obj
    • 7.26.20. grn_proc
    • 7.26.21. grn_search
    • 7.26.22. grn_table
    • 7.26.23. grn_table_cursor
    • 7.26.24. grn_thread_*
    • 7.26.25. grn_type
    • 7.26.26. grn_user_data
  • 7. Reference manual
  • 7.15. Function
  • 7.15.19. prefix_rk_search

7.15.19. prefix_rk_search#

7.15.19.1. Summary#

prefix_rk_search selects records by Prefix RK search.

You need to create TABLE_PAT_KEY table for prefix RK search.

You can’t use prefix_rk_search for sequential scan. It’s a selector only procedure.

7.15.19.2. Syntax#

prefix_rk_search requires two arguments. They are column and query:

prefix_rk_search(column, query)

column must be _key for now.

query must be string.

7.15.19.3. Usage#

Here are a schema definition and sample data to show usage:

Execution example:

table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto
# [[0,1337566253.89858,0.000355720520019531],true]
load --table Readings
[
{"_key": "ニホン"},
{"_key": "ニッポン"},
{"_key": "ローマジ"}
]
# [[0,1337566253.89858,0.000355720520019531],3]

Here is the simple usage of prefix_rk_search() function which selects ニホン and ニッポン by ni:

Execution example:

select Readings --filter 'prefix_rk_search(_key, "ni")'
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           "_id",
#           "UInt32"
#         ],
#         [
#           "_key",
#           "ShortText"
#         ]
#       ],
#       [
#         2,
#         "ニッポン"
#       ],
#       [
#         1,
#         "ニホン"
#       ]
#     ]
#   ]
# ]

You can implement Completion like feature by combining 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 sub_filter:

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]

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:

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,
#         "日本",
#         [
#           "ニホン",
#           "ニッポン"
#         ]
#       ]
#     ]
#   ]
# ]

You need to combine Prefix search operator to support no reading completion targets.

Add one no reading completion target:

Execution example:

load --table Items
[
{"_key": "nihon", "readings": []}
]
# [[0,1337566253.89858,0.000355720520019531],1]

Combine Prefix search operator to support no reading completion targets:

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",
#         [
#
#         ]
#       ]
#     ]
#   ]
# ]

Normally, you want to use case insensitive search for completion. Use --normalizer NormalizerAuto and label column for the case:

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]

Use LooseItems.label for display:

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",
#         "日本"
#       ]
#     ]
#   ]
# ]

7.15.19.4. Parameters#

There are two required parameter, column and query.

7.15.19.4.1. column#

Always specifies _key for now.

7.15.19.4.2. query#

Specifies a query in romaji, katakana or hiragana as string.

7.15.19.5. Return value#

prefix_rk_search function returns matched records.

7.15.19.6. See also#

  • Prefix RK search

  • sub_filter

previous

7.15.18. number_classify

next

7.15.20. query

On this page
  • 7.15.19.1. Summary
  • 7.15.19.2. Syntax
  • 7.15.19.3. Usage
  • 7.15.19.4. Parameters
    • 7.15.19.4.1. column
    • 7.15.19.4.2. query
  • 7.15.19.5. Return value
  • 7.15.19.6. See also
Edit on GitHub

© Copyright 2009-2025 Groonga Project.

Built with the PyData Sphinx Theme 0.16.1.