def add(self, field, value, minimum_match=1): if not isinstance(value, list): raise InvalidParameterQuery("value %r must be valid list" % value) self._values[field] = value if minimum_match: if isinstance(minimum_match, int): self._values['minimum_match'] = minimum_match else: self._values['minimum_match'] = int(minimum_match)
def serialize(self): if self.score_mode and self.score_mode not in ['avg', "total", "max"]: raise InvalidParameterQuery("Invalid score_mode: %s" % self.score_mode) data = { 'path':self.path, 'score_mode':self.score_mode, 'query':self.query.serialize()} return {self._internal_name:data}
def add(self, field, value, boost=None): if not value.strip(): raise InvalidParameterQuery("value %r must be valid text" % value) match = {'value': value} if boost: if isinstance(boost, (float, int)): match['boost'] = boost else: match['boost'] = float(boost) self._values[field] = match return self._values[field] = value
def serialize(self): filters = {} if self.boost != 1.0: filters["boost"] = self.boost for f in self.filters: filters.update(f.serialize()) if self.score not in ["max", "min", "avg"]: raise InvalidParameterQuery("Invalid value '%s' for score" % self.score) return {self._internal_name:{ 'type':self.type, 'query':filters, 'score':self.score, 'factor':self.factor, "incremental_factor":self.incremental_factor}}