Esempio n. 1
0
 def serialize(self):
     filters = {'language':self.language}
     if self.default_field:
         filters["default_field"] = self.default_field
         if not isinstance(self.default_field, (str, unicode)) and isinstance(self.default_field, list):
             if not self.use_dis_max:
                 filters["use_dis_max"] = self.use_dis_max
             if self.tie_breaker != 0:
                 filters["tie_breaker"] = self.tie_breaker
     if self.search_fields:
         filters['fields'] = self.search_fields
     if self.default_operator != "OR":
         filters["default_operator"] = self.default_operator
     if self.options:
         filters["options"] = self.options
     if self.synonyms:
         filters["synonyms"] = self.synonyms
     if self.stopwords:
         filters["stopwords"] = self.stopwords
     if self.analyzer:
         filters["analyzer"] = self.analyzer
     if self.analyzer:
         filters["analyzer"] = self.analyzer
     if not self.allow_leading_wildcard:
         filters["allow_leading_wildcard"] = self.allow_leading_wildcard
     if not self.lowercase_expanded_terms:
         filters["lowercase_expanded_terms"] = self.lowercase_expanded_terms
     if not self.enable_position_increments:
         filters["enable_position_increments"] = self.enable_position_increments
     if self.fuzzy_prefix_length:
         filters["fuzzy_prefix_length"] = self.fuzzy_prefix_length
     if self.fuzzy_min_sim != 0.5:
         filters["fuzzy_min_sim"] = self.fuzzy_min_sim
     if self.phrase_slop:
         filters["phrase_slop"] = self.phrase_slop
     if self.min_concept_size!=2:
         filters["min_concept_size"] = self.min_concept_size
     if self.max_concept_size!=4:
         filters["max_concept_size"] = self.max_concept_size
     if self.term_expansion_steps!=1:
         filters["term_expansion_steps"] = self.term_expansion_steps
         
     if self.boost!=1.0:
         filters["boost"] = self.boost
     if self.clean_text:
         query = clean_string(self.text)
         if not query:
             raise InvalidQuery("The query is empty")
         filters["query"] = query
     else:
         if not self.text.strip():
             raise InvalidQuery("The query is empty")
         filters["query"] = self.text            
     
     return {self._internal_name:filters}
Esempio n. 2
0
    def serialize(self):
        filters = {}
        if self.default_field:
            filters["default_field"] = self.default_field
            if not isinstance(self.default_field,
                              (str, unicode)) and isinstance(
                                  self.default_field, list):
                if not self.use_dis_max:
                    filters["use_dis_max"] = self.use_dis_max
                if self.tie_breaker != 0:
                    filters["tie_breaker"] = self.tie_breaker

        if self.default_operator != "OR":
            filters["default_operator"] = self.default_operator
        if self.analyzer:
            filters["analyzer"] = self.analyzer
        if not self.allow_leading_wildcard:
            filters["allow_leading_wildcard"] = self.allow_leading_wildcard
        if not self.lowercase_expanded_terms:
            filters["lowercase_expanded_terms"] = self.lowercase_expanded_terms
        if not self.enable_position_increments:
            filters[
                "enable_position_increments"] = self.enable_position_increments
        if self.fuzzy_prefix_length:
            filters["fuzzy_prefix_length"] = self.fuzzy_prefix_length
        if self.fuzzy_min_sim != 0.5:
            filters["fuzzy_min_sim"] = self.fuzzy_min_sim
        if self.phrase_slop:
            filters["phrase_slop"] = self.phrase_slop
        if self.search_fields:
            if isinstance(self.search_fields, (str, unicode)):
                filters["fields"] = [self.search_fields]
            else:
                filters["fields"] = self.search_fields

            if len(filters["fields"]) > 1:
                if not self.use_dis_max:
                    filters["use_dis_max"] = self.use_dis_max
                if self.tie_breaker != 0:
                    filters["tie_breaker"] = self.tie_breaker
        if self.boost != 1.0:
            filters["boost"] = self.boost
        if self.analyze_wildcard:
            filters["analyze_wildcard"] = self.analyze_wildcard
        if self.clean_text:
            query = clean_string(self.query)
            if not query:
                raise InvalidQuery("The query is empty")
            filters["query"] = query
        else:
            if not self.query.strip():
                raise InvalidQuery("The query is empty")
            filters["query"] = self.query
        return {self._internal_name: filters}
Esempio n. 3
0
    def serialize(self):
        filters = {}

        if self.tie_breaker != 0.0:
            filters["tie_breaker"] = self.tie_breaker

        if self.boost != 1.0:
            filters["boost"] = self.boost

        filters["queries"] = [q.serialize() for q in self.queries]
        if not filters["queries"]:
            raise InvalidQuery("A least a query is required")
        return {self._internal_name: filters}