sunburnt icon indicating copy to clipboard operation
sunburnt copied to clipboard

Allow boost_relevancy() to use the same queries as query()

Open markbirbeck opened this issue 14 years ago • 0 comments

I have a query like this:

q = query.boost_relevancy(boost1, field1__lte=1000000).\
    boost_relevancy(boost2, field2__lte=10)

However, an exception is thrown saying that the fields don't exist in the schema. This is because the __lte part is not being taken into account.

There is already code in add() for checking field names without the __lte part, and by changing add_boost() to use this code, the exception goes and the query runs correctly:

def add_boost(self, kwargs, boost_score):
    for k, v in kwargs.items():
        try:
            field_name, rel = k.split("__")
        except ValueError:
            field_name, rel = k, 'eq'
        field = self.schema.match_field(field_name)
        if not field:
            if (k, v) != ("*", "*"):
                # the only case where wildcards in field names are allowed
                raise ValueError("%s is not a valid field name" % field_name)
        elif not field.indexed:
            raise SolrError("Can't query on non-indexed field '%s'" % field_name)
        value = field.instance_from_user_data(v)
    self.boosts.append((kwargs, boost_score))

Apologies for not providing a patch/pull request, but I'll try to follow up after next week -- for now I have a serious deadline to meet!

markbirbeck avatar Oct 02 '11 18:10 markbirbeck