我正在尝试将性别包括在后端返回的自动赛车中。
目前的设置:
当我输入搜索栏时,让我们说“ sh”,它给出了诸如鞋子,衬衫等的自动驾驶措施。
新要求:
当我输入搜索栏时,我们应该说“ sh”,它应该返回个性化的自动驾驶器,如下在用户个人资料中的性别上。
例子 :
如果用户是女性,请返回
“女性鞋子”
下方的“女性衬衫”,
如果用户是男性,则返回
“男性鞋子”“男士鞋子”
“男性衬衫”,
有人可以帮助我如何在弹性搜索和Java Springboot中实施此操作。
I am trying include gender in the autosuggestions returned from backend.
Present setup :
As I type in the search bar, let us say "Sh", it gives autosuggestions like shoes, shirts etc.
New requirement :
As I type in the search bar, let us say "Sh", it should return personalized autosuggestions like below based on gender in user's profile.
Example :
If user is a female, return below
"shoes for women"
"shirts for women"
If user is male, return below
"shoes for men"
"shirts for men"
Can someone help me how to implement this in elastic search and java springboot.
发布评论
评论(1)
在Elasticsearch中有几种实施此方法的方法。
使用完成建议。在“完成建议”字段中的每个条目中,将性别添加为类别上下文。在向Elasticsearch发送请求时,将您在用户中签名的性别添加到查询上下文中。
简单实现:
进行查询:
您将获得具有“男性”上下文的所有条目,并以“ SH”开头。您可以简单地将“男性”字符串附加到客户端应用程序中的每个结果的末尾。
要在Spring Boot中实现此目标:您需要参考此链接,该链接突出显示了如何通过Spring Boot API实现完成建议。
请注意,您像我在答案中的演示一样构建了索引。 Java/Spring引导中的确切API实现只是包装REST API。
There are several ways to implement this in Elasticsearch.
Use the completion suggester. To each entry in the completion suggestion field, add the gender as a category context. While sending requests to elasticsearch, add the gender of your signed in user to the the query context.
Simple implementation:
Make the Query:
You will get all the entries that have a "Male" context and start with "sh". You can simply append the string "for men" to the end of every result, in your client application.
To implement this in Spring Boot : You need to refer to this link that highlights how to implement the Completion Suggester via the Spring Boot Api.
Medium Article shows a sample Spring Boot Implementation
Please note that you structure the index like I demoed in my answer. The exact API implementaion in Java/Spring Boot just wraps the REST API.