6

I'm with some problems in Django Haystack 1.2.5. I need to boost one field but aparently it is not working. I'm using Solr 1.4.1.

My Index:

class JobsTextIndex(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 have in the job_title "boost=1.50" but this apparently it is not working, this is what is generated by Solr:

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 

The query that I'm doing is this one:

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

Can someone give me a clue on what I need to get Haystack Boost working?

Best Regards,


Update 1: I need to give more importance to the "job_title" field. If for example I'm searching for the word "programmer" I need to show in the first place the results that have "programmer" in the "job_title" field ordered by date and then the results that have the word "programmer" in the "job_description" field. The Haystack boost is the right tool to achieve this?

sehe
  • 374,641
  • 47
  • 450
  • 633
André
  • 24,706
  • 43
  • 121
  • 178
  • I'm having the exact same problem: I want to boost one field, but the boost parameter isn't doing anything. Calling the .boost() method on the queryset only gives very unpredictable results. Did you figure out a solution? – Kevin Renskers Dec 16 '11 at 10:43
  • @mixedCase, I don't have the boost working yet. In my case the only option that I have is to do a raw query using the "dismax" Solr capabilities but I've been out of time to read more about Solr... – André Dec 16 '11 at 22:11

2 Answers2

7

Specifying boost=1.5 in your field definition is how you tell Haystack to use 'Field boost' on that specific field. From the Haystack documentation:

There are three types of boost:

  • Term Boost

  • Document Boost

  • Field Boost

Term boost happens at query time (when the search query is run) and is based around increasing the score is a certain word/phrase is seen.

On the other hand, document & field boosts take place at indexing time (when the document is being added to the index). Document boost causes the relevance of the entire result to go up, where field boost causes only searches within that field to do better.

You've specified field boost in your code, which will boost the field when the model is indexed, not when you make your query. The good news is that the boost you specified will still be used when a search is made on that field, but will be applied implicitly, rather than being specified explicitly in the query to Solr.

I don't think the query you've specified will have the boost applied to it though as you haven't searched on any fields.

Shaun O'Keefe
  • 1,308
  • 1
  • 11
  • 12
  • 1
    thanks for the reply. I have rebuild the index but the search results are the same than before I have added the "boost" parameter in the model. One other thing that I've noticed is that the "schema.xml" have not changed after I've had the "boost" parameter in the model, I've run the command "build_solr_schema" but the "boost" on the model don't have any effect. Someone have more clues about this? Thanks. – André Dec 04 '11 at 12:10
0

I had the same issue -- "schema.xml" have not changed after I've had the "boost" parameter in the model. As a solution I've started using DisMax query mode. Something like this is working for me:

SearchQuerySet().filter(text=Raw("{!dismax qf='field1^3 field2^2 text'}" + query))

I hope this will help someone.

ambi
  • 1,256
  • 11
  • 16
  • Any good resource to read how to achieve this? Or you found a better solution? – phoenixwizard Oct 12 '13 at 16:53
  • I'm not sure what do you mean. I've read [haystack docs](http://django-haystack.readthedocs.org/en/latest/inputtypes.html) and [dismax wiki](http://wiki.apache.org/solr/DisMaxQParserPlugin). I've also changed code a little bit to: `SearchQuerySet().filter(text=AltParser( 'dismax', q, qf='field1^3 field2^2 text', ))` – ambi Oct 15 '13 at 07:48
  • `SearchQuerySet().boost('"%s"' % number, 2.0)` –  Nov 21 '19 at 00:31