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.










share|improve this question
























  • Do wildcards work? .matching("*foo*foo*") lucene.apache.org/core/2_9_4/…
    – Selaron
    2 days ago















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.










share|improve this question
























  • Do wildcards work? .matching("*foo*foo*") lucene.apache.org/core/2_9_4/…
    – Selaron
    2 days ago













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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.






share|improve this answer





















  • 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













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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
































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.






share|improve this answer





















  • 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

















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.






share|improve this answer





















  • 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















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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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




















  • 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




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff