3
用草堆了woosh搜索引擎
喜IM:草垛多個領域搜索
我的模型看起來如下
class Person(models.Model):
personid = models.IntegerField(primary_key = True, db_column = 'PID')
firstname = models.CharField(max_length = 50, db_column = 'FIRSTNAME')
lastname = models.CharField(max_length = 50, db_column = 'LASTNAME')
class Meta:
db_table = '"TEST"."PERSON"'
managed = False
class TDoc(models.Model):
tdocid = models.IntegerField(primary_key = True, db_column = 'TDOCID')
person = models.ForeignKey(Person, db_column = 'PID')
content = models.TextField(db_column = 'CONTENT', blank = True)
filepath = models.TextField(db_column = 'FILEPATH', blank = True)
class Meta:
db_table = '"TEST"."TDOC"'
managed = False
的search_index.py如下:
class TDocIndex(SearchIndex):
content = CharField(model_attr = 'content', document = True)
filepaht = CharField(model_attr = 'filepath')
person = CharField(model_attr = 'person')
def get_queryset(self):
return TDoc.objects.all()
def prepare_person(self, obj):
# Store a list of id's for filtering
return obj.person.lastname
site.register(TDoc, TDocIndex)
我問題是我想做多個提交搜索,如
內容:xxx和人物:史密斯
乾草堆上一次搜索他們,我不能做特定的字段搜索。 我懷疑我的索引已損壞,但:
ix = open_dir("/testindex")
searcher = ix.searcher()
mparser = MultifieldParser(["content", "filepath", "person"], schema = ix.schema)
myquery = mparser.parse(content:xxx AND person:SMITH')
results = searcher.search(myquery)
for result in results:
print result
,但它的工作原理和回報是正確的值。 我米使用標準的草垛搜索查看,search.html從教程
(r'^search/', include('haystack.urls')),