如何在Djapian复合索引上进行标记搜索

时间:2012-09-13 15:40:54

标签: python django xapian

我有一个像这样的Djapian Indexer ..

class SomeModelIndexer(Indexer):
   fields = ["body"]
   tags = [('title', 'title', 2),
           ('tag', 'strtags')]

space.add_index(SomeModel, SomeModelIndexer, attach_as="indexer")

这允许我通过标签搜索SomeModels,搜索类似“tag:sausages”,它会找到任何标有“sausages”的SomeModels。 (strtags是SomeModel上的@property修饰函数)。

In [1]: from project.someapp.models import SomeModel
In [2]: from project.someapp import index
In [3]: SomeModel.indexer.search("tag:sausages").count()
Out[3]: 2L

这样可行,但我也有一个包含SomeModelIndexer的CompositeIndexer,但搜索“tag:sausages”的索引器会返回零结果。

composite_index = CompositeIndexer(SomeModel.indexer, AnotherModel.indexer)

In [4]: index.composite_index.search("tag:sausages").count()
Out[4]: 0L

有关如何使其发挥作用的任何线索?

1 个答案:

答案 0 :(得分:2)

我认为你应该提交一个错误。

如果您只搜索sausages,则应返回一些结果。

按照tutorial我做了一些查询后做了一些测试:

Person.indexer.search("name:alex").count() --> 2L --> OK
Movie.indexer.search("director:alex").count() --> 1L --> OK

index.complete_indexer.search("name:alex").count() --> 0L --> WRONG
index.complete_indexer.search("director:alex").count() --> 0L --> WRONG
index.complete_indexer.search("alex").count() --> 3L --> OK

complete_indexer是两个索引之间的CompositeIndexer

相关问题