Commit 223848df5067cbcc8bad345a33592f29c63af377
1 parent
8aaaee4a
Exists in
master
and in
19 other branches
ActiveRecord::Base -> ApplicationRecord [skip ci]
Showing
1 changed file
with
38 additions
and
38 deletions
Show diff stats
README.md
... | ... | @@ -59,7 +59,7 @@ The latest version works with Elasticsearch 2, 5, and 6. For Elasticsearch 1, us |
59 | 59 | Add searchkick to models you want to search. |
60 | 60 | |
61 | 61 | ```ruby |
62 | -class Product < ActiveRecord::Base | |
62 | +class Product < ApplicationRecord | |
63 | 63 | searchkick |
64 | 64 | end |
65 | 65 | ``` |
... | ... | @@ -238,7 +238,7 @@ Product.search "fresh honey", operator: "or" # fresh OR honey |
238 | 238 | By default, results must match the entire word - `back` will not match `backpack`. You can change this behavior with: |
239 | 239 | |
240 | 240 | ```ruby |
241 | -class Product < ActiveRecord::Base | |
241 | +class Product < ApplicationRecord | |
242 | 242 | searchkick word_start: [:name] |
243 | 243 | end |
244 | 244 | ``` |
... | ... | @@ -282,7 +282,7 @@ User.search "fresh honey", match: :phrase |
282 | 282 | Searchkick defaults to English for stemming. To change this, use: |
283 | 283 | |
284 | 284 | ```ruby |
285 | -class Product < ActiveRecord::Base | |
285 | +class Product < ApplicationRecord | |
286 | 286 | searchkick language: "german" |
287 | 287 | end |
288 | 288 | ``` |
... | ... | @@ -292,7 +292,7 @@ end |
292 | 292 | ### Synonyms |
293 | 293 | |
294 | 294 | ```ruby |
295 | -class Product < ActiveRecord::Base | |
295 | +class Product < ApplicationRecord | |
296 | 296 | searchkick synonyms: [["scallion", "green onion"], ["qtip", "cotton swab"]] |
297 | 297 | end |
298 | 298 | ``` |
... | ... | @@ -316,7 +316,7 @@ synonyms: ["lightbulb => halogenlamp"] |
316 | 316 | The above approach works well when your synonym list is static, but in practice, this is often not the case. When you analyze search conversions, you often want to add new synonyms or tags without a full reindex. You can use a library like [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on) and do: |
317 | 317 | |
318 | 318 | ```ruby |
319 | -class Product < ActiveRecord::Base | |
319 | +class Product < ApplicationRecord | |
320 | 320 | acts_as_taggable |
321 | 321 | scope :search_import, -> { includes(:tags) } |
322 | 322 | |
... | ... | @@ -350,7 +350,7 @@ mv prolog/wn_s.pl /var/lib |
350 | 350 | Tell each model to use it: |
351 | 351 | |
352 | 352 | ```ruby |
353 | -class Product < ActiveRecord::Base | |
353 | +class Product < ApplicationRecord | |
354 | 354 | searchkick wordnet: true |
355 | 355 | end |
356 | 356 | ``` |
... | ... | @@ -419,7 +419,7 @@ Product.search "🍨🍰", emoji: true |
419 | 419 | Control what data is indexed with the `search_data` method. Call `Product.reindex` after changing this method. |
420 | 420 | |
421 | 421 | ```ruby |
422 | -class Product < ActiveRecord::Base | |
422 | +class Product < ApplicationRecord | |
423 | 423 | belongs_to :department |
424 | 424 | |
425 | 425 | def search_data |
... | ... | @@ -435,7 +435,7 @@ end |
435 | 435 | Searchkick uses `find_in_batches` to import documents. To eager load associations, use the `search_import` scope. |
436 | 436 | |
437 | 437 | ```ruby |
438 | -class Product < ActiveRecord::Base | |
438 | +class Product < ApplicationRecord | |
439 | 439 | scope :search_import, -> { includes(:department) } |
440 | 440 | end |
441 | 441 | ``` |
... | ... | @@ -443,7 +443,7 @@ end |
443 | 443 | By default, all records are indexed. To control which records are indexed, use the `should_index?` method together with the `search_import` scope. |
444 | 444 | |
445 | 445 | ```ruby |
446 | -class Product < ActiveRecord::Base | |
446 | +class Product < ApplicationRecord | |
447 | 447 | scope :search_import, -> { where(active: true) } |
448 | 448 | |
449 | 449 | def should_index? |
... | ... | @@ -485,7 +485,7 @@ There are four strategies for keeping the index synced with your database. |
485 | 485 | Use background jobs for better performance |
486 | 486 | |
487 | 487 | ```ruby |
488 | - class Product < ActiveRecord::Base | |
488 | + class Product < ApplicationRecord | |
489 | 489 | searchkick callbacks: :async |
490 | 490 | end |
491 | 491 | ``` |
... | ... | @@ -501,7 +501,7 @@ There are four strategies for keeping the index synced with your database. |
501 | 501 | Turn off automatic syncing |
502 | 502 | |
503 | 503 | ```ruby |
504 | - class Product < ActiveRecord::Base | |
504 | + class Product < ApplicationRecord | |
505 | 505 | searchkick callbacks: false |
506 | 506 | end |
507 | 507 | ``` |
... | ... | @@ -527,7 +527,7 @@ end |
527 | 527 | Data is **not** automatically synced when an association is updated. If this is desired, add a callback to reindex: |
528 | 528 | |
529 | 529 | ```ruby |
530 | -class Image < ActiveRecord::Base | |
530 | +class Image < ApplicationRecord | |
531 | 531 | belongs_to :product |
532 | 532 | |
533 | 533 | after_commit :reindex_product |
... | ... | @@ -566,7 +566,7 @@ You do **not** need to clean up the search queries. Searchkick automatically tre |
566 | 566 | Next, add conversions to the index. |
567 | 567 | |
568 | 568 | ```ruby |
569 | -class Product < ActiveRecord::Base | |
569 | +class Product < ApplicationRecord | |
570 | 570 | has_many :searches, class_name: "Searchjoy::Search", as: :convertable |
571 | 571 | |
572 | 572 | searchkick conversions: ["conversions"] # name of field |
... | ... | @@ -594,7 +594,7 @@ rake searchkick:reindex CLASS=Product |
594 | 594 | Order results differently for each user. For example, show a user’s previously purchased products before other results. |
595 | 595 | |
596 | 596 | ```ruby |
597 | -class Product < ActiveRecord::Base | |
597 | +class Product < ApplicationRecord | |
598 | 598 | def search_data |
599 | 599 | { |
600 | 600 | name: name, |
... | ... | @@ -623,7 +623,7 @@ Autocomplete predicts what a user will type, making the search experience faster |
623 | 623 | First, specify which fields use this feature. This is necessary since autocomplete can increase the index size significantly, but don’t worry - this gives you blazing faster queries. |
624 | 624 | |
625 | 625 | ```ruby |
626 | -class Movie < ActiveRecord::Base | |
626 | +class Movie < ApplicationRecord | |
627 | 627 | searchkick word_start: [:title, :director] |
628 | 628 | end |
629 | 629 | ``` |
... | ... | @@ -683,7 +683,7 @@ Then add the search box and JavaScript code to a view. |
683 | 683 |  |
684 | 684 | |
685 | 685 | ```ruby |
686 | -class Product < ActiveRecord::Base | |
686 | +class Product < ApplicationRecord | |
687 | 687 | searchkick suggest: [:name] # fields to generate suggestions |
688 | 688 | end |
689 | 689 | ``` |
... | ... | @@ -821,7 +821,7 @@ Product.search "pear", aggs: {products_per_year: {date_histogram: {field: :creat |
821 | 821 | Specify which fields to index with highlighting. |
822 | 822 | |
823 | 823 | ```ruby |
824 | -class Product < ActiveRecord::Base | |
824 | +class Product < ApplicationRecord | |
825 | 825 | searchkick highlight: [:name] |
826 | 826 | end |
827 | 827 | ``` |
... | ... | @@ -874,7 +874,7 @@ product.similar(fields: [:name], where: {size: "12 oz"}) |
874 | 874 | ### Geospatial Searches |
875 | 875 | |
876 | 876 | ```ruby |
877 | -class Restaurant < ActiveRecord::Base | |
877 | +class Restaurant < ApplicationRecord | |
878 | 878 | searchkick locations: [:location] |
879 | 879 | |
880 | 880 | def search_data |
... | ... | @@ -920,7 +920,7 @@ Restaurant.search "wings", boost_by_distance: {location: {origin: {lat: 37, lon: |
920 | 920 | You can also index and search geo shapes. |
921 | 921 | |
922 | 922 | ```ruby |
923 | -class Restaurant < ActiveRecord::Base | |
923 | +class Restaurant < ApplicationRecord | |
924 | 924 | searchkick geo_shape: { |
925 | 925 | bounds: {tree: "geohash", precision: "1km"} |
926 | 926 | } |
... | ... | @@ -1172,7 +1172,7 @@ If you run into issues on Windows, check out [this post](https://www.rastating.c |
1172 | 1172 | By default, all string fields are searchable (can be used in `fields` option). Speed up indexing and reduce index size by only making some fields searchable. This disables the `_all` field unless it’s listed. |
1173 | 1173 | |
1174 | 1174 | ```ruby |
1175 | -class Product < ActiveRecord::Base | |
1175 | +class Product < ApplicationRecord | |
1176 | 1176 | searchkick searchable: [:name] |
1177 | 1177 | end |
1178 | 1178 | ``` |
... | ... | @@ -1182,7 +1182,7 @@ end |
1182 | 1182 | By default, all string fields are filterable (can be used in `where` option). Speed up indexing and reduce index size by only making some fields filterable. |
1183 | 1183 | |
1184 | 1184 | ```ruby |
1185 | -class Product < ActiveRecord::Base | |
1185 | +class Product < ApplicationRecord | |
1186 | 1186 | searchkick filterable: [:brand] |
1187 | 1187 | end |
1188 | 1188 | ``` |
... | ... | @@ -1267,7 +1267,7 @@ Searchkick.redis = ConnectionPool.new { Redis.new } |
1267 | 1267 | And ask your models to queue updates. |
1268 | 1268 | |
1269 | 1269 | ```ruby |
1270 | -class Product < ActiveRecord::Base | |
1270 | +class Product < ApplicationRecord | |
1271 | 1271 | searchkick callbacks: :queue |
1272 | 1272 | end |
1273 | 1273 | ``` |
... | ... | @@ -1291,7 +1291,7 @@ For more tips, check out [Keeping Elasticsearch in Sync](https://www.elastic.co/ |
1291 | 1291 | Searchkick supports [Elasticsearch’s routing feature](https://www.elastic.co/blog/customizing-your-document-routing), which can significantly speed up searches. |
1292 | 1292 | |
1293 | 1293 | ```ruby |
1294 | -class Business < ActiveRecord::Base | |
1294 | +class Business < ApplicationRecord | |
1295 | 1295 | searchkick routing: true |
1296 | 1296 | |
1297 | 1297 | def search_routing |
... | ... | @@ -1311,7 +1311,7 @@ Business.search "ice cream", routing: params[:city_id] |
1311 | 1311 | Reindex a subset of attributes to reduce time spent generating search data and cut down on network traffic. |
1312 | 1312 | |
1313 | 1313 | ```ruby |
1314 | -class Product < ActiveRecord::Base | |
1314 | +class Product < ApplicationRecord | |
1315 | 1315 | def search_data |
1316 | 1316 | { |
1317 | 1317 | name: name |
... | ... | @@ -1338,7 +1338,7 @@ Product.reindex(:search_prices) |
1338 | 1338 | Split out conversions into a separate method so you can use partial reindexing, and cache conversions to prevent N+1 queries. Be sure to use a centralized cache store like Memcached or Redis. |
1339 | 1339 | |
1340 | 1340 | ```ruby |
1341 | -class Product < ActiveRecord::Base | |
1341 | +class Product < ApplicationRecord | |
1342 | 1342 | def search_data |
1343 | 1343 | { |
1344 | 1344 | name: name |
... | ... | @@ -1403,7 +1403,7 @@ Searchkick makes it easy to use the Elasticsearch DSL on its own. |
1403 | 1403 | Create a custom mapping: |
1404 | 1404 | |
1405 | 1405 | ```ruby |
1406 | -class Product < ActiveRecord::Base | |
1406 | +class Product < ApplicationRecord | |
1407 | 1407 | searchkick mappings: { |
1408 | 1408 | product: { |
1409 | 1409 | properties: { |
... | ... | @@ -1418,7 +1418,7 @@ end |
1418 | 1418 | To keep the mappings and settings generated by Searchkick, use: |
1419 | 1419 | |
1420 | 1420 | ```ruby |
1421 | -class Product < ActiveRecord::Base | |
1421 | +class Product < ApplicationRecord | |
1422 | 1422 | searchkick merge_mappings: true, mappings: {...} |
1423 | 1423 | end |
1424 | 1424 | ``` |
... | ... | @@ -1544,7 +1544,7 @@ Product.search_index.clean_indices |
1544 | 1544 | Use custom settings |
1545 | 1545 | |
1546 | 1546 | ```ruby |
1547 | -class Product < ActiveRecord::Base | |
1547 | +class Product < ApplicationRecord | |
1548 | 1548 | searchkick settings: {number_of_shards: 3} |
1549 | 1549 | end |
1550 | 1550 | ``` |
... | ... | @@ -1552,7 +1552,7 @@ end |
1552 | 1552 | Use a different index name |
1553 | 1553 | |
1554 | 1554 | ```ruby |
1555 | -class Product < ActiveRecord::Base | |
1555 | +class Product < ApplicationRecord | |
1556 | 1556 | searchkick index_name: "products_v2" |
1557 | 1557 | end |
1558 | 1558 | ``` |
... | ... | @@ -1560,7 +1560,7 @@ end |
1560 | 1560 | Use a dynamic index name |
1561 | 1561 | |
1562 | 1562 | ```ruby |
1563 | -class Product < ActiveRecord::Base | |
1563 | +class Product < ApplicationRecord | |
1564 | 1564 | searchkick index_name: -> { "#{name.tableize}-#{I18n.locale}" } |
1565 | 1565 | end |
1566 | 1566 | ``` |
... | ... | @@ -1568,7 +1568,7 @@ end |
1568 | 1568 | Prefix the index name |
1569 | 1569 | |
1570 | 1570 | ```ruby |
1571 | -class Product < ActiveRecord::Base | |
1571 | +class Product < ApplicationRecord | |
1572 | 1572 | searchkick index_prefix: "datakick" |
1573 | 1573 | end |
1574 | 1574 | ``` |
... | ... | @@ -1588,7 +1588,7 @@ Product.search("banana", conversions_term: "organic banana") |
1588 | 1588 | Multiple conversion fields |
1589 | 1589 | |
1590 | 1590 | ```ruby |
1591 | -class Product < ActiveRecord::Base | |
1591 | +class Product < ApplicationRecord | |
1592 | 1592 | has_many :searches, class_name: "Searchjoy::Search" |
1593 | 1593 | |
1594 | 1594 | # searchkick also supports multiple "conversions" fields |
... | ... | @@ -1653,7 +1653,7 @@ Searchkick.search("*", index_name: [Product, Store], model_includes: {Product = |
1653 | 1653 | Specify default fields to search |
1654 | 1654 | |
1655 | 1655 | ```ruby |
1656 | -class Product < ActiveRecord::Base | |
1656 | +class Product < ApplicationRecord | |
1657 | 1657 | searchkick default_fields: [:name] |
1658 | 1658 | end |
1659 | 1659 | ``` |
... | ... | @@ -1661,7 +1661,7 @@ end |
1661 | 1661 | Turn off special characters |
1662 | 1662 | |
1663 | 1663 | ```ruby |
1664 | -class Product < ActiveRecord::Base | |
1664 | +class Product < ApplicationRecord | |
1665 | 1665 | # A will not match Ä |
1666 | 1666 | searchkick special_characters: false |
1667 | 1667 | end |
... | ... | @@ -1670,7 +1670,7 @@ end |
1670 | 1670 | Use a different [similarity algorithm](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-similarity.html) for scoring |
1671 | 1671 | |
1672 | 1672 | ```ruby |
1673 | -class Product < ActiveRecord::Base | |
1673 | +class Product < ApplicationRecord | |
1674 | 1674 | searchkick similarity: "classic" |
1675 | 1675 | end |
1676 | 1676 | ``` |
... | ... | @@ -1678,7 +1678,7 @@ end |
1678 | 1678 | Change import batch size |
1679 | 1679 | |
1680 | 1680 | ```ruby |
1681 | -class Product < ActiveRecord::Base | |
1681 | +class Product < ApplicationRecord | |
1682 | 1682 | searchkick batch_size: 200 # defaults to 1000 |
1683 | 1683 | end |
1684 | 1684 | ``` |
... | ... | @@ -1705,7 +1705,7 @@ Product.search("carrots", request_params: {search_type: "dfs_query_then_fetch"}) |
1705 | 1705 | Reindex conditionally |
1706 | 1706 | |
1707 | 1707 | ```ruby |
1708 | -class Product < ActiveRecord::Base | |
1708 | +class Product < ApplicationRecord | |
1709 | 1709 | searchkick callbacks: false |
1710 | 1710 | |
1711 | 1711 | # add the callbacks manually |
... | ... | @@ -1907,7 +1907,7 @@ Product.search_index.refresh |
1907 | 1907 | Due to the distributed nature of Elasticsearch, you can get incorrect results when the number of documents in the index is low. You can [read more about it here](https://www.elastic.co/blog/understanding-query-then-fetch-vs-dfs-query-then-fetch). To fix this, do: |
1908 | 1908 | |
1909 | 1909 | ```ruby |
1910 | -class Product < ActiveRecord::Base | |
1910 | +class Product < ApplicationRecord | |
1911 | 1911 | searchkick settings: {number_of_shards: 1} |
1912 | 1912 | end |
1913 | 1913 | ``` | ... | ... |