karmi / tire-contrib

Additions and extensions for the Tire gem
MIT License
65 stars 31 forks source link

Add support to :params for custom_filters_score #19

Closed volmer closed 11 years ago

volmer commented 11 years ago

Just added support to use params with custom_filters_score. Params are often necessary when creating more complex score scripts. For example:

query do
  custom_filters_score do
    query { string 'volmer' }

    params now: Time.now.to_i * 1000

    filter do
      filter 'exists', field: 'created_at'
      script "((0.08 / ((3.16*pow(10,-11)) * abs(now - doc['created_at'].date.getMillis()) + 0.05)))"
    end
  end
end

Thanks to @thor27 and Jon Tai's blog post.

karmi commented 11 years ago

Hi, great.

1/ Can you rewrite the unit test without the tap method? I understand we pull in the ActiveSupport etc, but let's keep unit tests 1.8 friendly.

2/ Can you add a realistic integration test, potentially using your example in the pull request description?

volmer commented 11 years ago

Thanks for the response, @karmi.

Ok, I've removed the tap method from the unit test. Could you please instruct me about where the integration tests for the custom filter score are located? I didn't find them.

karmi commented 11 years ago

Yes, the other queries have just unit tests, I think it's fine to add an example integration test into a separate Should context in the test...

volmer commented 11 years ago

As suggested, I've added a more realistic test (same as the example above) in a separate context.

Veraticus commented 11 years ago

Any chance you can merge this in soon, @karmi? I found myself needing this feature so had to integrate this branch into my project.

karmi commented 11 years ago

Hey, sorry, retouched, merged, pushed!

@volmer I've removed the integration test in the end, since I haven't felt it makes it much clear what's going on :), and added just a simple assert that the param is added to the JSON.

volmer commented 11 years ago

@karmi thanks for merging in!