Hibernate Search: Searching by multiple equal words
up vote
1
down vote
favorite
I use Hibernate Search 5.10.3, and I cannot search results which contain only N equal words. For instance, having the following samples in my index:
1. foo foo
2. foo bar
I want to get only the line 1 matching "foo foo", so I make the following query :
queryBuilder.simpleQueryString().onField("myField").matching("foo + foo").createQuery();
But this query returns both "foo foo" and "foo bar".
How to do this using hibernate search?
In general I need search all typed words in any order with considering of their count.
1)All words in search query must be in the field in any order 2) with the same count. I can reach 1) but have no idea how I can reach 2). Example:
1. foo bar smth
2. foo bar smth bar
If I search "bar smth foo" I need only 1. if "bar foo bar smth" - only 2.
java hibernate hibernate-search
add a comment |
up vote
1
down vote
favorite
I use Hibernate Search 5.10.3, and I cannot search results which contain only N equal words. For instance, having the following samples in my index:
1. foo foo
2. foo bar
I want to get only the line 1 matching "foo foo", so I make the following query :
queryBuilder.simpleQueryString().onField("myField").matching("foo + foo").createQuery();
But this query returns both "foo foo" and "foo bar".
How to do this using hibernate search?
In general I need search all typed words in any order with considering of their count.
1)All words in search query must be in the field in any order 2) with the same count. I can reach 1) but have no idea how I can reach 2). Example:
1. foo bar smth
2. foo bar smth bar
If I search "bar smth foo" I need only 1. if "bar foo bar smth" - only 2.
java hibernate hibernate-search
Do wildcards work?.matching("*foo*foo*")
lucene.apache.org/core/2_9_4/…
– Selaron
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I use Hibernate Search 5.10.3, and I cannot search results which contain only N equal words. For instance, having the following samples in my index:
1. foo foo
2. foo bar
I want to get only the line 1 matching "foo foo", so I make the following query :
queryBuilder.simpleQueryString().onField("myField").matching("foo + foo").createQuery();
But this query returns both "foo foo" and "foo bar".
How to do this using hibernate search?
In general I need search all typed words in any order with considering of their count.
1)All words in search query must be in the field in any order 2) with the same count. I can reach 1) but have no idea how I can reach 2). Example:
1. foo bar smth
2. foo bar smth bar
If I search "bar smth foo" I need only 1. if "bar foo bar smth" - only 2.
java hibernate hibernate-search
I use Hibernate Search 5.10.3, and I cannot search results which contain only N equal words. For instance, having the following samples in my index:
1. foo foo
2. foo bar
I want to get only the line 1 matching "foo foo", so I make the following query :
queryBuilder.simpleQueryString().onField("myField").matching("foo + foo").createQuery();
But this query returns both "foo foo" and "foo bar".
How to do this using hibernate search?
In general I need search all typed words in any order with considering of their count.
1)All words in search query must be in the field in any order 2) with the same count. I can reach 1) but have no idea how I can reach 2). Example:
1. foo bar smth
2. foo bar smth bar
If I search "bar smth foo" I need only 1. if "bar foo bar smth" - only 2.
java hibernate hibernate-search
java hibernate hibernate-search
edited 2 days ago
asked 2 days ago
Alexander Dudarkov
62
62
Do wildcards work?.matching("*foo*foo*")
lucene.apache.org/core/2_9_4/…
– Selaron
2 days ago
add a comment |
Do wildcards work?.matching("*foo*foo*")
lucene.apache.org/core/2_9_4/…
– Selaron
2 days ago
Do wildcards work?
.matching("*foo*foo*")
lucene.apache.org/core/2_9_4/…– Selaron
2 days ago
Do wildcards work?
.matching("*foo*foo*")
lucene.apache.org/core/2_9_4/…– Selaron
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
That's not the kind of thing that is easy to do with Lucene. You might want to reconsider your use case, see if full-text search really is the way to go.
I don't have an exact solution to give you, but phrase queries look fairly similar to what you're trying to achieve.
You could try something like this:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"").createQuery();
The above will match two "bar" that strictly follow each other. If you want to be a bit more lenient, you can set the slop:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"~2").createQuery();
This will match two "bar" that follow each other OR are separated by one or two words. The actual meaning is a bit more complicated, but you get the idea. You can find an exact definition of the slop in the javadoc of org.apache.lucene.search.PhraseQuery#getSlop
.
I suppose using a very high slop would achieve more or less what you want, but that might have a bad impact on performance.
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
That's not the kind of thing that is easy to do with Lucene. You might want to reconsider your use case, see if full-text search really is the way to go.
I don't have an exact solution to give you, but phrase queries look fairly similar to what you're trying to achieve.
You could try something like this:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"").createQuery();
The above will match two "bar" that strictly follow each other. If you want to be a bit more lenient, you can set the slop:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"~2").createQuery();
This will match two "bar" that follow each other OR are separated by one or two words. The actual meaning is a bit more complicated, but you get the idea. You can find an exact definition of the slop in the javadoc of org.apache.lucene.search.PhraseQuery#getSlop
.
I suppose using a very high slop would achieve more or less what you want, but that might have a bad impact on performance.
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
add a comment |
up vote
0
down vote
That's not the kind of thing that is easy to do with Lucene. You might want to reconsider your use case, see if full-text search really is the way to go.
I don't have an exact solution to give you, but phrase queries look fairly similar to what you're trying to achieve.
You could try something like this:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"").createQuery();
The above will match two "bar" that strictly follow each other. If you want to be a bit more lenient, you can set the slop:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"~2").createQuery();
This will match two "bar" that follow each other OR are separated by one or two words. The actual meaning is a bit more complicated, but you get the idea. You can find an exact definition of the slop in the javadoc of org.apache.lucene.search.PhraseQuery#getSlop
.
I suppose using a very high slop would achieve more or less what you want, but that might have a bad impact on performance.
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
That's not the kind of thing that is easy to do with Lucene. You might want to reconsider your use case, see if full-text search really is the way to go.
I don't have an exact solution to give you, but phrase queries look fairly similar to what you're trying to achieve.
You could try something like this:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"").createQuery();
The above will match two "bar" that strictly follow each other. If you want to be a bit more lenient, you can set the slop:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"~2").createQuery();
This will match two "bar" that follow each other OR are separated by one or two words. The actual meaning is a bit more complicated, but you get the idea. You can find an exact definition of the slop in the javadoc of org.apache.lucene.search.PhraseQuery#getSlop
.
I suppose using a very high slop would achieve more or less what you want, but that might have a bad impact on performance.
That's not the kind of thing that is easy to do with Lucene. You might want to reconsider your use case, see if full-text search really is the way to go.
I don't have an exact solution to give you, but phrase queries look fairly similar to what you're trying to achieve.
You could try something like this:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"").createQuery();
The above will match two "bar" that strictly follow each other. If you want to be a bit more lenient, you can set the slop:
queryBuilder.simpleQueryString().onField("myField").matching("foo smth "bar bar"~2").createQuery();
This will match two "bar" that follow each other OR are separated by one or two words. The actual meaning is a bit more complicated, but you get the idea. You can find an exact definition of the slop in the javadoc of org.apache.lucene.search.PhraseQuery#getSlop
.
I suppose using a very high slop would achieve more or less what you want, but that might have a bad impact on performance.
answered 2 days ago
yrodiere
2,4861314
2,4861314
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
add a comment |
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
Thank you for the reply! I need it for the strict name search. And when I search for example John John Smith I need only fields which have 3 words: two John and one Smith. So generally my goal is: if entered N words - receive fields with N words which exactly match entered words but in any order (without some extra words which not entered). (One field contains a full name)
– Alexander Dudarkov
yesterday
add a comment |
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203525%2fhibernate-search-searching-by-multiple-equal-words%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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
Do wildcards work?
.matching("*foo*foo*")
lucene.apache.org/core/2_9_4/…– Selaron
2 days ago