Reputation: 21
When I chain a filter before my more_like_this call on SearchQuerySet, the filter doesn't seem to be applied at all.
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='[email protected]').count() # 147 - 147 documents with [email protected]... so far so good
sqs().more_like_this(article).count() #54893
sqs().filter(author='[email protected]').more_like_this(article).count() # 54893!!!
I assumed doing:
sqs().filter(author='[email protected]').more_like_this(article)
would limit my MLT search within the 147 filtered documents, but it's almost as if the filter is being completely ignored.
I also tried reversing the order of the chain:
sqs().more_like_this(article).filter(author='[email protected]')
but it ends up with returning the entire search index
Any ideas? Thanks in advance.
Here's my 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)
Upvotes: 1
Views: 879
Reputation: 1298
I've run into the same problem long time ago - filtering with more like this is just not implemented in haystacks elasticsearch backend. I've made pull request to both pyelasticsearch and haystack to make it work. Pyelasticsearch allows it now, but haystack still have no support (and I've closed my pull request).
This commit fixes it in haystack: https://github.com/jasisz/django-haystack/commit/76473d8eebf49a0fffba025993a533b852aa8578
Upvotes: 2