-
Notifications
You must be signed in to change notification settings - Fork 6
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
Experiments: Add possible suggestion to the empty results response #391
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature seems nice, +1 to add it.
A few comments below though :)
private void hackQuery(SearchQuery<GuideSearchHit> query, String q, Language language, String highlightCssClass) { | ||
try { | ||
Field payloadField = ElasticsearchSearchQueryImpl.class.getDeclaredField("payload"); | ||
payloadField.setAccessible(true); | ||
JsonObject payload = (JsonObject) payloadField.get(query); | ||
JsonObject suggest = new JsonObject(); | ||
payload.add("suggest", suggest); | ||
suggest.addProperty("text", q); | ||
JsonObject suggestion = new JsonObject(); | ||
suggest.add("didYouMean", suggestion); | ||
JsonObject phrase = new JsonObject(); | ||
suggestion.add("phrase", phrase); | ||
phrase.addProperty("field", language.addSuffix("fullContent_suggestion")); | ||
phrase.addProperty("size", 1); | ||
phrase.addProperty("gram_size", 1); | ||
JsonObject highlight = new JsonObject(); | ||
phrase.add("highlight", highlight); | ||
highlight.addProperty("pre_tag", "<span class=\"" + highlightCssClass + "\">"); | ||
highlight.addProperty("post_tag", "</span>"); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you simply use https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-dsl-query-elasticsearch-json to edit the JSON? It doesn't require reflection and it's an actual API :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was looking for but didn't find! 🙈 😃 thanks! 😃
// To convert characters into ascii ones, e.g. à to a or ę to e etc. | ||
"asciifolding", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure converting Japanese to Ascii will go well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's true 🙈 😃. I suspect that it does not affect characters it doesn't know .... since we have this filter just above in the default analyzer (it is the last one in the list)
// To make all words in lowercase. | ||
"lowercase", | ||
// To convert characters into ascii ones, e.g. à to a or ę to e etc. | ||
"asciifolding", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, converting Chinese to ascii seems bold.
c811710
to
c62ebbc
Compare
c62ebbc
to
f11b6cb
Compare
f11b6cb
to
5a4161d
Compare
Hey @yrodiere
I was going through some tickets at HSEARCH 😃 and noticed one submitted by the community about suggesters, but without much info. Hence, I thought I'd take a closer look at the suggesters before closing the ticket 🙈 and it turned out to be an interesting feature. This PR tests how we could leverage from it in search.quarkus.io.
While at it, I thought: should we give users a way to manipulate the request JSON before we send it (like in this PR we are adding another top-level element to the JSON, so adding things through e.g. a JSON predicate, wouldn't really work...)
Some links: