from haystack.query import SearchQuerySet, SQ, AutoQuery
search_term = 'C100'
sqs = SearchQuerySet().models(Product).filter(SQ(text=AutoQuery(search_term)) | SQ(brand_name=search_term) )
for s in sqs:
print s.boost, s.score, s.brand_name, ':', s.object.name
class ProductIndex(CelerySearchIndex, indexes.Indexable):
"""
1.5 0.84893364 Zacuto : Zacuto Recoil Shoulder Rig for C100, C100II & C300
1.5 0.84868896 Zacuto : Zacuto Z-Finder Pro for Canon C100
1.0 0.70724076 Zacuto : Zacuto Studio Baseplate with 12" Rods for C100/C100II/C300/C500
1.0 0.70021886 Canon : Canon CA-930 Battery Charger for C100/C100II/C300/C500
1.0 0.6494849 Anton Bauer : Anton Bauer QRC-CA940 Battery Plate for Canon C500, C300 & C100
1.0 0.6002867 Canon : Canon BP-970G Battery Pack for C100/C100II/C300/C500
2.0 0.5658623 Canon : Canon C100 Mark II Digital Cinema Camera EF Mount
1.5 0.4332277 Canon : Canon 100 f/2.8L IS Macro
"""
text = indexes.CharField(document=True, use_template=True)
product_id = indexes.IntegerField(model_attr='id', null=False)
brand_name = indexes.CharField(model_attr='brand__name', null=True, weight=1.75)
def get_model(self):
return models.Product
def index_queryset(self, using=None):
return self.get_model().objects.filter(is_active=True)
def prepare(self, instance):
data = super(ProductIndex, self).prepare(instance)
data['boost'] = 1.5 # even weight everything
if instance.is_camera:
data['boost'] = 2.0 # weight cameras higher
elif instance.is_accessory:
data['boost'] = 1.0 # weight accessories lower
return data
class ProductIndex(CelerySearchIndex, indexes.Indexable):
"""
None 0.84893364 Zacuto : Zacuto Recoil Shoulder Rig for C100, C100II & C300
None 0.84868896 Zacuto : Zacuto Z-Finder Pro for Canon C100
None 0.70724076 Zacuto : Zacuto Studio Baseplate with 12" Rods for C100/C100II/C300/C500
None 0.70021886 Canon : Canon CA-930 Battery Charger for C100/C100II/C300/C500
None 0.6494849 Anton Bauer : Anton Bauer QRC-CA940 Battery Plate for Canon C500, C300 & C100
None 0.6002867 Canon : Canon BP-970G Battery Pack for C100/C100II/C300/C500
None 0.5658623 Canon : Canon C100 Mark II Digital Cinema Camera EF Mount
None 0.4332277 Canon : Canon 100 f/2.8L IS Macro
"""
text = indexes.CharField(document=True, use_template=True)
product_id = indexes.IntegerField(model_attr='id', null=False)
brand_name = indexes.CharField(model_attr='brand__name', null=True, weight=5.0)
def get_model(self):
return models.Product
def index_queryset(self, using=None):
return self.get_model().objects.filter(is_active=True)
class ProductIndex(CelerySearchIndex, indexes.Indexable):
"""
None 0.84893364 Zacuto : Zacuto Recoil Shoulder Rig for C100, C100II & C300
None 0.84868896 Zacuto : Zacuto Z-Finder Pro for Canon C100
None 0.70724076 Zacuto : Zacuto Studio Baseplate with 12" Rods for C100/C100II/C300/C500
None 0.70021886 Canon : Canon CA-930 Battery Charger for C100/C100II/C300/C500
None 0.6889441 Anton Bauer : Anton Bauer QRC-CA940 Battery Plate for Canon C500, C300 & C100
None 0.6002867 Canon : Canon BP-970G Battery Pack for C100/C100II/C300/C500
None 0.5658623 Canon : Canon C100 Mark II Digital Cinema Camera EF Mount
None 0.4332277 Canon : Canon 100 f/2.8L IS Macro
"""
text = indexes.CharField(document=True, use_template=True)
product_id = indexes.IntegerField(model_attr='id', null=False)
brand_name = indexes.CharField(model_attr='brand__name', null=True)
def get_model(self):
return models.Product
def index_queryset(self, using=None):
return self.get_model().objects.filter(is_active=True)
curl 'localhost:9200/haystack/_mapping/modelresult/field/brand_name/'
{"haystack":{"mappings":{"modelresult":{"brand_name":{"full_name":"brand_name","mapping":{"brand_name":{"type":"string","boost":1.75,"analyzer":"snowball"}}}}}}
So what am I missing? Is this an AWS only issue? Is this an elasticsearch issue?