Hibernate Search Lucene. Suggestion but almost like SQL “LIKE”2019 Community Moderator ElectionHibernate Search: How to use wildcards correctly?Comparison of full text search engine - Lucene, Sphinx, Postgresql, MySQL?Hibernate show real SQLwhat analzyer is good for my situation? hibernate search caseAnd operator in Hibernate (lucene) searchHibernate lucene search include “the” and “a” as part of searchLucene Hibernate-Search - Filtering Query-StringSearching Solr index for concatenated wordsHow to handle synonyms and stop words when building a fuzzy query with Hibernate Search Query DSLhibernate query not searching beyond 2 characters for some strings and not working on multi word searchhow to retrieve exact search results with multiple query strings in hibernate search
How can I manipulate the output of Information?
Do I really need to have a scientific explanation for my premise?
Giving a career talk in my old university, how prominently should I tell students my salary?
What's the 'present simple' form of the word "нашла́" in 3rd person singular female?
What is Earthy controling in the ISS cupola?
What are some noteworthy "mic-drop" moments in math?
Create chunks from an array
Are all players supposed to be able to see each others' character sheets?
Why does liquid water form when we exhale on a mirror?
What do you call someone who likes to pick fights?
Why does cron require MTA for logging?
Virginia employer terminated employee and wants signing bonus returned
Trig Subsitution When There's No Square Root
What do *foreign films* mean for an American?
Minimizing with differential evolution
What materials can be used to make a humanoid skin warm?
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
Conservation of Mass and Energy
Should I take out a loan for a friend to invest on my behalf?
How to draw dashed arc of a circle behind pyramid?
Crossing a border with an infant of a different citizenship
Why couldn't the separatists legally leave the Republic?
Am I understanding this Storm King's Thunder map wrong?
Is divide-by-zero a security vulnerability?
Hibernate Search Lucene. Suggestion but almost like SQL “LIKE”
2019 Community Moderator ElectionHibernate Search: How to use wildcards correctly?Comparison of full text search engine - Lucene, Sphinx, Postgresql, MySQL?Hibernate show real SQLwhat analzyer is good for my situation? hibernate search caseAnd operator in Hibernate (lucene) searchHibernate lucene search include “the” and “a” as part of searchLucene Hibernate-Search - Filtering Query-StringSearching Solr index for concatenated wordsHow to handle synonyms and stop words when building a fuzzy query with Hibernate Search Query DSLhibernate query not searching beyond 2 characters for some strings and not working on multi word searchhow to retrieve exact search results with multiple query strings in hibernate search
Its my first time dealing with optimized search functionality, and part of my proficiency is on the front end of android development, but I'm willing to take the adventure of hibernate-search. I do understand the functionality of SQL "LIKE" query, what it does and its limitation, thats the reason why I jumped straight ahead to hibernate-search (lucene), my goal is to have an auto suggestion based on inputs(input queries). This is what I got so far
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "myanalyzer",
tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class), //
filters = //
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = WordDelimiterFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),)
@Analyzer(definition = "myanalyzer")
public class Shop implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
enter code here
@Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
private String name;
... other methods
My query
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
Its just a basic query, and I focus solely on the analyzer configuration to get what I want, its really confusing which part should I focus on to achieve what I want, the Tokenizing? the Filtering? or the Query itself?
anyway I have these 2 phrases already indexed.
"Apache Lychee Department"
"Apache Strawberry Club Large"
When I process/query "Straw" it gives me the Apache Strawberry Club Large
but when I process/query "Lychee" or "Apache Lychee" the query gives me both? Im only expecting Apache Lychee Department
The way I understand all my configuration is/are
EdgeNGramFilterFactory (1024) will give me a series of 1,024 index of EdgeNGrams
LowerCaseFilterFactory will give me all lower-cased indeces
WordDelimiterFilterFactory filter it by making the query as one word, and give me the matching data.
and every entry/data will be tokenized as a Keyword by KeywordTokenizerFactory and will be indexed 1,024 by EdgeNGram
I tried to query a phrase, but still getting the same output
Query luceneQuery = qb.phrase().onField("name").sentence(searchTerm).createQuery();
My Goal is to have an auto-suggestion.. or atleast start with mimicking "LIKE" of sql..
hibernate lucene hibernate-search lexical-analysis
New contributor
add a comment |
Its my first time dealing with optimized search functionality, and part of my proficiency is on the front end of android development, but I'm willing to take the adventure of hibernate-search. I do understand the functionality of SQL "LIKE" query, what it does and its limitation, thats the reason why I jumped straight ahead to hibernate-search (lucene), my goal is to have an auto suggestion based on inputs(input queries). This is what I got so far
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "myanalyzer",
tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class), //
filters = //
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = WordDelimiterFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),)
@Analyzer(definition = "myanalyzer")
public class Shop implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
enter code here
@Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
private String name;
... other methods
My query
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
Its just a basic query, and I focus solely on the analyzer configuration to get what I want, its really confusing which part should I focus on to achieve what I want, the Tokenizing? the Filtering? or the Query itself?
anyway I have these 2 phrases already indexed.
"Apache Lychee Department"
"Apache Strawberry Club Large"
When I process/query "Straw" it gives me the Apache Strawberry Club Large
but when I process/query "Lychee" or "Apache Lychee" the query gives me both? Im only expecting Apache Lychee Department
The way I understand all my configuration is/are
EdgeNGramFilterFactory (1024) will give me a series of 1,024 index of EdgeNGrams
LowerCaseFilterFactory will give me all lower-cased indeces
WordDelimiterFilterFactory filter it by making the query as one word, and give me the matching data.
and every entry/data will be tokenized as a Keyword by KeywordTokenizerFactory and will be indexed 1,024 by EdgeNGram
I tried to query a phrase, but still getting the same output
Query luceneQuery = qb.phrase().onField("name").sentence(searchTerm).createQuery();
My Goal is to have an auto-suggestion.. or atleast start with mimicking "LIKE" of sql..
hibernate lucene hibernate-search lexical-analysis
New contributor
add a comment |
Its my first time dealing with optimized search functionality, and part of my proficiency is on the front end of android development, but I'm willing to take the adventure of hibernate-search. I do understand the functionality of SQL "LIKE" query, what it does and its limitation, thats the reason why I jumped straight ahead to hibernate-search (lucene), my goal is to have an auto suggestion based on inputs(input queries). This is what I got so far
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "myanalyzer",
tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class), //
filters = //
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = WordDelimiterFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),)
@Analyzer(definition = "myanalyzer")
public class Shop implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
enter code here
@Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
private String name;
... other methods
My query
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
Its just a basic query, and I focus solely on the analyzer configuration to get what I want, its really confusing which part should I focus on to achieve what I want, the Tokenizing? the Filtering? or the Query itself?
anyway I have these 2 phrases already indexed.
"Apache Lychee Department"
"Apache Strawberry Club Large"
When I process/query "Straw" it gives me the Apache Strawberry Club Large
but when I process/query "Lychee" or "Apache Lychee" the query gives me both? Im only expecting Apache Lychee Department
The way I understand all my configuration is/are
EdgeNGramFilterFactory (1024) will give me a series of 1,024 index of EdgeNGrams
LowerCaseFilterFactory will give me all lower-cased indeces
WordDelimiterFilterFactory filter it by making the query as one word, and give me the matching data.
and every entry/data will be tokenized as a Keyword by KeywordTokenizerFactory and will be indexed 1,024 by EdgeNGram
I tried to query a phrase, but still getting the same output
Query luceneQuery = qb.phrase().onField("name").sentence(searchTerm).createQuery();
My Goal is to have an auto-suggestion.. or atleast start with mimicking "LIKE" of sql..
hibernate lucene hibernate-search lexical-analysis
New contributor
Its my first time dealing with optimized search functionality, and part of my proficiency is on the front end of android development, but I'm willing to take the adventure of hibernate-search. I do understand the functionality of SQL "LIKE" query, what it does and its limitation, thats the reason why I jumped straight ahead to hibernate-search (lucene), my goal is to have an auto suggestion based on inputs(input queries). This is what I got so far
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "myanalyzer",
tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class), //
filters = //
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = WordDelimiterFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),)
@Analyzer(definition = "myanalyzer")
public class Shop implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
enter code here
@Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
private String name;
... other methods
My query
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
Its just a basic query, and I focus solely on the analyzer configuration to get what I want, its really confusing which part should I focus on to achieve what I want, the Tokenizing? the Filtering? or the Query itself?
anyway I have these 2 phrases already indexed.
"Apache Lychee Department"
"Apache Strawberry Club Large"
When I process/query "Straw" it gives me the Apache Strawberry Club Large
but when I process/query "Lychee" or "Apache Lychee" the query gives me both? Im only expecting Apache Lychee Department
The way I understand all my configuration is/are
EdgeNGramFilterFactory (1024) will give me a series of 1,024 index of EdgeNGrams
LowerCaseFilterFactory will give me all lower-cased indeces
WordDelimiterFilterFactory filter it by making the query as one word, and give me the matching data.
and every entry/data will be tokenized as a Keyword by KeywordTokenizerFactory and will be indexed 1,024 by EdgeNGram
I tried to query a phrase, but still getting the same output
Query luceneQuery = qb.phrase().onField("name").sentence(searchTerm).createQuery();
My Goal is to have an auto-suggestion.. or atleast start with mimicking "LIKE" of sql..
hibernate lucene hibernate-search lexical-analysis
hibernate lucene hibernate-search lexical-analysis
New contributor
New contributor
edited Mar 7 at 5:26
Nestor Briaga
New contributor
asked Mar 7 at 5:18
Nestor BriagaNestor Briaga
32
32
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
There are two things you should take into account:
- By default, when there are multiple terms in a query, the results will include documents that match any of the terms, not all of the terms.
- By default, your queries will be analyzed using the same analyzer you used when indexing.
This means in particular that your query "Lychee" will be analyzed to something like "L Ly Lyc Lych Lyche Lychee" (because of the edge ngram filter). The string "Apache Strawberry Club Large" because it was previously analyzed and the term "Large" was expanded to "L La Lar Larg Large" because of the edge ngram filter. So the query "Lychee" will match "Apache Strawberry Club Large", simply because they both contain a word that starts with L...
That's obviously undesired behavior.
The first step would be to change the way your query is analyzed, so that you don't end up matching completely unrelated documents.
Basically you will need to define another analyzer which is almost identical, but does not have the "edge ngram" filter. Then you will need to tell Hibernate Search to use that analyzer to analyze your query.
See this answer for a detailed explanation.
As a second step, you need to make your query match if all the included terms are present in a document. To that end, the easiest solution would be to use the simple query string query instead of the keyword query.
Replace this:
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
With this:
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(searchTerm).createQuery();
The key being the call to .withAndAsDefaultOperator()
.
This change will have several other effects, such as enabling special syntax in the input string, so I'd encourage your to read the reference documentation to know what simpleQueryString
is about exactly.
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
add a comment |
I made it work by this, thanks to @yrodiere
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "edgeNgram",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),
)
@AnalyzerDef(name = "search_query_analyzer",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class)
)
public class Shop implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Field(store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
@Analyzer(definition = "edgeNgram")
private String name;
public void setName(String name)
this.name = name;
public String getName()
return this.name;
and my query
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Shop.class)
.overridesForField("name", "search_query_analyzer").get();
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(shopSearchTerm).createQuery();
But im not sure if Im implementing it on proper approach..
New contributor
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
Nestor Briaga is a new contributor. Be nice, and check out our Code of Conduct.
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%2f55036564%2fhibernate-search-lucene-suggestion-but-almost-like-sql-like%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are two things you should take into account:
- By default, when there are multiple terms in a query, the results will include documents that match any of the terms, not all of the terms.
- By default, your queries will be analyzed using the same analyzer you used when indexing.
This means in particular that your query "Lychee" will be analyzed to something like "L Ly Lyc Lych Lyche Lychee" (because of the edge ngram filter). The string "Apache Strawberry Club Large" because it was previously analyzed and the term "Large" was expanded to "L La Lar Larg Large" because of the edge ngram filter. So the query "Lychee" will match "Apache Strawberry Club Large", simply because they both contain a word that starts with L...
That's obviously undesired behavior.
The first step would be to change the way your query is analyzed, so that you don't end up matching completely unrelated documents.
Basically you will need to define another analyzer which is almost identical, but does not have the "edge ngram" filter. Then you will need to tell Hibernate Search to use that analyzer to analyze your query.
See this answer for a detailed explanation.
As a second step, you need to make your query match if all the included terms are present in a document. To that end, the easiest solution would be to use the simple query string query instead of the keyword query.
Replace this:
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
With this:
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(searchTerm).createQuery();
The key being the call to .withAndAsDefaultOperator()
.
This change will have several other effects, such as enabling special syntax in the input string, so I'd encourage your to read the reference documentation to know what simpleQueryString
is about exactly.
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
add a comment |
There are two things you should take into account:
- By default, when there are multiple terms in a query, the results will include documents that match any of the terms, not all of the terms.
- By default, your queries will be analyzed using the same analyzer you used when indexing.
This means in particular that your query "Lychee" will be analyzed to something like "L Ly Lyc Lych Lyche Lychee" (because of the edge ngram filter). The string "Apache Strawberry Club Large" because it was previously analyzed and the term "Large" was expanded to "L La Lar Larg Large" because of the edge ngram filter. So the query "Lychee" will match "Apache Strawberry Club Large", simply because they both contain a word that starts with L...
That's obviously undesired behavior.
The first step would be to change the way your query is analyzed, so that you don't end up matching completely unrelated documents.
Basically you will need to define another analyzer which is almost identical, but does not have the "edge ngram" filter. Then you will need to tell Hibernate Search to use that analyzer to analyze your query.
See this answer for a detailed explanation.
As a second step, you need to make your query match if all the included terms are present in a document. To that end, the easiest solution would be to use the simple query string query instead of the keyword query.
Replace this:
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
With this:
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(searchTerm).createQuery();
The key being the call to .withAndAsDefaultOperator()
.
This change will have several other effects, such as enabling special syntax in the input string, so I'd encourage your to read the reference documentation to know what simpleQueryString
is about exactly.
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
add a comment |
There are two things you should take into account:
- By default, when there are multiple terms in a query, the results will include documents that match any of the terms, not all of the terms.
- By default, your queries will be analyzed using the same analyzer you used when indexing.
This means in particular that your query "Lychee" will be analyzed to something like "L Ly Lyc Lych Lyche Lychee" (because of the edge ngram filter). The string "Apache Strawberry Club Large" because it was previously analyzed and the term "Large" was expanded to "L La Lar Larg Large" because of the edge ngram filter. So the query "Lychee" will match "Apache Strawberry Club Large", simply because they both contain a word that starts with L...
That's obviously undesired behavior.
The first step would be to change the way your query is analyzed, so that you don't end up matching completely unrelated documents.
Basically you will need to define another analyzer which is almost identical, but does not have the "edge ngram" filter. Then you will need to tell Hibernate Search to use that analyzer to analyze your query.
See this answer for a detailed explanation.
As a second step, you need to make your query match if all the included terms are present in a document. To that end, the easiest solution would be to use the simple query string query instead of the keyword query.
Replace this:
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
With this:
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(searchTerm).createQuery();
The key being the call to .withAndAsDefaultOperator()
.
This change will have several other effects, such as enabling special syntax in the input string, so I'd encourage your to read the reference documentation to know what simpleQueryString
is about exactly.
There are two things you should take into account:
- By default, when there are multiple terms in a query, the results will include documents that match any of the terms, not all of the terms.
- By default, your queries will be analyzed using the same analyzer you used when indexing.
This means in particular that your query "Lychee" will be analyzed to something like "L Ly Lyc Lych Lyche Lychee" (because of the edge ngram filter). The string "Apache Strawberry Club Large" because it was previously analyzed and the term "Large" was expanded to "L La Lar Larg Large" because of the edge ngram filter. So the query "Lychee" will match "Apache Strawberry Club Large", simply because they both contain a word that starts with L...
That's obviously undesired behavior.
The first step would be to change the way your query is analyzed, so that you don't end up matching completely unrelated documents.
Basically you will need to define another analyzer which is almost identical, but does not have the "edge ngram" filter. Then you will need to tell Hibernate Search to use that analyzer to analyze your query.
See this answer for a detailed explanation.
As a second step, you need to make your query match if all the included terms are present in a document. To that end, the easiest solution would be to use the simple query string query instead of the keyword query.
Replace this:
Query lucenQuery = qb.keyword().onField("name").matching(searchTerm).createQuery();
With this:
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(searchTerm).createQuery();
The key being the call to .withAndAsDefaultOperator()
.
This change will have several other effects, such as enabling special syntax in the input string, so I'd encourage your to read the reference documentation to know what simpleQueryString
is about exactly.
answered 2 days ago
yrodiereyrodiere
2,7961315
2,7961315
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
add a comment |
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
Sorry for the late response, Thank you so much for this very informative assistance, I'm atleast on the right direction. Thank you
– Nestor Briaga
3 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
And also, I didnt realize that NGram will create Index for each word, i though it will only index per entry.. didnt expect that for every white space, it will create an index..
– Nestor Briaga
2 hours ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
Hello again, I made it work, i checked the link you gave me and I didnt know you can create a separate analyzer apart from creating a first analyzer, but would you mind checking the code I did, if Im making the approach right?
– Nestor Briaga
1 hour ago
add a comment |
I made it work by this, thanks to @yrodiere
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "edgeNgram",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),
)
@AnalyzerDef(name = "search_query_analyzer",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class)
)
public class Shop implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Field(store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
@Analyzer(definition = "edgeNgram")
private String name;
public void setName(String name)
this.name = name;
public String getName()
return this.name;
and my query
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Shop.class)
.overridesForField("name", "search_query_analyzer").get();
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(shopSearchTerm).createQuery();
But im not sure if Im implementing it on proper approach..
New contributor
add a comment |
I made it work by this, thanks to @yrodiere
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "edgeNgram",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),
)
@AnalyzerDef(name = "search_query_analyzer",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class)
)
public class Shop implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Field(store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
@Analyzer(definition = "edgeNgram")
private String name;
public void setName(String name)
this.name = name;
public String getName()
return this.name;
and my query
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Shop.class)
.overridesForField("name", "search_query_analyzer").get();
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(shopSearchTerm).createQuery();
But im not sure if Im implementing it on proper approach..
New contributor
add a comment |
I made it work by this, thanks to @yrodiere
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "edgeNgram",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),
)
@AnalyzerDef(name = "search_query_analyzer",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class)
)
public class Shop implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Field(store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
@Analyzer(definition = "edgeNgram")
private String name;
public void setName(String name)
this.name = name;
public String getName()
return this.name;
and my query
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Shop.class)
.overridesForField("name", "search_query_analyzer").get();
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(shopSearchTerm).createQuery();
But im not sure if Im implementing it on proper approach..
New contributor
I made it work by this, thanks to @yrodiere
@Indexed
@Table (name = "shop_table")
@Entity
@AnalyzerDef(name = "edgeNgram",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params =
@Parameter(name = "maxGramSize", value = "1024") ),
)
@AnalyzerDef(name = "search_query_analyzer",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters =
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class)
)
public class Shop implements Serializable
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Field(store = Store.YES, analyze = Analyze.YES)
@Column(name = "name")
@Analyzer(definition = "edgeNgram")
private String name;
public void setName(String name)
this.name = name;
public String getName()
return this.name;
and my query
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Shop.class)
.overridesForField("name", "search_query_analyzer").get();
Query lucenQuery = qb.simpleQueryString().onField("name").withAndAsDefaultOperator().matching(shopSearchTerm).createQuery();
But im not sure if Im implementing it on proper approach..
New contributor
edited 32 mins ago
New contributor
answered 1 hour ago
Nestor BriagaNestor Briaga
32
32
New contributor
New contributor
add a comment |
add a comment |
Nestor Briaga is a new contributor. Be nice, and check out our Code of Conduct.
Nestor Briaga is a new contributor. Be nice, and check out our Code of Conduct.
Nestor Briaga is a new contributor. Be nice, and check out our Code of Conduct.
Nestor Briaga is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55036564%2fhibernate-search-lucene-suggestion-but-almost-like-sql-like%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