Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: tell select which index column to use. #1132

Closed
tonytonyjan opened this issue Aug 28, 2020 · 2 comments
Closed

feature request: tell select which index column to use. #1132

tonytonyjan opened this issue Aug 28, 2020 · 2 comments

Comments

@tonytonyjan
Copy link

tonytonyjan commented Aug 28, 2020

For example:

table_create --name Terms --flags TABLE_PAT_KEY --key_type ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create --table Terms --name post_index1 --flags COLUMN_INDEX|WITH_POSITION --type Posts --source content
column_create --table Terms --name post_index2 --flags COLUMN_INDEX|WITH_POSITION --type Posts --source content
select --table Posts --match_columns content --query hello
  1. How do I know select will use post_index1 or post_index2?
  2. How to I tell select which one to use?
@komainu8
Copy link
Member

komainu8 commented Aug 28, 2020

How do I know select will use post_index1 or post_index2?

It is implementation-dependent that Groonga chooses which index column to use.
Therefore, we can't know it accurately in advance.

How to I tell select which one to use?

We can specify the index column to use as below.

`--filter '${table_name}.${index_column_name} @ xxx'`

An example will be shown below.

We set two different indexes the title column of the Entires table in the below example.

The first index is the entries_title column of the Term2 table.
The second index is the entries_title column of the Term3 table.

table_create Entries TABLE_HASH_KEY ShortText
column_create Entries body COLUMN_SCALAR ShortText
column_create Entries title COLUMN_SCALAR ShortText

table_create Terms TABLE_PAT_KEY ShortText

table_create Terms2 TABLE_PAT_KEY ShortText --default_tokenizer TokenRegexp --normalizer NormalizerAuto

table_create Terms3 TABLE_PAT_KEY ShortText --default_tokenizer TokenMecab --normalizer NormalizerAuto

load --table Entries
[
["_key","body","title"],
["http://example.com/entry1","This is my first entry.","Hello Groonga."],
["http://example.com/entry2","I love Groonga!","Hello world."],
["http://example.com/entry3","I use Mroonga.","Hello Mroonga, bye Groonga."],
["http://example.com/entry4","I'm back.","Say, Hello Groonga!"]
]

column_create Terms entries_title COLUMN_INDEX|INDEX_MEDIUM Entries title
column_create Terms2 entries_title COLUMN_INDEX|WITH_POSITION|INDEX_MEDIUM Entries title
column_create Terms3 entries_title COLUMN_INDEX|WITH_POSITION|INDEX_MEDIUM Entries title
  • Case 1

If we want to use the index of the Term2 table, we specify Terms2.entries_title in the --filter option as below.

select --table Entries --filter 'Terms2.entries_title @~ "\\\\AHello"'

[[0,1598623331.807821,0.00315546989440918],[[[3],[["_id","UInt32"],["_key","ShortText"],["body","ShortText"],["title","ShortText"]],[1,"http://example.com/entry1","This is my first entry.","Hello Groonga."],[2,"http://example.com/entry2","I love Groonga!","Hello world."],[3,"http://example.com/entry3","I use Mroonga.","Hello Mroonga, bye Groonga."]]]]

Whether the specified index is used or not is outputted in the log of Groonga as below. (However, we need set log level of the log is info or debug.)

2020-08-28 23:02:11.809798|i| [object][search][index][key][regexp] <Terms2.entries_title>
  • Case2

If we want to use the index of the Term3 table, we specify Terms3.entries_title in the --filter option as below.

select --table Entries --filter 'Terms3.entries_title @~ "\\\\AHello"'

[[0,1598623408.736453,0.008265495300292969],[[[0],[["_id","UInt32"],["_key","ShortText"],["body","ShortText"],["title","ShortText"]]]]]

Here is the log of Groonga for this select.

2020-08-28 23:03:28.738411|i| [object][search][index][key][regexp] <Terms3.entries_title>

@kou
Copy link
Member

kou commented Sep 7, 2020

No response.

@kou kou closed this as completed Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants