具有多个不同值的字段 [英] Field having multiple distinct values

查看:84
本文介绍了具有多个不同值的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在使用Lucene构建图书搜索" API. 我需要在Lucene索引中索引Book Name,Author和Book类别字段.

Am building a "Book search" API using Lucene. I need to index Book Name,Author, and Book category fields in Lucene index.

一本书可以属于多个不同的书籍类别...例如:

A single book can fall under multiple distinct book categories...for example:

BookName1-小说,幽默,哲学. BookName1-小说,科学. BookName1-幽默,业务. BookName4-幽默 等等.....

BookName1 --fiction,humour,philosophy. BookName1 --fiction,science. BookName1 --humour,business. BookName4-humour and so on.....

用户应该能够搜索特定类别(例如荣誉")中的所有图书.

User should be able to search all the books under a particular category say "homour".

鉴于这种情况,我如何在以上字段中建立索引并在lucene中构建查询?

Given this situation, how do i index above fields and build the query in lucene?

推荐答案

您可以让一个Lucene文档的字段多次出现.创建文档,添加名称和作者的值,然后对每个类别执行相同的操作

You can have a field for a Lucene document occur multiple times. Create the document, add the values for the the name and author, then do the same for each category

  • 创建新的lucene文档
  • 添加名称字段和值
  • 添加作者字段和值
  • 每个类别:
    • 添加类别字段和值
    • create new lucene document
    • add name field and value
    • add author field and value
    • for each category:
      • add category field and value

      当您在索引中搜索类别时,它将返回所有具有类别字段且带有您要的值的文档.类别应为关键字"字段.

      When you search the index for a category, it will return all documents that have a category field with the value you're after. The category should be a 'Keyword' field.

      我用英语编写它是因为每个lucene版本的特定代码略有不同.

      I've written it in english because the specific code is slightly different per lucene version.

      这篇关于具有多个不同值的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆