1

スペースが含まれる by ファセットにnarrowing問題があります。SearchQuerySet

ElasticSearchでdjango-haystackを使用しています

次のインデックスがあります。

class ProductIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title') 

    category = indexes.MultiValueField(faceted=True) # m2m field
    weight = indexes.MultiValueField(faceted=True, null=True) 
    title_auto = indexes.EdgeNgramField(model_attr='title') # for autocomplete

def get_model(self):
    return Product

def prepare_category(self, obj):
    return [(cat.title) for cat in obj.categories.all()]

def prepare_weight(self, obj):
    return [(meta.value) for meta in obj.productmeta_set.filter(label="weight")]

しかし、クエリを実行しようとすると、非常に奇妙な結果が得られます。

合計ファセット数:

>>> sqs = SearchQuerySet().all().facet("category")
>>> sqs.facet_counts()
{'fields': {'category': [(u'Wall Tiles', 1028), (u'Floor Tiles', 440), (u'Baths', 49), (u'Basins', 25), (u'Toilets', 19)]}, 'dates': {}, 'queries': {}}

次のように、壁タイルの正しい値を取得できました。

>>> sqs.narrow("category:%s" % sqs.query.clean("Wall Tiles") ).count()
1028 # correct value

(これはFacetedSearchFormで使用されるメソッドを使用しています)

しかし、不思議なことに、床タイルに同じアプローチを使用すると、すべてのタイルが取得されます。

>>> sqs.narrow("category:%s" % sqs.query.clean("Floor Tiles") ).count()
1468 # incorrect (count of floor tiles + wall tiles)

さらに奇妙なのは、上記の Wall Tiles クエリを use に変更すると_exact、両方のカウントが返されることです!

>>> sqs.narrow("category_exact:%s" % sqs.query.clean("Wall Tiles") ).count()
1468

スペースが含まれていないカテゴリでは問題なく機能します。

ここで基本的な何かが欠けていると確信しています..しかし、私の人生では、なぜこのような奇妙な結果が得られるのかわかりません!

4

1 に答える 1