Django Haystack - How To Raise A Field?

I have problems with Django Haystack 1.2.5. I need to enlarge one field, but it does not seem to work. I am 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 job_title "boost = 1.50", but this does not seem to work, this is what Solr generates:

 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 I am making is as follows:

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

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

Best wishes,


Update 1: I need to attach more importance to the "job_title" field. If, for example, I search for the word "programmer," I need to first show the results that have "programmer" in the field "job_title", ordered by date, and then the results that have the word "programmer" in the field job_description. Is Haystack Acceleration the Right Tool to Achieve This?

+6
source share
2 answers

Setting boost=1.5 in your field definition is how you tell Haystack to use "Field boost" in that particular field. From the Haystack documentation:

There are three types of enhancement:

  • Acceleration of the term

  • Document Acceleration

  • Field acceleration

Confirmation of the term occurs during the query (when the search query is executed) and based on the increase in the score, it is a specific word / phrase.

On the other hand, documents and fields are strengthened during indexing (when a document is added to the index). Strengthening the document, the relevance of the whole result should increase when the reasons for increasing the field, only a search in this field will be better.

In the code, you specified an increase in the field, which will increase the field when indexing the model, and not when executing the query. The good news is that the promotion you specified will still be used when the search is done in this field, but will be applied implicitly, and not explicitly specified in the Solr request.

I do not think that the query you specified will be applied to it, although you have not searched in any fields.

+6
source

I had the same problem - "schema.xml" did not change after I had the "boost" parameter in the model. As a solution, I started using DisMax request mode. Something like this works for me:

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

Hope this helps someone.

0
source

Source: https://habr.com/ru/post/902997/


All Articles