algoliasearch 1.14.0 → 1.15.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 +4 -4
- data/ChangeLog +4 -0
- data/Gemfile.lock +3 -3
- data/README.md +106 -60
- data/lib/algolia/index.rb +17 -2
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +1 -1
- data/spec/mock_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4652471c52a7730735419658326bb7202e00a8ef
|
4
|
+
data.tar.gz: bb43fe5aebc4ff687e2fcc51626c08de40c4f3b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 941a2837cb2c6a8da7d88c30829badbeb0a7eb2b7ad0e23ef0dd7349a16af7142c52bd8f01be51ccea9e47bdf01756ec200649717693da222fdf04362737697f
|
7
|
+
data.tar.gz: 710b30782cbf1b835b80b7c8dead3f5e84ac35113aa47ebc2cd4fa16e8dac2eaf68aa73c4fb160b47a984811658ce32e09fa9ec863cd1c59efbd24870b584ad3
|
data/ChangeLog
CHANGED
data/Gemfile.lock
CHANGED
@@ -32,8 +32,8 @@ GEM
|
|
32
32
|
net-http-pipeline
|
33
33
|
highline (1.6.21)
|
34
34
|
httpclient (2.8.3)
|
35
|
-
json (1.8.
|
36
|
-
json (1.8.
|
35
|
+
json (1.8.6)
|
36
|
+
json (1.8.6-java)
|
37
37
|
launchy (2.4.3)
|
38
38
|
addressable (~> 2.3)
|
39
39
|
launchy (2.4.3-java)
|
@@ -325,4 +325,4 @@ DEPENDENCIES
|
|
325
325
|
webmock
|
326
326
|
|
327
327
|
BUNDLED WITH
|
328
|
-
1.
|
328
|
+
1.15.3
|
data/README.md
CHANGED
@@ -26,12 +26,19 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
|
|
26
26
|
1. **[Quick Start](#quick-start)**
|
27
27
|
|
28
28
|
* [Initialize the client](#initialize-the-client)
|
29
|
-
* [Push data](#push-data)
|
30
|
-
* [Search](#search)
|
31
|
-
* [Configure](#configure)
|
32
|
-
* [Frontend search](#frontend-search)
|
33
29
|
|
34
|
-
1. **[
|
30
|
+
1. **[Push data](#push-data)**
|
31
|
+
|
32
|
+
|
33
|
+
1. **[Configure](#configure)**
|
34
|
+
|
35
|
+
|
36
|
+
1. **[Search](#search)**
|
37
|
+
|
38
|
+
|
39
|
+
1. **[Search UI](#search-ui)**
|
40
|
+
|
41
|
+
* [index.html](#indexhtml)
|
35
42
|
|
36
43
|
|
37
44
|
|
@@ -41,6 +48,7 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
|
|
41
48
|
|
42
49
|
|
43
50
|
|
51
|
+
|
44
52
|
## Install
|
45
53
|
|
46
54
|
Install AlgoliaSearch using:
|
@@ -59,95 +67,133 @@ In 30 seconds, this quick start tutorial will show you how to index and search o
|
|
59
67
|
|
60
68
|
### Initialize the client
|
61
69
|
|
62
|
-
|
63
|
-
You can find both
|
70
|
+
To begin, you will need to initialize the client. In order to do this you will need your **Application ID** and **API Key**.
|
71
|
+
You can find both on [your Algolia account](https://www.algolia.com/api-keys).
|
64
72
|
|
65
73
|
```ruby
|
66
74
|
require 'rubygems'
|
67
75
|
require 'algoliasearch'
|
68
76
|
|
69
|
-
Algolia.init :
|
70
|
-
:
|
77
|
+
Algolia.init application_id: 'YourApplicationID',
|
78
|
+
api_key: 'YourAPIKey'
|
71
79
|
```
|
72
80
|
|
73
|
-
|
81
|
+
## Push data
|
74
82
|
|
75
|
-
Without any prior configuration, you can start indexing [500 contacts](https://
|
83
|
+
Without any prior configuration, you can start indexing [500 contacts](https://raw.githubusercontent.com/algolia/datasets-public/master/contacts.json) in the ```contacts``` index using the following code:
|
76
84
|
```ruby
|
77
|
-
index = Algolia::Index.new(
|
78
|
-
batch = JSON.parse(File.read(
|
85
|
+
index = Algolia::Index.new('contacts')
|
86
|
+
batch = JSON.parse(File.read('contacts.json'))
|
79
87
|
index.add_objects(batch)
|
80
88
|
```
|
81
89
|
|
82
|
-
|
90
|
+
## Configure
|
83
91
|
|
84
|
-
|
92
|
+
Settings can be customized to fine tune the search behavior. For example, you can add a custom sort by number of followers to further enhance the built-in relevance:
|
85
93
|
|
86
94
|
```ruby
|
87
|
-
|
88
|
-
puts index.search('jimmie').to_json
|
89
|
-
# search a firstname with typo
|
90
|
-
puts index.search('jimie').to_json
|
91
|
-
# search for a company
|
92
|
-
puts index.search('california paint').to_json
|
93
|
-
# search for a firstname & company
|
94
|
-
puts index.search('jimmie paint').to_json
|
95
|
+
index.set_settings customRanking: ['desc(followers)']
|
95
96
|
```
|
96
97
|
|
97
|
-
|
98
|
+
You can also configure the list of attributes you want to index by order of importance (most important first).
|
98
99
|
|
99
|
-
|
100
|
+
**Note:** The Algolia engine is designed to suggest results as you type, which means you'll generally search by prefix.
|
101
|
+
In this case, the order of attributes is very important to decide which hit is the best:
|
100
102
|
|
101
103
|
```ruby
|
102
|
-
index.set_settings
|
104
|
+
index.set_settings searchableAttributes: %w(
|
105
|
+
lastname
|
106
|
+
firstname
|
107
|
+
company
|
108
|
+
email
|
109
|
+
city
|
110
|
+
address
|
111
|
+
)
|
103
112
|
```
|
104
113
|
|
105
|
-
|
114
|
+
## Search
|
106
115
|
|
107
|
-
|
108
|
-
In this case the order of attributes is very important to decide which hit is the best:
|
116
|
+
You can now search for contacts using `firstname`, `lastname`, `company`, etc. (even with typos):
|
109
117
|
|
110
118
|
```ruby
|
111
|
-
|
112
|
-
|
119
|
+
# search by firstname
|
120
|
+
puts index.search('jimmie').to_json
|
121
|
+
# search a firstname with typo
|
122
|
+
puts index.search('jimie').to_json
|
123
|
+
# search for a company
|
124
|
+
puts index.search('california paint').to_json
|
125
|
+
# search for a firstname & company
|
126
|
+
puts index.search('jimmie paint').to_json
|
113
127
|
```
|
114
128
|
|
115
|
-
|
129
|
+
## Search UI
|
130
|
+
|
131
|
+
**Warning:** If you are building a web application, you may be more interested in using one of our
|
132
|
+
[frontend search UI librairies](https://www.algolia.com/doc/guides/search-ui/search-libraries/)
|
116
133
|
|
117
|
-
|
134
|
+
The following example shows how to build a front-end search quickly using
|
135
|
+
[InstanSearch.js](https://community.algolia.com/instantsearch.js/)
|
118
136
|
|
119
|
-
|
120
|
-
* Your users get a better response time by not going through your servers
|
121
|
-
* It will offload unnecessary tasks from your servers
|
137
|
+
### index.html
|
122
138
|
|
123
139
|
```html
|
124
|
-
|
125
|
-
<
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
+
<!doctype html>
|
141
|
+
<head>
|
142
|
+
<meta charset="UTF-8">
|
143
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.css">
|
144
|
+
</head>
|
145
|
+
<body>
|
146
|
+
<header>
|
147
|
+
<div>
|
148
|
+
<input id="search-input" placeholder="Search for products">
|
149
|
+
<!-- We use a specific placeholder in the input to guides users in their search. -->
|
150
|
+
|
151
|
+
</header>
|
152
|
+
<main>
|
153
|
+
|
154
|
+
|
155
|
+
</main>
|
156
|
+
|
157
|
+
<script type="text/html" id="hit-template">
|
158
|
+
|
159
|
+
<p class="hit-name">{{{_highlightResult.firstname.value}}} {{{_highlightResult.lastname.value}}}</p>
|
160
|
+
|
161
|
+
</script>
|
162
|
+
|
163
|
+
<script src="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>
|
164
|
+
<script src="app.js"></script>
|
165
|
+
</body>
|
166
|
+
```
|
167
|
+
|
168
|
+
### app.js
|
169
|
+
|
170
|
+
```js
|
171
|
+
var search = instantsearch({
|
172
|
+
// Replace with your own values
|
173
|
+
appId: 'YourApplicationID',
|
174
|
+
apiKey: 'YourSearchOnlyAPIKey', // search only API key, no ADMIN key
|
175
|
+
indexName: 'contacts',
|
176
|
+
urlSync: true
|
177
|
+
});
|
178
|
+
|
179
|
+
search.addWidget(
|
180
|
+
instantsearch.widgets.searchBox({
|
181
|
+
container: '#search-input'
|
182
|
+
})
|
140
183
|
);
|
141
184
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
185
|
+
search.addWidget(
|
186
|
+
instantsearch.widgets.hits({
|
187
|
+
container: '#hits',
|
188
|
+
hitsPerPage: 10,
|
189
|
+
templates: {
|
190
|
+
item: document.getElementById('hit-template').innerHTML,
|
191
|
+
empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
|
192
|
+
}
|
193
|
+
})
|
194
|
+
);
|
147
195
|
|
148
|
-
|
149
|
-
}
|
150
|
-
</script>
|
196
|
+
search.start();
|
151
197
|
```
|
152
198
|
|
153
199
|
## Getting Help
|
data/lib/algolia/index.rb
CHANGED
@@ -405,13 +405,28 @@ module Algolia
|
|
405
405
|
params.delete('attributesToRetrieve')
|
406
406
|
|
407
407
|
params[:hitsPerPage] = 1000
|
408
|
+
params[:distinct] = false
|
408
409
|
params[:attributesToRetrieve] = ['objectID']
|
410
|
+
last_task = nil
|
409
411
|
loop do
|
410
412
|
res = search(query, params)
|
411
413
|
break if res['hits'].empty?
|
412
|
-
|
413
|
-
|
414
|
+
last_task = delete_objects(res['hits'].map { |h| h['objectID'] })
|
415
|
+
break if res['hits'].size < 1000
|
414
416
|
end
|
417
|
+
last_task
|
418
|
+
end
|
419
|
+
|
420
|
+
#
|
421
|
+
# Delete all objects matching a query and wait end of indexing
|
422
|
+
#
|
423
|
+
# @param query the query string
|
424
|
+
# @param params the optional query parameters
|
425
|
+
#
|
426
|
+
def delete_by_query!(query, params = nil)
|
427
|
+
res = delete_by_query(query, params)
|
428
|
+
wait_task(res['taskID']) if res
|
429
|
+
res
|
415
430
|
end
|
416
431
|
|
417
432
|
#
|
data/lib/algolia/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -241,7 +241,7 @@ describe 'Client' do
|
|
241
241
|
@index.add_object({:firstname => "Robert1"})
|
242
242
|
@index.add_object!({:firstname => "Robert2"})
|
243
243
|
@index.search('')['nbHits'].should eq(2)
|
244
|
-
@index.delete_by_query('rob')
|
244
|
+
@index.delete_by_query!('rob')
|
245
245
|
@index.search('')['nbHits'].should eq(0)
|
246
246
|
end
|
247
247
|
|
data/spec/mock_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|