searchjoy 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +10 -0
- data/LICENSE.txt +1 -1
- data/README.md +22 -23
- data/app/models/searchjoy/search.rb +4 -9
- data/lib/generators/searchjoy/templates/{install.rb → install.rb.tt} +1 -1
- data/lib/searchjoy.rb +10 -12
- data/lib/searchjoy/engine.rb +4 -0
- data/lib/searchjoy/track.rb +41 -17
- data/lib/searchjoy/version.rb +1 -1
- metadata +38 -21
- data/.gitattributes +0 -1
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/searchjoy.gemspec +0 -28
- data/test/searchjoy_test.rb +0 -15
- data/test/test_helper.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64e99ae7ad3156c550ad14bd0c6b8bea1771749a10136329dae8bf6493612125
|
4
|
+
data.tar.gz: c8270664778714b46af93a4914c43539f69b73704d32e74f37bbbcc93352fca3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0528355d4e0ae8259a06ef1f669c250dda444202f10de264594f1c338742a7400b95c0e60dd0d8458df114a560cc10139c405543840cf093cee155606706e437'
|
7
|
+
data.tar.gz: deed698f626106cba1e4dff53983b978c01176b5e42c9a80a7cdc49a399282983b94e52ab826b9533603799c6af75d0866b16ed5c039ac27098904b8e2f04915
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Works with any search platform, including Elasticsearch, Sphinx, and Solr
|
|
12
12
|
|
13
13
|
:cupid: An amazing companion to [Searchkick](https://github.com/ankane/searchkick)
|
14
14
|
|
15
|
-
##
|
15
|
+
## Installation
|
16
16
|
|
17
17
|
Add this line to your application’s Gemfile:
|
18
18
|
|
@@ -35,7 +35,7 @@ mount Searchjoy::Engine, at: "searchjoy"
|
|
35
35
|
|
36
36
|
Be sure to protect the endpoint in production - see the [Authentication](#authentication) section for ways to do this.
|
37
37
|
|
38
|
-
|
38
|
+
## Track Searches
|
39
39
|
|
40
40
|
Track searches by creating a record in the database.
|
41
41
|
|
@@ -51,22 +51,27 @@ Searchjoy::Search.create(
|
|
51
51
|
With [Searchkick](https://github.com/ankane/searchkick), you can use the `track` option to do this automatically.
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
Item.search
|
54
|
+
Item.search("apple", track: {user_id: 1})
|
55
55
|
```
|
56
56
|
|
57
57
|
If you want to track more attributes, add them to the `searchjoy_searches` table. Then, pass the values to the `track` option.
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
Item.search
|
60
|
+
Item.search("apple", track: {user_id: 1, source: "web"})
|
61
61
|
```
|
62
62
|
|
63
63
|
It’s that easy.
|
64
64
|
|
65
|
-
|
65
|
+
## Track Conversions
|
66
66
|
|
67
67
|
First, choose a conversion metric. At Instacart, an item added to the cart from the search results page counts as a conversion.
|
68
68
|
|
69
|
-
Next, when a user searches, keep track of the search id. With Searchkick, you can get the id with
|
69
|
+
Next, when a user searches, keep track of the search id. With Searchkick, you can get the id with:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
results = Item.search("apple", track: true)
|
73
|
+
results.search.id
|
74
|
+
```
|
70
75
|
|
71
76
|
When a user converts, find the record and call `convert`.
|
72
77
|
|
@@ -78,15 +83,14 @@ search.convert
|
|
78
83
|
Better yet, record the model that converted.
|
79
84
|
|
80
85
|
```ruby
|
81
|
-
item = Item.find(params[:item_id])
|
82
86
|
search.convert(item)
|
83
87
|
```
|
84
88
|
|
85
|
-
|
89
|
+
## Authentication
|
86
90
|
|
87
91
|
Don’t forget to protect the dashboard in production.
|
88
92
|
|
89
|
-
|
93
|
+
### Devise
|
90
94
|
|
91
95
|
In your `config/routes.rb`:
|
92
96
|
|
@@ -96,7 +100,7 @@ authenticate :user, ->(user) { user.admin? } do
|
|
96
100
|
end
|
97
101
|
```
|
98
102
|
|
99
|
-
|
103
|
+
### Basic Authentication
|
100
104
|
|
101
105
|
Set the following variables in your environment or an initializer.
|
102
106
|
|
@@ -105,45 +109,40 @@ ENV["SEARCHJOY_USERNAME"] = "andrew"
|
|
105
109
|
ENV["SEARCHJOY_PASSWORD"] = "secret"
|
106
110
|
```
|
107
111
|
|
108
|
-
|
112
|
+
## Customize
|
109
113
|
|
110
|
-
To
|
114
|
+
To customize, create an initializer `config/initializers/searchjoy.rb`.
|
115
|
+
|
116
|
+
Change the time zone
|
111
117
|
|
112
118
|
```ruby
|
113
119
|
Searchjoy.time_zone = "Pacific Time (US & Canada)" # defaults to Time.zone
|
114
120
|
```
|
115
121
|
|
116
|
-
Change the number of top searches shown
|
122
|
+
Change the number of top searches shown
|
117
123
|
|
118
124
|
```ruby
|
119
125
|
Searchjoy.top_searches = 500 # defaults to 100
|
120
126
|
```
|
121
127
|
|
122
|
-
Link to the search results
|
128
|
+
Link to the search results
|
123
129
|
|
124
130
|
```ruby
|
125
131
|
Searchjoy.query_url = ->(search) { Rails.application.routes.url_helpers.items_path(q: search.query) }
|
126
132
|
```
|
127
133
|
|
128
|
-
Add additional info to the query in the live stream
|
134
|
+
Add additional info to the query in the live stream
|
129
135
|
|
130
136
|
```ruby
|
131
137
|
Searchjoy.query_name = ->(search) { "#{search.query} #{search.city}" }
|
132
138
|
```
|
133
139
|
|
134
|
-
Show the conversion name in the live stream
|
140
|
+
Show the conversion name in the live stream
|
135
141
|
|
136
142
|
```ruby
|
137
143
|
Searchjoy.conversion_name = ->(model) { model.name }
|
138
144
|
```
|
139
145
|
|
140
|
-
## TODO
|
141
|
-
|
142
|
-
- customize views
|
143
|
-
- analytics for individual queries
|
144
|
-
- group similar queries
|
145
|
-
- track pagination, facets, sorting, etc
|
146
|
-
|
147
146
|
## Contributing
|
148
147
|
|
149
148
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
@@ -1,15 +1,10 @@
|
|
1
1
|
module Searchjoy
|
2
2
|
class Search < ActiveRecord::Base
|
3
|
-
|
4
|
-
belongs_to :convertable, polymorphic: true, optional: true
|
5
|
-
else
|
6
|
-
belongs_to :convertable, polymorphic: true
|
7
|
-
end
|
3
|
+
self.table_name = "searchjoy_searches"
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
5
|
+
options = ActiveRecord::VERSION::MAJOR == 5 ? {optional: true} : {}
|
6
|
+
belongs_to :convertable, polymorphic: true, **options
|
7
|
+
belongs_to :user, **options
|
13
8
|
|
14
9
|
before_save :set_normalized_query
|
15
10
|
|
@@ -7,7 +7,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
|
|
7
7
|
t.string :normalized_query
|
8
8
|
t.integer :results_count
|
9
9
|
t.timestamp :created_at
|
10
|
-
t.references :convertable, polymorphic: true
|
10
|
+
t.references :convertable, polymorphic: true, index: {name: "index_searchjoy_searches_on_convertable"}
|
11
11
|
t.timestamp :converted_at
|
12
12
|
end
|
13
13
|
|
data/lib/searchjoy.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require "
|
1
|
+
require "active_support/core_ext/module/attribute_accessors"
|
2
2
|
require "chartkick"
|
3
3
|
require "groupdate"
|
4
4
|
|
5
5
|
require "searchjoy/track"
|
6
|
-
require "searchjoy/engine" if defined?(Rails)
|
7
6
|
require "searchjoy/version"
|
8
7
|
|
9
8
|
module Searchjoy
|
@@ -21,17 +20,16 @@ module Searchjoy
|
|
21
20
|
mattr_accessor :conversion_name
|
22
21
|
mattr_accessor :query_name
|
23
22
|
mattr_accessor :query_url
|
24
|
-
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def self.attach_to_searchkick!
|
25
|
+
Searchkick::Query.prepend(Searchjoy::Track::Query)
|
26
|
+
Searchkick::MultiSearch.prepend(Searchjoy::Track::MultiSearch)
|
27
|
+
Searchkick::Results.send(:attr_accessor, :search)
|
28
|
+
end
|
30
29
|
end
|
31
30
|
|
32
|
-
if defined?(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
31
|
+
if defined?(Rails)
|
32
|
+
require "searchjoy/engine"
|
33
|
+
else
|
34
|
+
Searchjoy.attach_to_searchkick! if defined?(Searchkick)
|
37
35
|
end
|
data/lib/searchjoy/engine.rb
CHANGED
data/lib/searchjoy/track.rb
CHANGED
@@ -1,24 +1,48 @@
|
|
1
1
|
module Searchjoy
|
2
2
|
module Track
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
klass.name
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
module Query
|
4
|
+
def track
|
5
|
+
results = @execute
|
6
|
+
|
7
|
+
if options[:track] && !results.search
|
8
|
+
attributes = options[:track] == true ? {} : options[:track]
|
9
|
+
|
10
|
+
search_type =
|
11
|
+
if klass.respond_to?(:name) && klass.name.present?
|
12
|
+
klass.name
|
13
|
+
elsif options[:models]
|
14
|
+
Array(options[:models]).map(&:to_s).sort.join(" ")
|
15
|
+
elsif options[:index_name]
|
16
|
+
Array(options[:index_name]).map(&:to_s).sort.join(" ")
|
17
|
+
else
|
18
|
+
"All Indices"
|
19
|
+
end
|
20
|
+
|
21
|
+
results.search = Searchjoy::Search.create({search_type: search_type, query: term, results_count: results.total_count}.merge(attributes))
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
|
-
|
25
|
+
def execute
|
26
|
+
results = super
|
27
|
+
track
|
28
|
+
results
|
29
|
+
end
|
30
|
+
|
31
|
+
def search
|
32
|
+
@execute.search if @execute
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module MultiSearch
|
37
|
+
def perform
|
38
|
+
result = super
|
39
|
+
|
40
|
+
@queries.each do |query|
|
41
|
+
query.track
|
42
|
+
end
|
43
|
+
|
44
|
+
result
|
45
|
+
end
|
22
46
|
end
|
23
47
|
end
|
24
48
|
end
|
data/lib/searchjoy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchjoy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chartkick
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '5'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +94,43 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: searchkick
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email: andrew@chartkick.com
|
100
127
|
executables: []
|
101
128
|
extensions: []
|
102
129
|
extra_rdoc_files: []
|
103
130
|
files:
|
104
|
-
- ".gitattributes"
|
105
|
-
- ".gitignore"
|
106
131
|
- CHANGELOG.md
|
107
|
-
- Gemfile
|
108
132
|
- LICENSE.txt
|
109
133
|
- README.md
|
110
|
-
- Rakefile
|
111
134
|
- app/controllers/searchjoy/searches_controller.rb
|
112
135
|
- app/models/searchjoy/search.rb
|
113
136
|
- app/views/layouts/searchjoy/application.html.erb
|
@@ -117,14 +140,11 @@ files:
|
|
117
140
|
- app/views/searchjoy/searches/stream.html.erb
|
118
141
|
- config/routes.rb
|
119
142
|
- lib/generators/searchjoy/install_generator.rb
|
120
|
-
- lib/generators/searchjoy/templates/install.rb
|
143
|
+
- lib/generators/searchjoy/templates/install.rb.tt
|
121
144
|
- lib/searchjoy.rb
|
122
145
|
- lib/searchjoy/engine.rb
|
123
146
|
- lib/searchjoy/track.rb
|
124
147
|
- lib/searchjoy/version.rb
|
125
|
-
- searchjoy.gemspec
|
126
|
-
- test/searchjoy_test.rb
|
127
|
-
- test/test_helper.rb
|
128
148
|
homepage: https://github.com/ankane/searchjoy
|
129
149
|
licenses:
|
130
150
|
- MIT
|
@@ -137,18 +157,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
157
|
requirements:
|
138
158
|
- - ">="
|
139
159
|
- !ruby/object:Gem::Version
|
140
|
-
version: '
|
160
|
+
version: '2.4'
|
141
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
162
|
requirements:
|
143
163
|
- - ">="
|
144
164
|
- !ruby/object:Gem::Version
|
145
165
|
version: '0'
|
146
166
|
requirements: []
|
147
|
-
|
148
|
-
rubygems_version: 2.6.13
|
167
|
+
rubygems_version: 3.0.3
|
149
168
|
signing_key:
|
150
169
|
specification_version: 4
|
151
170
|
summary: Search analytics made easy
|
152
|
-
test_files:
|
153
|
-
- test/searchjoy_test.rb
|
154
|
-
- test/test_helper.rb
|
171
|
+
test_files: []
|
data/.gitattributes
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
app/views/* linguist-vendored
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/searchjoy.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "searchjoy/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "searchjoy"
|
8
|
-
spec.version = Searchjoy::VERSION
|
9
|
-
spec.authors = ["Andrew Kane"]
|
10
|
-
spec.email = ["andrew@chartkick.com"]
|
11
|
-
spec.description = "Search analytics made easy"
|
12
|
-
spec.summary = "Search analytics made easy"
|
13
|
-
spec.homepage = "https://github.com/ankane/searchjoy"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "chartkick", ">= 2"
|
22
|
-
spec.add_dependency "groupdate", ">= 3"
|
23
|
-
spec.add_dependency "activerecord", ">= 4"
|
24
|
-
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "minitest"
|
28
|
-
end
|
data/test/searchjoy_test.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class SearchjoyTest < Minitest::Test
|
4
|
-
def test_must_respond_to_top_searches
|
5
|
-
assert_respond_to Searchjoy, :top_searches
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_must_respond_to_conversion_name
|
9
|
-
assert_respond_to Searchjoy, :conversion_name
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_must_respond_to_time_zone
|
13
|
-
assert_respond_to Searchjoy, :time_zone
|
14
|
-
end
|
15
|
-
end
|