Using BooleanQuery or write more indexes?(使用 BooleanQuery 还是编写更多索引?)
问题描述
这样的类别树:
root_1
sub_1
sub_2
... to sub_20
每个文档都有一个子类别(如 sub_2).现在,我只在lucene索引中写了sub_2:
Every document has a sub category(like sub_2). Now, I only wrote sub_2 in lucene index:
new NumericField("category",...).setIntValue(sub_2.getID());
我想获取所有 root_1 的文档,使用 BooleanQuery(将 sub_1 合并到 sub_20)在每个条目文档中搜索或写入其他类别:
I want to get all root_1's documents, using BooleanQuery (merge the sub_1 to sub_20) to search or write an other category in every entry document:
new NumericField("category",...).setIntValue(sub_2.getID());
new NumericField("category",...).setIntValue(root_1.getID());//sub_2's ancestor category
哪个是更好的选择?
推荐答案
我将使用类别层次结构的路径枚举/'Dewey Decimal' 表示.也就是说,不是只为第一个根的第二个孩子存储sub_2",而是存储类似001.002"的东西.
I would use a path enumeration/'Dewey Decimal' representation of the category hierarchy. That is, instead of just storing 'sub_2' for the second child of the first root, store instead something like '001.002'.
要查找根及其所有子项,您可以搜索category:001*".
To find the root and all of its children, you would search on "category:001*".
要仅查找根的子项,您可以搜索category:001.*".
To find only the children of the root, you would search on "category:001.*".
(另请参阅 如何将树数据存储在 Lucene/Solr/Elasticsearch 索引或 NoSQL 数据库中?.)
这篇关于使用 BooleanQuery 还是编写更多索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 BooleanQuery 还是编写更多索引?
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
