Using BooleanQuery or write more indexes?

烂漫一生 提交于 2019-12-02 19:37:53

问题


A category tree like this:

root_1
  sub_1
  sub_2
  ... to sub_20 

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());

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

Which is the better choice?


回答1:


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

To find the root and all of its children, you would search on "category:001*".

To find only the children of the root, you would search on "category:001.*".

(Please also see How to store tree data in a Lucene/Solr/Elasticsearch index or a NoSQL db?.)



来源:https://stackoverflow.com/questions/10464377/using-booleanquery-or-write-more-indexes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!