Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Boost hits based on date #976

Open
Linuus opened this issue Sep 2, 2014 · 2 comments
Open

Boost hits based on date #976

Linuus opened this issue Sep 2, 2014 · 2 comments

Comments

@Linuus
Copy link

Linuus commented Sep 2, 2014

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?

@karmi
Copy link
Owner

karmi commented Sep 2, 2014

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.

@Linuus
Copy link
Author

Linuus commented Sep 2, 2014

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: elastic/elasticsearch-rails#203

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants