How do I insert additional tokens into a Hibernate Search token stream?
up vote
0
down vote
favorite
In Hibernate Search, how do I add support for full, startsWith and endsWith matching?
E.g., for indexing values
doc 1: bridge
doc 2: bridge rusting
doc 3: strong bridge
I want queries to return:
query: ^bridge$
result: doc 1
query: ^bridge
result: docs 1 & 2
query: bridge$
result: docs 1 & 3
The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:
doc 1: _BEGIN_ bridge _END_
doc 2: _BEGIN_ bridge rusting _END_
doc 3: _BEGIN_ strong bridge _END_
so that:
query: _BEGIN_ bridge _END_
returns: docs 1
query: _BEGIN_ bridge
returns: docs 1 and 2
query: bridge _END_
returns: docs 1 and 3
Conceptually this should work. But how to implement?
Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?
hibernate search lucene
add a comment |
up vote
0
down vote
favorite
In Hibernate Search, how do I add support for full, startsWith and endsWith matching?
E.g., for indexing values
doc 1: bridge
doc 2: bridge rusting
doc 3: strong bridge
I want queries to return:
query: ^bridge$
result: doc 1
query: ^bridge
result: docs 1 & 2
query: bridge$
result: docs 1 & 3
The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:
doc 1: _BEGIN_ bridge _END_
doc 2: _BEGIN_ bridge rusting _END_
doc 3: _BEGIN_ strong bridge _END_
so that:
query: _BEGIN_ bridge _END_
returns: docs 1
query: _BEGIN_ bridge
returns: docs 1 and 2
query: bridge _END_
returns: docs 1 and 3
Conceptually this should work. But how to implement?
Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?
hibernate search lucene
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In Hibernate Search, how do I add support for full, startsWith and endsWith matching?
E.g., for indexing values
doc 1: bridge
doc 2: bridge rusting
doc 3: strong bridge
I want queries to return:
query: ^bridge$
result: doc 1
query: ^bridge
result: docs 1 & 2
query: bridge$
result: docs 1 & 3
The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:
doc 1: _BEGIN_ bridge _END_
doc 2: _BEGIN_ bridge rusting _END_
doc 3: _BEGIN_ strong bridge _END_
so that:
query: _BEGIN_ bridge _END_
returns: docs 1
query: _BEGIN_ bridge
returns: docs 1 and 2
query: bridge _END_
returns: docs 1 and 3
Conceptually this should work. But how to implement?
Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?
hibernate search lucene
In Hibernate Search, how do I add support for full, startsWith and endsWith matching?
E.g., for indexing values
doc 1: bridge
doc 2: bridge rusting
doc 3: strong bridge
I want queries to return:
query: ^bridge$
result: doc 1
query: ^bridge
result: docs 1 & 2
query: bridge$
result: docs 1 & 3
The solution seems simple: override the Lucene indexer, so fields gets indexed with some extra tokens:
doc 1: _BEGIN_ bridge _END_
doc 2: _BEGIN_ bridge rusting _END_
doc 3: _BEGIN_ strong bridge _END_
so that:
query: _BEGIN_ bridge _END_
returns: docs 1
query: _BEGIN_ bridge
returns: docs 1 and 2
query: bridge _END_
returns: docs 1 and 3
Conceptually this should work. But how to implement?
Should I create a custom token filter MyCustomTokenFilter, and override incrementToken(), etc? If so, how do tell Hibernate Search to ONLY use MyCustomTokenFilter during indexing and NOT during querying (so I can decide when to use the START and END tokens)?
hibernate search lucene
hibernate search lucene
asked Nov 10 at 18:45
Dimitri S.
366
366
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242261%2fhow-do-i-insert-additional-tokens-into-a-hibernate-search-token-stream%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown