toastdriven/django-haystack — Issue #456: Field boost with Solr does not work
Author: lopesandre
Created: 2011-12-05 00:31:03+00:00
State: open

Hi,

I'm using Solr 1.4.1 and Haystack 1.2.5

I'm testing to add boost to one field in the index but it does not have any effect. Here is one index example:

class JobsadsTextIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
job_title = indexes.CharField(model_attr='job_title', boost=1.50)
job_description = indexes.CharField(model_attr='job_description')
country_ad = indexes.CharField(model_attr='country_ad')
zone_ad = indexes.CharField(model_attr='zone_ad', faceted=True)
location_ad = indexes.CharField(model_attr='location_ad', faceted=True)
date_inserted = indexes.DateTimeField(model_attr='date_inserted')

def index_queryset(self):
"""Used when the entire index for model is updated."""
return JobsadsText.objects.filter(date_inserted__lte=datetime.datetime.now())

I've added "boost=1.50" to the field "job_title". When I run "rebuild_solr_schema" I don't see any change in schema. The schema is supposed to have some information about the field to boost?

I also do not see any reference in the request to Solr about boost. It is suppose to see any reference to boost in the Solr request? Solr request:

INFO: [core0] webapp=/solr path=/select/ params={facet=on&sort=date_inserted+desc&fl=*+score&start=0&q=arquiteto&facet.field=location_ad_exact&facet.field=zone_ad_exact&wt=json&fq=django_ct:(myapp.jobstext)&rows=20} hits=65 status=0 QTime=5

I have tested some queries,

It ok to mix order_by() with boost, like in this query:

sqs = SearchQuerySet().facet('zone_ad').facet('location_ad').order_by('-date_inserted')

The query above with field boosting does not make any difference, the search only gets ordered by date.

I have made some other tests, like this one:

class JobsadsTextIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
job_title = indexes.CharField(model_attr='job_title', boost=100)
job_description = indexes.CharField(model_attr='job_description')
country_ad = indexes.CharField(model_attr='country_ad')
zone_ad = indexes.CharField(model_attr='zone_ad', faceted=True)
location_ad = indexes.CharField(model_attr='location_ad', faceted=True)
date_inserted = indexes.DateTimeField(model_attr='date_inserted')

def index_queryset(self):
"""Used when the entire index for model is updated."""
return JobsadsText.objects.filter(date_inserted__lte=datetime.datetime.now())

Using this query:

sqs = SearchQuerySet().facet('zone_ad').facet('location_ad')

I always do a "rebuild_index" when I change something in the Index. No matter the value that I put in the boost(boost=1.50, boost=100) the result is always the same.