algoliasearch 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41cdb9e15fe44adcea0c9c9d2fd06b42284ee323
4
- data.tar.gz: c744385715e62c575ca066f3e01c9ac9d9fffa61
3
+ metadata.gz: 7cc178ecc1fd486b092b7a19e9d04477f393578c
4
+ data.tar.gz: d9bfe9f943ea4734d40cad2db135cfcfa8cde564
5
5
  SHA512:
6
- metadata.gz: 49577f70778667287e47dd77691a247c475fd85448562a65d6bb5d457a31bf0966c82a8e48d67cfe2cb8af465b8a3c4089e928aaab58088f37ca66cf83be766b
7
- data.tar.gz: 934a7181e7815c046c362bf44f38f37a30d1c12a2a729e2555e62f37f17e64c6d453fe9581989d7db5e213c8ff6f9c0b55349e86f775b963a36faec1ed49a81d
6
+ metadata.gz: e22b08a8198b0e92a670bbbc82c932b3ab5aa8270f952948bf4b0fdaa3b52b65b6daf8ca7e43b8d9be64b4817b8ca2978a82d08a2b45baeff185521e784daccf
7
+ data.tar.gz: e256f1cf45cdf56cf84384fedfa28acdaf273a6ab0ba7f8a0314084309b7b77dedc0b4df9be3b3300305099f20708dcae2c0a9f3a2a7f784df41611fa46fe689
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ 2013-11-08 1.1.7
4
+
5
+ * Search params: encode array-based parameters (tagFilters, facetFilters, ...)
6
+
3
7
  2013-11-07 1.1.6
4
8
 
5
9
  * Index: clear and clear! methods can now be used the delete the whole content of an index
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  Algolia Search API Client for Ruby
2
2
  ==================
3
3
 
4
+ [Algolia Search](http://www.algolia.com) is a search API that provides hosted full-text, numerical and faceted search.
5
+ Algolia’s Search API makes it easy to deliver a great search experience in your apps & websites providing:
6
+
7
+ * REST and JSON-based API
8
+ * search among infinite attributes from a single searchbox
9
+ * instant-search after each keystroke
10
+ * relevance & popularity combination
11
+ * typo-tolerance in any language
12
+ * faceting
13
+ * 99.99% SLA
14
+ * first-class data security
15
+
4
16
  This Ruby client let you easily use the Algolia Search API from your backend. It wraps [Algolia's REST API](http://www.algolia.com/doc/rest_api).
5
17
 
6
18
  [![Build Status](https://travis-ci.org/algolia/algoliasearch-client-ruby.png?branch=master)](https://travis-ci.org/algolia/algoliasearch-client-ruby) [![Gem Version](https://badge.fury.io/rb/algoliasearch.png)](http://badge.fury.io/rb/algoliasearch) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-client-ruby.png)](https://codeclimate.com/github/algolia/algoliasearch-client-ruby)
@@ -22,6 +34,7 @@ Table of Content
22
34
  1. [Index settings](#index-settings)
23
35
  1. [List indexes](#list-indexes)
24
36
  1. [Delete an index](#delete-an-index)
37
+ 1. [Clear an index](#clear-an-index)
25
38
  1. [Wait indexing](#wait-indexing)
26
39
  1. [Batch writes](#batch-writes)
27
40
  1. [Security / User API Keys](#security--user-api-keys)
@@ -89,28 +102,34 @@ Search
89
102
  To perform a search, you just need to initialize the index and perform a call to the search function.<br/>
90
103
  You can use the following optional arguments:
91
104
 
92
- * **attributes**: a string that contains the names of attributes to retrieve separated by a comma.<br/>By default all attributes are retrieved.
93
- * **attributesToHighlight**: a string that contains the names of attributes to highlight separated by a comma.<br/>By default indexed attributes are highlighted. Numerical attributes cannot be highlighted. A **matchLevel** is returned for each highlighted attribute and can contain: "full" if all the query terms were found in the attribute, "partial" if only some of the query terms were found, or "none" if none of the query terms were found.
94
- * **attributesToSnippet**: a string that contains the names of attributes to snippet alongside the number of words to return (syntax is 'attributeName:nbWords'). Attributes are separated by a comma (Example: "attributesToSnippet=name:10,content:10").<br/>By default no snippet is computed.
105
+ * **page**: (integer) Pagination parameter used to select the page to retrieve.<br/>Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set `page=9`
106
+ * **hitsPerPage**: (integer) Pagination parameter used to select the number of hits per page. Defaults to 20.
107
+ * **attributesToRetrieve**: a string that contains the list of object attributes you want to retrieve (let you minimize the answer size).<br/> Attributes are separated with a comma (for example `"name,address"`), you can also use a string array encoding (for example `["name","address"]` ). By default, all attributes are retrieved. You can also use `*` to retrieve all values when an **attributesToRetrieve** setting is specified for your index.
108
+ * **attributesToHighlight**: a string that contains the list of attributes you want to highlight according to the query. Attributes are separated by a comma. You can also use a string array encoding (for example `["name","address"]`). If an attribute has no match for the query, the raw value is returned. By default all indexed text attributes are highlighted. You can use `*` if you want to highlight all textual attributes. Numerical attributes are not highlighted. A matchLevel is returned for each highlighted attribute and can contain:
109
+ * **full**: if all the query terms were found in the attribute,
110
+ * **partial**: if only some of the query terms were found,
111
+ * **none**: if none of the query terms were found.
112
+ * **attributesToSnippet**: a string that contains the list of attributes to snippet alongside the number of words to return (syntax is `attributeName:nbWords`). Attributes are separated by a comma (Example: `attributesToSnippet=name:10,content:10`). <br/>You can also use a string array encoding (Example: `attributesToSnippet: ["name:10","content:10"]`). By default no snippet is computed.
95
113
  * **minWordSizefor1Typo**: the minimum number of characters in a query word to accept one typo in this word.<br/>Defaults to 3.
96
114
  * **minWordSizefor2Typos**: the minimum number of characters in a query word to accept two typos in this word.<br/>Defaults to 7.
97
- * **getRankingInfo**: if set to 1, the result hits will contain ranking information in _rankingInfo attribute.
98
- * **page**: *(pagination parameter)* page to retrieve (zero base).<br/>Defaults to 0.
99
- * **hitsPerPage**: *(pagination parameter)* number of hits per page.<br/>Defaults to 10.
115
+ * **getRankingInfo**: if set to 1, the result hits will contain ranking information in **_rankingInfo** attribute.
100
116
  * **aroundLatLng**: search for entries around a given latitude/longitude (specified as two floats separated by a comma).<br/>For example `aroundLatLng=47.316669,5.016670`).<br/>You can specify the maximum distance in meters with the **aroundRadius** parameter (in meters) and the precision for ranking with **aroundPrecision** (for example if you set aroundPrecision=100, two objects that are distant of less than 100m will be considered as identical for "geo" ranking parameter).<br/>At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
101
117
  * **insideBoundingBox**: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng).<br/>For example `insideBoundingBox=47.3165,4.9665,47.3424,5.0201`).<br/>At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
102
- * **queryType**: select how the query words are interpreted:
118
+ * **numericFilters**: a string that contains the list of numeric filters you want to apply separated by a comma. The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
119
+ You can have multiple conditions on one attribute like for example `numericFilters=price>100,price<1000`. You can also use a string array encoding (for example `numericFilters: ["price>100","price<1000"]`).
120
+ * **tagFilters**: filter the query by a set of tags. You can AND tags by separating them by commas. To OR tags, you must add parentheses. For example, `tags=tag1,(tag2,tag3)` means *tag1 AND (tag2 OR tag3)*. You can also use a string array encoding, for example `tagFilters: ["tag1",["tag2","tag3"]]` means *tag1 AND (tag2 OR tag3)*.<br/>At indexing, tags should be added in the **_tags** attribute of objects (for example `{"_tags":["tag1","tag2"]}`).
121
+ * **facetFilters**: filter the query by a list of facets. Facets are separated by commas and each facet is encoded as `attributeName:value`. For example: `facetFilters=category:Book,author:John%20Doe`. You can also use a string array encoding (for example `["category:Book","author:John%20Doe"]`).
122
+ * **facets**: List of object attributes that you want to use for faceting. <br/>Attributes are separated with a comma (for example `"category,author"` ). You can also use a JSON string array encoding (for example `["category","author"]` ). Only attributes that have been added in **attributesForFaceting** index setting can be used in this parameter. You can also use `*` to perform faceting on all attributes specified in **attributesForFaceting**.
123
+ * **queryType**: select how the query words are interpreted, it can be one of the following value:
103
124
  * **prefixAll**: all query words are interpreted as prefixes,
104
125
  * **prefixLast**: only the last word is interpreted as a prefix (default behavior),
105
126
  * **prefixNone**: no query word is interpreted as a prefix. This option is not recommended.
106
- * **numerics**: specify the list of numeric filters you want to apply separated by a comma. The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
107
- You can have multiple conditions on one attribute like for example `numerics=price>100,price<1000`.
108
- * **tags**: filter the query by a set of tags. You can AND tags by separating them by commas. To OR tags, you must add parentheses. For example, `tags=tag1,(tag2,tag3)` means *tag1 AND (tag2 OR tag3)*.<br/>At indexing, tags should be added in the _tags attribute of objects (for example `{"_tags":["tag1","tag2"]}` )
127
+ * **optionalWords**: a string that contains the list of words that should be considered as optional when found in the query. The list of words is comma separated.
109
128
 
110
129
  ```ruby
111
130
  index = Algolia::Index.new("contacts")
112
131
  res = index.search("query string")
113
- res = index.search("query string", { "attributes" => "firstname,lastname", "hitsPerPage" => 20})
132
+ res = index.search("query string", { "attributesToRetrieve" => "firstname,lastname", "hitsPerPage" => 20})
114
133
  ```
115
134
 
116
135
  The server response will look like:
@@ -121,17 +140,6 @@ The server response will look like:
121
140
  {
122
141
  "firstname": "Jimmie",
123
142
  "lastname": "Barninger",
124
- "company": "California Paint & Wlpaper Str",
125
- "address": "Box #-4038",
126
- "city": "Modesto",
127
- "county": "Stanislaus",
128
- "state": "CA",
129
- "zip": "95352",
130
- "phone": "209-525-7568",
131
- "fax": "209-525-4389",
132
- "email": "jimmie@barninger.com",
133
- "web": "http://www.jimmiebarninger.com",
134
- "followers": 3947,
135
143
  "objectID": "433",
136
144
  "_highlightResult": {
137
145
  "firstname": {
@@ -145,18 +153,6 @@ The server response will look like:
145
153
  "company": {
146
154
  "value": "California <em>Paint</em> & Wlpaper Str",
147
155
  "matchLevel": "partial"
148
- },
149
- "address": {
150
- "value": "Box #-4038",
151
- "matchLevel": "none"
152
- },
153
- "city": {
154
- "value": "Modesto",
155
- "matchLevel": "none"
156
- },
157
- "email": {
158
- "value": "<em>jimmie</em>@barninger.com",
159
- "matchLevel": "partial"
160
156
  }
161
157
  }
162
158
  }
@@ -167,7 +163,7 @@ The server response will look like:
167
163
  "hitsPerPage": 20,
168
164
  "processingTimeMS": 1,
169
165
  "query": "jimmie paint",
170
- "params": "query=jimmie+paint&"
166
+ "params": "query=jimmie+paint&attributesToRetrieve=firstname,lastname&hitsPerPage=50"
171
167
  }
172
168
  ```
173
169
 
@@ -253,26 +249,29 @@ You can retrieve all settings using the `getSettings` function. The result will
253
249
  * **minWordSizefor1Typo**: (integer) the minimum number of characters to accept one typo (default = 3).
254
250
  * **minWordSizefor2Typos**: (integer) the minimum number of characters to accept two typos (default = 7).
255
251
  * **hitsPerPage**: (integer) the number of hits per page (default = 10).
256
- * **attributesToRetrieve**: (array of strings) default list of attributes to retrieve in objects.
257
- * **attributesToHighlight**: (array of strings) default list of attributes to highlight.
258
- * **attributesToSnippet**: (array of strings) default list of attributes to snippet alongside the number of words to return (syntax is 'attributeName:nbWords')<br/>By default no snippet is computed.
259
- * **attributesToIndex**: (array of strings) the list of fields you want to index.<br/>By default all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results.<br/>This parameter has two important uses:
260
- * *Limits the attributes to index*.<br/>For example if you store a binary image in base64, you want to store it and be able to retrieve it but you don't want to search in the base64 string.
261
- * *Controls part of the ranking*.<br/>Matches in attributes at the beginning of the list will be considered more important than matches in attributes further down the list. In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable this behavior if you add your attribute inside `unordered(AttributeName)`, for example `attributesToIndex:["title", "unordered(text)"]`.
262
- * **ranking**: (array of strings) controls the way hits are sorted.<br/>We have six available criteria:
252
+ * **attributesToRetrieve**: (array of strings) default list of attributes to retrieve in objects. If set to null, all attributes are retrieved.
253
+ * **attributesToHighlight**: (array of strings) default list of attributes to highlight. If set to null, all indexed attributes are highlighted.
254
+ * **attributesToSnippet**: (array of strings) default list of attributes to snippet alongside the number of words to return (syntax is 'attributeName:nbWords')<br/>By default no snippet is computed. If set to null, no snippet is computed.
255
+ * **attributesToIndex**: (array of strings) the list of fields you want to index.<br/>If set to null, all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results.<br/>This parameter has two important uses:
256
+ * *Limit the attributes to index*.<br/>For example if you store a binary image in base64, you want to store it and be able to retrieve it but you don't want to search in the base64 string.
257
+ * *Control part of the ranking*.<br/>(see the ranking parameter for full explanation) Matches in attributes at the beginning of the list will be considered more important than matches in attributes further down the list. In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable this behavior if you add your attribute inside `unordered(AttributeName)`, for example `attributesToIndex: ["title", "unordered(text)"]`.
258
+ * **attributesForFaceting**: (array of strings) The list of fields you want to use for faceting. All strings in the attribute selected for faceting are extracted and added as a facet. If set to null, no attribute is used for faceting.
259
+ * **ranking**: (array of strings) controls the way results are sorted.<br/>We have six available criteria:
263
260
  * **typo**: sort according to number of typos,
264
- * **geo**: sort according to decreasing distance when performing a geo-location based search,
265
- * **proximity**: sort according to the proximity of query words in hits,
266
- * **attribute**: sort according to the order of attributes defined by **attributesToIndex**,
261
+ * **geo**: sort according to decreassing distance when performing a geo-location based search,
262
+ * **proximity**: sort according to the proximity of query words in hits,
263
+ * **attribute**: sort according to the order of attributes defined by attributesToIndex,
267
264
  * **exact**: sort according to the number of words that are matched identical to query word (and not as a prefix),
268
- * **custom**: sort according to a user defined formula set in **customRanking** attribute.
269
- <br/>The default order is `["typo", "geo", "proximity", "attribute", "exact", "custom"]`. We strongly recommend to keep this configuration.
265
+ * **custom**: sort according to a user defined formula set in **customRanking** attribute.<br/>The standard order is ["typo", "geo", "proximity", "attribute", "exact", "custom"]
270
266
  * **customRanking**: (array of strings) lets you specify part of the ranking.<br/>The syntax of this condition is an array of strings containing attributes prefixed by asc (ascending order) or desc (descending order) operator.
271
- For example `"customRanking" => ["desc(population)", "asc(name)"]`
272
- * **queryType**: select how the query words are interpreted:
267
+ For example `"customRanking" => ["desc(population)", "asc(name)"]`
268
+ * **queryType**: Select how the query words are interpreted, it can be one of the following value:
273
269
  * **prefixAll**: all query words are interpreted as prefixes,
274
270
  * **prefixLast**: only the last word is interpreted as a prefix (default behavior),
275
271
  * **prefixNone**: no query word is interpreted as a prefix. This option is not recommended.
272
+ * **highlightPreTag**: (string) Specify the string that is inserted before the highlighted parts in the query result (default to "&lt;em&gt;").
273
+ * **highlightPostTag**: (string) Specify the string that is inserted after the highlighted parts in the query result (default to "&lt;/em&gt;").
274
+ * **optionalWords**: (array of strings) Specify a list of words that should be considered as optional when found in the query.
276
275
 
277
276
  You can easily retrieve settings or update them:
278
277
 
@@ -302,6 +301,15 @@ index = Algolia::Index.new("contacts")
302
301
  index.delete
303
302
  ```
304
303
 
304
+ Clear an index
305
+ -------------
306
+
307
+ You can delete the index content without removing settings and index specific API keys with the clearIndex command:
308
+
309
+ ```ruby
310
+ index.clear
311
+ ```
312
+
305
313
  Wait indexing
306
314
  -------------
307
315
 
@@ -373,13 +381,18 @@ puts res['key']
373
381
  res = index.add_user_key(["search"])
374
382
  puts res['key']
375
383
  ```
376
- You can also create a temporary API key that will be valid only for a specific period of time (in seconds):
384
+ You can also create an API Key with advanced restrictions:
385
+
386
+ * Add a validity period: the key will be valid only for a specific period of time (in seconds),
387
+ * Specify the maximum number of API calls allowed from an IP address per hour. Each time an API call is performed with this key, a check is performed. If the IP at the origin of the call did more than this number of calls in the last hour, a 403 code is returned. Defaults to 0 (no rate limit). This parameter can be used to protect you from attempts at retrieving your entire content by massively querying the index.
388
+ * Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited). This parameter can be used to protect you from attempts at retrieving your entire content by massively querying the index.
389
+
377
390
  ```ruby
378
391
  # Creates a new global API key that is valid for 300 seconds
379
392
  res = Algolia.add_user_key(["search"], 300)
380
393
  puts res['key']
381
- # Creates a new index specific API key valid for 300 seconds
382
- res = index.add_user_key(["search"], 300)
394
+ # Creates a new index specific API key valid for 300 seconds, with a rate limit of 100 calls per hour per IP and a maximum of 20 hits
395
+ res = index.add_user_key(["search"], 300, 100, 20)
383
396
  puts res['key']
384
397
  ```
385
398
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "algoliasearch"
8
- s.version = "1.1.6"
8
+ s.version = "1.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Algolia"]
12
- s.date = "2013-11-07"
12
+ s.date = "2013-11-08"
13
13
  s.description = "A simple Ruby client for the algolia.com REST API"
14
14
  s.email = "contact@algolia.com"
15
15
  s.extra_rdoc_files = [
@@ -77,43 +77,61 @@ module Algolia
77
77
  #
78
78
  # @param query the full text query
79
79
  # @param args (optional) if set, contains an associative array with query parameters:
80
- # - attributes: a string that contains attribute names to retrieve separated by a comma.
81
- # By default all attributes are retrieved.
82
- # - numerics: specify the list of numeric filters you want to apply separated by a comma.
83
- # The syntax of one filter is `attributeName` followed by `operand` followed by `value`.
84
- # Supported operands are `<`, `<=`, `=`, `>` and `>=`.
85
- # You can have multiple conditions on one attribute like for example `numerics=price>100,price<1000`.
86
- # - attributesToHighlight: a string that contains attribute names to highlight separated by a comma.
87
- # By default indexed attributes are highlighted.
88
- # - attributesToSnippet: a string that contains the names of attributes to snippet alongside the number
89
- # of words to return (syntax is 'attributeName:nbWords').
90
- # Attributes are separated by a comma (Example: "attributesToSnippet=name:10,content:10").
91
- # By default no snippet is computed.
92
- # - minWordSizefor1Typo: the minimum number of characters in a query word to accept one typo in this word.
93
- # Defaults to 3.
94
- # - minWordSizefor2Typos: the minimum number of characters in a query word to accept two typos in this word.
95
- # Defaults to 7.
96
- # - getRankingInfo: if set to 1, the result hits will contain ranking information in
97
- # _rankingInfo attribute
98
- # - page: (pagination parameter) page to retrieve (zero base). Defaults to 0.
99
- # - hitsPerPage: (pagination parameter) number of hits per page. Defaults to 10.
100
- # - aroundLatLng let you search for entries around a given latitude/longitude (two float separated
101
- # by a ',' for example aroundLatLng=47.316669,5.016670).
102
- # You can specify the maximum distance in meters with aroundRadius parameter (in meters).
103
- # At indexing, geoloc of an object should be set with _geoloc attribute containing lat and lng attributes (for example {"_geoloc":{"lat":48.853409, "lng":2.348800}})
104
- # - insideBoundingBox let you search entries inside a given area defined by the two extreme points of
105
- # a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat, p2Lng.
106
- # For example insideBoundingBox=47.3165,4.9665,47.3424,5.0201).
107
- # At indexing, geoloc of an object should be set with _geoloc attribute containing lat and lng attributes (for example {"_geoloc":{"lat":48.853409, "lng":2.348800}})
108
- # - queryType: select how the query words are interpreted:
109
- # - prefixAll: all query words are interpreted as prefixes,
110
- # - prefixLast: only the last word is interpreted as a prefix (default behavior),
111
- # - prefixNone: no query word is interpreted as a prefix. This option is not recommended.
112
- # - tags filter the query by a set of tags. You can AND tags by separating them by commas. To OR tags, you must add parentheses. For example, tags=tag1,(tag2,tag3) means tag1 AND (tag2 OR tag3).
113
- # At indexing, tags should be added in the _tags attribute of objects (for example {"_tags":["tag1","tag2"]} )
114
- #
80
+ # - page: (integer) Pagination parameter used to select the page to retrieve.
81
+ # Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9
82
+ # - hitsPerPage: (integer) Pagination parameter used to select the number of hits per page. Defaults to 20.
83
+ # - attributesToRetrieve: a string that contains the list of object attributes you want to retrieve (let you minimize the answer size).
84
+ # Attributes are separated with a comma (for example "name,address").
85
+ # You can also use a string array encoding (for example ["name","address"]).
86
+ # By default, all attributes are retrieved. You can also use '*' to retrieve all values when an attributesToRetrieve setting is specified for your index.
87
+ # - attributesToHighlight: a string that contains the list of attributes you want to highlight according to the query.
88
+ # Attributes are separated by a comma. You can also use a string array encoding (for example ["name","address"]).
89
+ # If an attribute has no match for the query, the raw value is returned. By default all indexed text attributes are highlighted.
90
+ # You can use `*` if you want to highlight all textual attributes. Numerical attributes are not highlighted.
91
+ # A matchLevel is returned for each highlighted attribute and can contain:
92
+ # - full: if all the query terms were found in the attribute,
93
+ # - partial: if only some of the query terms were found,
94
+ # - none: if none of the query terms were found.
95
+ # - attributesToSnippet: a string that contains the list of attributes to snippet alongside the number of words to return (syntax is `attributeName:nbWords`).
96
+ # Attributes are separated by a comma (Example: attributesToSnippet=name:10,content:10).
97
+ # You can also use a string array encoding (Example: attributesToSnippet: ["name:10","content:10"]). By default no snippet is computed.
98
+ # - minWordSizefor1Typo: the minimum number of characters in a query word to accept one typo in this word. Defaults to 3.
99
+ # - minWordSizefor2Typos: the minimum number of characters in a query word to accept two typos in this word. Defaults to 7.
100
+ # - getRankingInfo: if set to 1, the result hits will contain ranking information in _rankingInfo attribute.
101
+ # - aroundLatLng: search for entries around a given latitude/longitude (specified as two floats separated by a comma).
102
+ # For example aroundLatLng=47.316669,5.016670).
103
+ # You can specify the maximum distance in meters with the aroundRadius parameter (in meters) and the precision for ranking with aroundPrecision
104
+ # (for example if you set aroundPrecision=100, two objects that are distant of less than 100m will be considered as identical for "geo" ranking parameter).
105
+ # At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}})
106
+ # - insideBoundingBox: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng).
107
+ # For example insideBoundingBox=47.3165,4.9665,47.3424,5.0201).
108
+ # At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}})
109
+ # - numericFilters: a string that contains the list of numeric filters you want to apply separated by a comma.
110
+ # The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
111
+ # You can have multiple conditions on one attribute like for example numericFilters=price>100,price<1000.
112
+ # You can also use a string array encoding (for example numericFilters: ["price>100","price<1000"]).
113
+ # - tagFilters: filter the query by a set of tags. You can AND tags by separating them by commas.
114
+ # To OR tags, you must add parentheses. For example, tags=tag1,(tag2,tag3) means tag1 AND (tag2 OR tag3).
115
+ # You can also use a string array encoding, for example tagFilters: ["tag1",["tag2","tag3"]] means tag1 AND (tag2 OR tag3).
116
+ # At indexing, tags should be added in the _tags** attribute of objects (for example {"_tags":["tag1","tag2"]}).
117
+ # - facetFilters: filter the query by a list of facets.
118
+ # Facets are separated by commas and each facet is encoded as `attributeName:value`.
119
+ # For example: `facetFilters=category:Book,author:John%20Doe`.
120
+ # You can also use a string array encoding (for example `["category:Book","author:John%20Doe"]`).
121
+ # - facets: List of object attributes that you want to use for faceting.
122
+ # Attributes are separated with a comma (for example `"category,author"` ).
123
+ # You can also use a JSON string array encoding (for example ["category","author"]).
124
+ # Only attributes that have been added in **attributesForFaceting** index setting can be used in this parameter.
125
+ # You can also use `*` to perform faceting on all attributes specified in **attributesForFaceting**.
126
+ # - queryType: select how the query words are interpreted, it can be one of the following value:
127
+ # - prefixAll: all query words are interpreted as prefixes,
128
+ # - prefixLast: only the last word is interpreted as a prefix (default behavior),
129
+ # - prefixNone: no query word is interpreted as a prefix. This option is not recommended.
130
+ # - optionalWords: a string that contains the list of words that should be considered as optional when found in the query.
131
+ # The list of words is comma separated. #
115
132
  def search(query, params = {})
116
- Algolia.client.get(Protocol.search_uri(name, query, params))
133
+ encoded_params = Hash[params.map { |k,v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
134
+ Algolia.client.get(Protocol.search_uri(name, query, encoded_params))
117
135
  end
118
136
 
119
137
  #
@@ -253,42 +271,45 @@ module Algolia
253
271
  # Set settings for this index
254
272
  #
255
273
  # @param settigns the settings object that can contains :
256
- # - minWordSizefor1Typo (integer) the minimum number of characters to accept one typo (default = 3)
257
- # - minWordSizefor2Typos: (integer) the minimum number of characters to accept two typos (default = 7)
258
- # - hitsPerPage: (integer) the number of hits per page (default = 10)
259
- # - attributesToRetrieve: (array of strings) default list of attributes to retrieve for objects
260
- # - attributesToHighlight: (array of strings) default list of attributes to highlight
261
- # - attributesToSnippet: (array of strings) default list of attributes to snippet alongside the number
262
- # of words to return (syntax is 'attributeName:nbWords').
263
- # By default no snippet is computed.
264
- # - attributesToIndex: (array of strings) the list of fields you want to index.
265
- # By default all textual and numerical attributes of your objects are indexed, but you should update it to get optimal
266
- # results. This parameter has two important uses:
267
- # - Limit the attributes to index.
268
- # For example if you store a binary image in base64, you want to store it in the index but you
269
- # don't want to use the base64 string for search.
270
- # - Control part of the ranking (see the ranking parameter for full explanation).
271
- # Matches in attributes at the beginning of the list will be considered more important than matches
272
- # in attributes further down the list.
273
- # In one attribute, matching text at the beginning of the attribute will be considered more important than text after,
274
- # you can disable this behavior if you add your attribute inside `unordered(AttributeName)`,
275
- # for example `attributesToIndex:["title", "unordered(text)"]`.
276
- # - ranking: (array of strings) controls the way results are sorted.
277
- # We have four available criteria:
278
- # - typo (sort according to number of typos),
279
- # - geo: (sort according to decreassing distance when performing a geo-location based search),
280
- # - proximity: sort according to the proximity of query words in hits,
281
- # - attribute: sort according to the order of attributes defined by **attributesToIndex**,
282
- # - exact: sort according to the number of words that are matched identical to query word (and not as a prefix),
283
- # - custom which is user defined
284
- # (the standard order is ["typo", "geo", "proximity", "attribute", "exact", "custom"])
285
- # - queryType: select how the query words are interpreted:
286
- # - prefixAll: all query words are interpreted as prefixes,
287
- # - prefixLast: only the last word is interpreted as a prefix (default behavior),
288
- # - prefixNone: no query word is interpreted as a prefix. This option is not recommended.
289
- # - customRanking: (array of strings) lets you specify part of the ranking.
290
- # The syntax of this condition is an array of strings containing attributes prefixed
291
- # by asc (ascending order) or desc (descending order) operator.
274
+ # - minWordSizefor1Typo: (integer) the minimum number of characters to accept one typo (default = 3).
275
+ # - minWordSizefor2Typos: (integer) the minimum number of characters to accept two typos (default = 7).
276
+ # - hitsPerPage: (integer) the number of hits per page (default = 10).
277
+ # - attributesToRetrieve: (array of strings) default list of attributes to retrieve in objects.
278
+ # If set to null, all attributes are retrieved.
279
+ # - attributesToHighlight: (array of strings) default list of attributes to highlight.
280
+ # If set to null, all indexed attributes are highlighted.
281
+ # - attributesToSnippet**: (array of strings) default list of attributes to snippet alongside the number of words to return (syntax is attributeName:nbWords).
282
+ # By default no snippet is computed. If set to null, no snippet is computed.
283
+ # - attributesToIndex: (array of strings) the list of fields you want to index.
284
+ # If set to null, all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results.
285
+ # This parameter has two important uses:
286
+ # - Limit the attributes to index: For example if you store a binary image in base64, you want to store it and be able to
287
+ # retrieve it but you don't want to search in the base64 string.
288
+ # - Control part of the ranking*: (see the ranking parameter for full explanation) Matches in attributes at the beginning of
289
+ # the list will be considered more important than matches in attributes further down the list.
290
+ # In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable
291
+ # this behavior if you add your attribute inside `unordered(AttributeName)`, for example attributesToIndex: ["title", "unordered(text)"].
292
+ # - attributesForFaceting: (array of strings) The list of fields you want to use for faceting.
293
+ # All strings in the attribute selected for faceting are extracted and added as a facet. If set to null, no attribute is used for faceting.
294
+ # - ranking: (array of strings) controls the way results are sorted.
295
+ # We have six available criteria:
296
+ # - typo: sort according to number of typos,
297
+ # - geo: sort according to decreassing distance when performing a geo-location based search,
298
+ # - proximity: sort according to the proximity of query words in hits,
299
+ # - attribute: sort according to the order of attributes defined by attributesToIndex,
300
+ # - exact: sort according to the number of words that are matched identical to query word (and not as a prefix),
301
+ # - custom: sort according to a user defined formula set in **customRanking** attribute.
302
+ # The standard order is ["typo", "geo", "proximity", "attribute", "exact", "custom"]
303
+ # - customRanking: (array of strings) lets you specify part of the ranking.
304
+ # The syntax of this condition is an array of strings containing attributes prefixed by asc (ascending order) or desc (descending order) operator.
305
+ # For example `"customRanking" => ["desc(population)", "asc(name)"]`
306
+ # - queryType: Select how the query words are interpreted, it can be one of the following value:
307
+ # - prefixAll: all query words are interpreted as prefixes,
308
+ # - prefixLast: only the last word is interpreted as a prefix (default behavior),
309
+ # - prefixNone: no query word is interpreted as a prefix. This option is not recommended.
310
+ # - highlightPreTag: (string) Specify the string that is inserted before the highlighted parts in the query result (default to "<em>").
311
+ # - highlightPostTag: (string) Specify the string that is inserted after the highlighted parts in the query result (default to "</em>").
312
+ # - optionalWords: (array of strings) Specify a list of words that should be considered as optional when found in the query.
292
313
  #
293
314
  def set_settings(new_settings)
294
315
  Algolia.client.put(Protocol.settings_uri(name), new_settings.to_json)
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.1.6"
2
+ VERSION = "1.1.7"
3
3
  end
@@ -1,8 +1,15 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
+ # avoid concurrent access to the same index
4
+ def safe_index_name(name)
5
+ return name if ENV['TRAVIS'].to_s != "true"
6
+ id = ENV['TRAVIS_JOB_NUMBER'].split('.').last
7
+ "#{name}_travis-#{id}"
8
+ end
9
+
3
10
  describe 'Client' do
4
11
  before(:all) do
5
- @index = Algolia::Index.new("friends")
12
+ @index = Algolia::Index.new(safe_index_name("friends"))
6
13
  @index.delete rescue "not fatal"
7
14
  end
8
15
 
@@ -45,4 +52,41 @@ describe 'Client' do
45
52
  @index.search("")["hits"].length.should eq(0)
46
53
  end
47
54
 
55
+ it "should allow an array of tags" do
56
+ @index.add_object!({ :name => "P1", :_tags => "t1" })
57
+ @index.add_object!({ :name => "P2", :_tags => "t1" })
58
+ @index.add_object!({ :name => "P3", :_tags => "t2" })
59
+ @index.add_object!({ :name => "P4", :_tags => "t3" })
60
+ @index.add_object!({ :name => "P5", :_tags => ["t3", "t4"] })
61
+
62
+ @index.search("", { tagFilters: ["t1"] })['hits'].length.should eq(2) # t1
63
+ @index.search("", { tagFilters: ["t1", "t2"] })['hits'].length.should eq(0) # t1 AND t2
64
+ @index.search("", { tagFilters: ["t3", "t4"] })['hits'].length.should eq(1) # t3 AND t4
65
+ @index.search("", { tagFilters: [["t1", "t2"]] })['hits'].length.should eq(3) # t1 OR t2
66
+ end
67
+
68
+ it "should be facetable" do
69
+ @index.clear!
70
+ @index.set_settings( { attributesForFacetting: ["f", "g"] })
71
+ @index.add_object!({ :name => "P1", :f => "f1", :g => "g1" })
72
+ @index.add_object!({ :name => "P2", :f => "f1", :g => "g2" })
73
+ @index.add_object!({ :name => "P3", :f => "f2", :g => "g2" })
74
+ @index.add_object!({ :name => "P4", :f => "f3", :g => "g2" })
75
+
76
+ res = @index.search("", { facets: "f" })
77
+ res['facets']['f']['f1'].should eq(2)
78
+ res['facets']['f']['f2'].should eq(1)
79
+ res['facets']['f']['f3'].should eq(1)
80
+
81
+ res = @index.search("", { facets: "f", facetFilters: ["f:f1"] })
82
+ res['facets']['f']['f1'].should eq(2)
83
+ res['facets']['f']['f2'].should be_nil
84
+ res['facets']['f']['f3'].should be_nil
85
+
86
+ res = @index.search("", { facets: "f", facetFilters: ["f:f1", "g:g2"] })
87
+ res['facets']['f']['f1'].should eq(1)
88
+ res['facets']['f']['f2'].should be_nil
89
+ res['facets']['f']['f3'].should be_nil
90
+ end
91
+
48
92
  end
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.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb