Commit c5cbe34d1a6a20b95991c0be834420804c1afda3
1 parent
1bcff9d1
Exists in
master
and in
21 other branches
Added training code
Showing
1 changed file
with
33 additions
and
0 deletions
Show diff stats
README.md
... | ... | @@ -42,6 +42,39 @@ Use analytics on search conversions to improve results. |
42 | 42 | |
43 | 43 | Also, give popular documents a little boost. |
44 | 44 | |
45 | +Create a model to keep track of searches. | |
46 | + | |
47 | +```ruby | |
48 | +class Search < ActiveRecord::Base | |
49 | + belongs_to :item | |
50 | + # fields: id, query, searched_at, converted_at, item_id | |
51 | +end | |
52 | +``` | |
53 | + | |
54 | +Add the conversions to the index. | |
55 | + | |
56 | +```ruby | |
57 | +class Book < ActiveRecord::Base | |
58 | + has_many :searches | |
59 | + | |
60 | + def to_indexed_json | |
61 | + { | |
62 | + title: title, | |
63 | + conversions: searches.group("query").count.map{|query, count| {query: query, count: count} }, # TODO fix | |
64 | + _boost: Math.log(copies_sold_count) # boost more popular books a bit | |
65 | + } | |
66 | + end | |
67 | +end | |
68 | +``` | |
69 | + | |
70 | +Tell the query to use conversions once the reindex is complete. | |
71 | + | |
72 | +```ruby | |
73 | +Book.search do | |
74 | + searchkick_query ["title"], "Nobody Listens to Andrew", true | |
75 | +end | |
76 | +``` | |
77 | + | |
45 | 78 | ### Zero Downtime Changes |
46 | 79 | |
47 | 80 | Elasticsearch has a feature called aliases that allows you to change mappings with no downtime. | ... | ... |