SearchQuerySet での more_like_this 呼び出しの前にフィルターをチェーンすると、フィルターがまったく適用されないように見えます。
from haystack.query import SearchQuerySet as sqs
from articles.models import Article
article = Article.objects.get(pk=4560) # Article instance of one of the many articles I have
sqs().filter(author='testest@testtest.com').count() # 147 - 147 documents with author=testest@testtest.com... so far so good
sqs().more_like_this(article).count() #54893
sqs().filter(author='testest@testtest.com').more_like_this(article).count() # 54893!!!
私は次のことを想定しました:
sqs().filter(author='testest@testtest.com').more_like_this(article)
私の MLT 検索を 147 のフィルターされたドキュメント内に制限しますが、まるでフィルターが完全に無視されているかのようです。
また、チェーンの順序を逆にしてみました:
sqs().more_like_this(article).filter(author='testest@testtest.com')
しかし、検索インデックス全体を返すことになります
何か案は?前もって感謝します。
これが私の article_text.txt です
{{ object.title }}
{{ object.body.excerpt|striptags|escape }}
search_index.py
class ArticleIndexes(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True, boost=1.1)
author = indexes.CharField(model_attr='author')
site_id = indexes.CharField(model_attr='site_id')
# non-indexed, stored field
stored_obj = ArticleStorageField(indexed=False)