如何将术语有效负载对放入 lucene 文档中
我有一个术语和相关有效负载的列表。我怎样才能将它们放入 lucene 文档或者更确切地说是一个字段中?
这是我的列表:
List<MyTerm> list = new List<MyTerm>(){
new MyTerm(){
Text = "apple",
Payload = BitConverter.GetBytes(2)
},
new MyTerm(){
Text = "juice",
Payload = BitConverter.GetBytes(5)
}};
我想我必须使用以下字段构造函数。
Field(string name, TokenStream tokenStream);
但是如何从我的列表中构建所需的 tokenStream 呢?
编辑
我想按字词搜索。自定义评分需要有效负载。
我的术语是图像的主色,我想存储该颜色的百分比,以便在按颜色搜索时进行评分。如果有人搜索红色图像,那么红色较多的图像的得分应该高于红色较少的图像。
编辑
我应该提到,一张图像可以有多种主色。此外,我希望能够通过多种主色搜索图像。例如:我想检索有很多红色和很多蓝色的图像。因此,我认为将颜色和强度放入不同的字段并不是一种选择。
I have a list of terms and associated payloads. How can I put these into a lucene document or rather a field?
Here is my list:
List<MyTerm> list = new List<MyTerm>(){
new MyTerm(){
Text = "apple",
Payload = BitConverter.GetBytes(2)
},
new MyTerm(){
Text = "juice",
Payload = BitConverter.GetBytes(5)
}};
I guess I have to use the following constructor of a field.
Field(string name, TokenStream tokenStream);
But how to build the required tokenStream from my list?
Edit
I want to search by terms. The payloads are needed for custom scoring.
My terms are dominant colors of an image and I want to store the percentage of that color for scoring when searching by colors. If someone searches for red images, images with a lot red in it should be scored higher then images with less red in it.
Edit
I should mention, that one image can have mulitiple dominant colors. Furthermore I want to be able to search for images by multiple dominant colors. For example: I want to retrieve images which have a lot red and a lot blue. Thus I guess putting colors and intensities into different fields is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,根据您的解释,我建议使用 2 个字段 - 一个用于术语(主色),一个用于有效负载(颜色强度) - 并对有效负载的结果进行排序。它可能如下所示:
color
字段用于查询,intensity
用于排序。如果需要,请将值存储在索引中。取决于您进一步的需求。
顺便说一句:请使用编辑功能用您的附加信息更新您的原始问题。
OK, based on your explanation I would suggest using 2 Fields - one for the term (dominant color) and one for the payload (intensity of color) - and sort the results on payload. This could look like this:
The
color
field is used for querying,intensity
for sorting.If you want to, store the values in the index. Depends on your further needs.
BTW: Please use the edit function to update your original question with your additional information.