retire icon indicating copy to clipboard operation
retire copied to clipboard

Boost hits based on date

Open Linuus opened this issue 11 years ago • 2 comments

Hi!

I'm trying to boost some of my results based on how old they are.

I have a model called Article, which can be either an article or news. This is specified in the field article_type.

Now I want to boost the results which is newer than 2 months AND have article_type: 'news' but I have no luck so far.

Any ideas how I can do that with Tire's DSL?

Linuus avatar Sep 02 '14 12:09 Linuus

For this, you have the custom_score query, see tests for an example.

However, that works only in Elasticsearch 0.90.x -- it has been replaced by much more convenient and powerful function_score. Also, you should definitely use the new Elasticsearch Ruby client and the Rails integration.

karmi avatar Sep 02 '14 13:09 karmi

Thank you for the answer. Yes, I guess a custom_query could do it. As an alternative, would it be possible to create something like this with the Tire DSL:

{
  "query" : {
    "bool" : {
      "must" : {
        query_string: {
          query: "<search term(s)>"
        }
      },
      "should" : [
        {
          "range" : {
            "publishedAt" : {
              "boost" : 5,
              "gte" : "<1 month ago>"
            }
          }
        },
        {
          "range" : {
            "publishedAt" : {
              "boost" : 4,
              "gte" : "<2 months ago>"
            }
          }
        },
        {
          "range" : {
            "publishedAt" : {
              "boost" : 3,
              "gte" : "<3 months ago>"
            }
          }
        }
      ]
    }
  }
}

And yes, I want to migrate to the new gems but I have some issues with them. Mainly it is the lack of multi model searching, which is essential for me. But I already have an issue for that here: https://github.com/elasticsearch/elasticsearch-rails/issues/203

Linuus avatar Sep 02 '14 14:09 Linuus