Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marko-bekhta
Copy link
Collaborator

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...)

image

Some links:

Copy link
Member

@yrodiere yrodiere left a 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 :)

Comment on lines 169 to 162
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);
}
}
Copy link
Member

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 :)

Copy link
Collaborator Author

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! 😃

Comment on lines +181 to +182
// To convert characters into ascii ones, e.g. à to a or ę to e etc.
"asciifolding",
Copy link
Member

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...

Copy link
Collaborator Author

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",
Copy link
Member

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.

src/main/resources/web/app/qs-target.ts Outdated Show resolved Hide resolved
@marko-bekhta
Copy link
Collaborator Author

ok... played with it a bit more so it's more usable on the actual site, and user can click to get the results:

sugg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants