Commit c0b0460efa008aed537a248d80f67b5633bbd167
1 parent
714aaded
Exists in
master
and in
21 other branches
Updated readme
Showing
3 changed files
with
14 additions
and
50 deletions
Show diff stats
CHANGELOG.md
README.md
@@ -343,7 +343,7 @@ You can change this with: | @@ -343,7 +343,7 @@ You can change this with: | ||
343 | Product.search "zucini", misspellings: {edit_distance: 2} # zucchini | 343 | Product.search "zucini", misspellings: {edit_distance: 2} # zucchini |
344 | ``` | 344 | ``` |
345 | 345 | ||
346 | -To improve performance for correctly spelled queries (which should be a majority for most applications), Searchkick can first perform a search without misspellings, and if there are too few results, perform another with them. | 346 | +To prevent poor precision and improve performance for correctly spelled queries (which should be a majority for most applications), Searchkick can first perform a search without misspellings, and if there are too few results, perform another with them. |
347 | 347 | ||
348 | ```ruby | 348 | ```ruby |
349 | Product.search "zuchini", misspellings: {below: 5} | 349 | Product.search "zuchini", misspellings: {below: 5} |
@@ -1106,7 +1106,11 @@ rake searchkick:reindex CLASS=Product | @@ -1106,7 +1106,11 @@ rake searchkick:reindex CLASS=Product | ||
1106 | Create an initializer `config/initializers/elasticsearch.rb` with multiple hosts: | 1106 | Create an initializer `config/initializers/elasticsearch.rb` with multiple hosts: |
1107 | 1107 | ||
1108 | ```ruby | 1108 | ```ruby |
1109 | -Searchkick.client = Elasticsearch::Client.new(hosts: ["localhost:9200", "localhost:9201"], retry_on_failure: true) | 1109 | +ENV["ELASTICSEARCH_URL"] = "http://localhost:9200,http://localhost:9201" |
1110 | + | ||
1111 | +Searchkick.client_options = { | ||
1112 | + retry_on_failure: true | ||
1113 | +} | ||
1110 | ``` | 1114 | ``` |
1111 | 1115 | ||
1112 | See [elasticsearch-transport](https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-transport) for a complete list of options. | 1116 | See [elasticsearch-transport](https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-transport) for a complete list of options. |
@@ -1321,13 +1325,13 @@ class Product < ActiveRecord::Base | @@ -1321,13 +1325,13 @@ class Product < ActiveRecord::Base | ||
1321 | end | 1325 | end |
1322 | end | 1326 | end |
1323 | 1327 | ||
1324 | -Product.partial_reindex(:search_prices) | 1328 | +Product.reindex(:search_prices) |
1325 | ``` | 1329 | ``` |
1326 | 1330 | ||
1327 | Remove old indices | 1331 | Remove old indices |
1328 | 1332 | ||
1329 | ```ruby | 1333 | ```ruby |
1330 | -Product.clean_indices | 1334 | +Product.searchkick_index.clean_indices |
1331 | ``` | 1335 | ``` |
1332 | 1336 | ||
1333 | Use custom settings | 1337 | Use custom settings |
@@ -1424,11 +1428,11 @@ class Product < ActiveRecord::Base | @@ -1424,11 +1428,11 @@ class Product < ActiveRecord::Base | ||
1424 | end | 1428 | end |
1425 | ``` | 1429 | ``` |
1426 | 1430 | ||
1427 | -Use [Okapi BM25](https://www.elastic.co/guide/en/elasticsearch/guide/current/pluggable-similarites.html) for ranking | 1431 | +Use a different [similarity algorithm](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-similarity.html) for scoring |
1428 | 1432 | ||
1429 | ```ruby | 1433 | ```ruby |
1430 | class Product < ActiveRecord::Base | 1434 | class Product < ActiveRecord::Base |
1431 | - searchkick similarity: "BM25" | 1435 | + searchkick similarity: "classic" |
1432 | end | 1436 | end |
1433 | ``` | 1437 | ``` |
1434 | 1438 | ||
@@ -1459,14 +1463,6 @@ Add [request parameters](https://www.elastic.co/guide/en/elasticsearch/reference | @@ -1459,14 +1463,6 @@ Add [request parameters](https://www.elastic.co/guide/en/elasticsearch/reference | ||
1459 | Product.search("carrots", request_params: {search_type: "dfs_query_then_fetch"}) | 1463 | Product.search("carrots", request_params: {search_type: "dfs_query_then_fetch"}) |
1460 | ``` | 1464 | ``` |
1461 | 1465 | ||
1462 | -Make fields unsearchable but include in the source | ||
1463 | - | ||
1464 | -```ruby | ||
1465 | -class Product < ActiveRecord::Base | ||
1466 | - searchkick unsearchable: [:color] | ||
1467 | -end | ||
1468 | -``` | ||
1469 | - | ||
1470 | Reindex conditionally | 1466 | Reindex conditionally |
1471 | 1467 | ||
1472 | **Note:** With ActiveRecord, use this feature with caution - [transaction rollbacks can cause data inconsistencies](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md#custom-callbacks) | 1468 | **Note:** With ActiveRecord, use this feature with caution - [transaction rollbacks can cause data inconsistencies](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md#custom-callbacks) |
@@ -1476,7 +1472,7 @@ class Product < ActiveRecord::Base | @@ -1476,7 +1472,7 @@ class Product < ActiveRecord::Base | ||
1476 | searchkick callbacks: false | 1472 | searchkick callbacks: false |
1477 | 1473 | ||
1478 | # add the callbacks manually | 1474 | # add the callbacks manually |
1479 | - after_save :reindex, if: proc{|model| model.name_changed? } # use your own condition | 1475 | + after_save :reindex, if: -> (model) { model.name_changed? } # use your own condition |
1480 | after_destroy :reindex | 1476 | after_destroy :reindex |
1481 | end | 1477 | end |
1482 | ``` | 1478 | ``` |
@@ -1522,44 +1518,13 @@ end | @@ -1522,44 +1518,13 @@ end | ||
1522 | 1518 | ||
1523 | ```ruby | 1519 | ```ruby |
1524 | product = FactoryGirl.create(:product) | 1520 | product = FactoryGirl.create(:product) |
1525 | -product.reindex # don't forget this | ||
1526 | -Product.searchkick_index.refresh # or this | 1521 | +product.reindex(refresh: true) |
1527 | ``` | 1522 | ``` |
1528 | 1523 | ||
1529 | ## Multi-Tenancy | 1524 | ## Multi-Tenancy |
1530 | 1525 | ||
1531 | Check out [this great post](https://www.tiagoamaro.com.br/2014/12/11/multi-tenancy-with-searchkick/) on the [Apartment](https://github.com/influitive/apartment) gem. Follow a similar pattern if you use another gem. | 1526 | Check out [this great post](https://www.tiagoamaro.com.br/2014/12/11/multi-tenancy-with-searchkick/) on the [Apartment](https://github.com/influitive/apartment) gem. Follow a similar pattern if you use another gem. |
1532 | 1527 | ||
1533 | -## Migrating from Tire | ||
1534 | - | ||
1535 | -1. Change `search` methods to `tire.search` and add index name in existing search calls | ||
1536 | - | ||
1537 | - ```ruby | ||
1538 | - Product.search "fruit" | ||
1539 | - ``` | ||
1540 | - | ||
1541 | - should be replaced with | ||
1542 | - | ||
1543 | - ```ruby | ||
1544 | - Product.tire.search "fruit", index: "products" | ||
1545 | - ``` | ||
1546 | - | ||
1547 | -2. Replace tire mapping w/ searchkick method | ||
1548 | - | ||
1549 | - ```ruby | ||
1550 | - class Product < ActiveRecord::Base | ||
1551 | - searchkick | ||
1552 | - end | ||
1553 | - ``` | ||
1554 | - | ||
1555 | -3. Deploy and reindex | ||
1556 | - | ||
1557 | - ```ruby | ||
1558 | - rake searchkick:reindex CLASS=Product # or Product.reindex in the console | ||
1559 | - ``` | ||
1560 | - | ||
1561 | -4. Once it finishes, replace search calls w/ searchkick calls | ||
1562 | - | ||
1563 | ## Upgrading | 1528 | ## Upgrading |
1564 | 1529 | ||
1565 | View the [changelog](https://github.com/ankane/searchkick/blob/master/CHANGELOG.md). | 1530 | View the [changelog](https://github.com/ankane/searchkick/blob/master/CHANGELOG.md). |
lib/searchkick/index.rb
@@ -9,8 +9,8 @@ module Searchkick | @@ -9,8 +9,8 @@ module Searchkick | ||
9 | @options = options | 9 | @options = options |
10 | end | 10 | end |
11 | 11 | ||
12 | - def create(options = {}) | ||
13 | - client.indices.create index: name, body: options | 12 | + def create(body = {}) |
13 | + client.indices.create index: name, body: body | ||
14 | end | 14 | end |
15 | 15 | ||
16 | def delete | 16 | def delete |