Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for conversions boost term #933

Merged
merged 1 commit into from Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -1587,9 +1587,10 @@ end
and during query time:

```ruby
Product.search("banana") # boost by both fields (default)
Product.search("banana") # boost by both fields (default) and term (banana) will be used for both matching and boosting.
Product.search("banana", conversions: "total_conversions") # only boost by total_conversions
Product.search("banana", conversions: false) # no conversion boosting
Product.search("banana", conversions: "total_conversions", conversions_term: "organic banana") # Match banana but boost by organic banana
```

Change timeout
Expand Down
4 changes: 2 additions & 2 deletions lib/searchkick/query.rb
Expand Up @@ -16,7 +16,7 @@ class Query

def initialize(klass, term = "*", **options)
unknown_keywords = options.keys - [:aggs, :body, :body_options, :boost,
:boost_by, :boost_by_distance, :boost_where, :conversions, :debug, :emoji, :exclude, :execute, :explain,
:boost_by, :boost_by_distance, :boost_where, :conversions, :conversions_term, :debug, :emoji, :exclude, :execute, :explain,
:fields, :highlight, :includes, :index_name, :indices_boost, :limit, :load,
:match, :misspellings, :offset, :operator, :order, :padding, :page, :per_page, :profile,
:request_params, :routing, :select, :similar, :smart_aggs, :suggest, :track, :type, :where]
Expand Down Expand Up @@ -381,7 +381,7 @@ def prepare
boost_mode: "replace",
query: {
match: {
"#{conversions_field}.query" => term
"#{conversions_field}.query" => options[:conversions_term] || term
}
}
}.merge(script_score)
Expand Down
12 changes: 12 additions & 0 deletions test/boost_test.rb
Expand Up @@ -28,6 +28,18 @@ def test_multiple_conversions
assert_order "speaker", ["Speaker A", "Speaker B", "Speaker C"], {conversions: "conversions_b"}, Speaker
end

def test_multiple_conversions_with_boost_term
store [
{name: "Speaker A", conversions_a: {"speaker" => 4, "speaker_1" => 1}},
{name: "Speaker B", conversions_a: {"speaker" => 3, "speaker_1" => 2}},
{name: "Speaker C", conversions_a: {"speaker" => 2, "speaker_1" => 3}},
{name: "Speaker D", conversions_a: {"speaker" => 1, "speaker_1" => 4}}
], Speaker

assert_order "speaker", ["Speaker A", "Speaker B", "Speaker C", "Speaker D"], {conversions: "conversions_a"}, Speaker
assert_order "speaker", ["Speaker D", "Speaker C", "Speaker B", "Speaker A"], {conversions: "conversions_a", conversions_term: "speaker_1"}, Speaker
end

def test_conversions_stemmed
store [
{name: "Tomato A", conversions: {"tomato" => 1, "tomatos" => 1, "Tomatoes" => 1}},
Expand Down