Commit e005f88d3a482dbba4477e811680d3758b257e67
1 parent
169dc02c
Exists in
master
and in
2 other branches
Added parentheses to examples [skip ci]
Showing
1 changed file
with
59 additions
and
59 deletions
Show diff stats
README.md
... | ... | @@ -98,7 +98,7 @@ Searchkick supports the complete [Elasticsearch Search API](https://www.elastic. |
98 | 98 | Query like SQL |
99 | 99 | |
100 | 100 | ```ruby |
101 | -Product.search "apples", where: {in_stock: true}, limit: 10, offset: 50 | |
101 | +Product.search("apples", where: {in_stock: true}, limit: 10, offset: 50) | |
102 | 102 | ``` |
103 | 103 | |
104 | 104 | Search specific fields |
... | ... | @@ -226,7 +226,7 @@ You can also boost by: |
226 | 226 | Use a `*` for the query. |
227 | 227 | |
228 | 228 | ```ruby |
229 | -Product.search "*" | |
229 | +Product.search("*") | |
230 | 230 | ``` |
231 | 231 | |
232 | 232 | ### Pagination |
... | ... | @@ -235,7 +235,7 @@ Plays nicely with kaminari and will_paginate. |
235 | 235 | |
236 | 236 | ```ruby |
237 | 237 | # controller |
238 | -@products = Product.search "milk", page: params[:page], per_page: 20 | |
238 | +@products = Product.search("milk", page: params[:page], per_page: 20) | |
239 | 239 | ``` |
240 | 240 | |
241 | 241 | View with kaminari |
... | ... | @@ -255,13 +255,13 @@ View with will_paginate |
255 | 255 | By default, results must match all words in the query. |
256 | 256 | |
257 | 257 | ```ruby |
258 | -Product.search "fresh honey" # fresh AND honey | |
258 | +Product.search("fresh honey") # fresh AND honey | |
259 | 259 | ``` |
260 | 260 | |
261 | 261 | To change this, use: |
262 | 262 | |
263 | 263 | ```ruby |
264 | -Product.search "fresh honey", operator: "or" # fresh OR honey | |
264 | +Product.search("fresh honey", operator: "or") # fresh OR honey | |
265 | 265 | ``` |
266 | 266 | |
267 | 267 | By default, results must match the entire word - `back` will not match `backpack`. You can change this behavior with: |
... | ... | @@ -275,7 +275,7 @@ end |
275 | 275 | And to search (after you reindex): |
276 | 276 | |
277 | 277 | ```ruby |
278 | -Product.search "back", fields: [:name], match: :word_start | |
278 | +Product.search("back", fields: [:name], match: :word_start) | |
279 | 279 | ``` |
280 | 280 | |
281 | 281 | Available options are: |
... | ... | @@ -297,7 +297,7 @@ The default is `:word`. The most matches will happen with `:word_middle`. |
297 | 297 | To match a field exactly (case-sensitive), use: |
298 | 298 | |
299 | 299 | ```ruby |
300 | -User.search query, fields: [{email: :exact}, :name] | |
300 | +Product.search(query, fields: [{email: :exact}, :name]) | |
301 | 301 | ``` |
302 | 302 | |
303 | 303 | ### Phrase Matches |
... | ... | @@ -305,7 +305,7 @@ User.search query, fields: [{email: :exact}, :name] |
305 | 305 | To only match the exact order, use: |
306 | 306 | |
307 | 307 | ```ruby |
308 | -User.search "fresh honey", match: :phrase | |
308 | +Product.search("fresh honey", match: :phrase) | |
309 | 309 | ``` |
310 | 310 | |
311 | 311 | ### Stemming and Language |
... | ... | @@ -426,7 +426,7 @@ end |
426 | 426 | Search with: |
427 | 427 | |
428 | 428 | ```ruby |
429 | -Product.search query, fields: [:name_tagged] | |
429 | +Product.search(query, fields: [:name_tagged]) | |
430 | 430 | ``` |
431 | 431 | |
432 | 432 | ### Misspellings |
... | ... | @@ -436,13 +436,13 @@ By default, Searchkick handles misspelled queries by returning results with an [ |
436 | 436 | You can change this with: |
437 | 437 | |
438 | 438 | ```ruby |
439 | -Product.search "zucini", misspellings: {edit_distance: 2} # zucchini | |
439 | +Product.search("zucini", misspellings: {edit_distance: 2}) # zucchini | |
440 | 440 | ``` |
441 | 441 | |
442 | 442 | 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. |
443 | 443 | |
444 | 444 | ```ruby |
445 | -Product.search "zuchini", misspellings: {below: 5} | |
445 | +Product.search("zuchini", misspellings: {below: 5}) | |
446 | 446 | ``` |
447 | 447 | |
448 | 448 | If there are fewer than 5 results, a 2nd search is performed with misspellings enabled. The result of this query is returned. |
... | ... | @@ -450,13 +450,13 @@ If there are fewer than 5 results, a 2nd search is performed with misspellings e |
450 | 450 | Turn off misspellings with: |
451 | 451 | |
452 | 452 | ```ruby |
453 | -Product.search "zuchini", misspellings: false # no zucchini | |
453 | +Product.search("zuchini", misspellings: false) # no zucchini | |
454 | 454 | ``` |
455 | 455 | |
456 | 456 | Specify which fields can include misspellings with: |
457 | 457 | |
458 | 458 | ```ruby |
459 | -Product.search "zucini", fields: [:name, :color], misspellings: {fields: [:name]} | |
459 | +Product.search("zucini", fields: [:name, :color], misspellings: {fields: [:name]}) | |
460 | 460 | ``` |
461 | 461 | |
462 | 462 | > When doing this, you must also specify fields to search |
... | ... | @@ -466,7 +466,7 @@ Product.search "zucini", fields: [:name, :color], misspellings: {fields: [:name] |
466 | 466 | If a user searches `butter`, they may also get results for `peanut butter`. To prevent this, use: |
467 | 467 | |
468 | 468 | ```ruby |
469 | -Product.search "butter", exclude: ["peanut butter"] | |
469 | +Product.search("butter", exclude: ["peanut butter"]) | |
470 | 470 | ``` |
471 | 471 | |
472 | 472 | You can map queries and terms to exclude with: |
... | ... | @@ -477,7 +477,7 @@ exclude_queries = { |
477 | 477 | "cream" => ["ice cream", "whipped cream"] |
478 | 478 | } |
479 | 479 | |
480 | -Product.search query, exclude: exclude_queries[query] | |
480 | +Product.search(query, exclude: exclude_queries[query]) | |
481 | 481 | ``` |
482 | 482 | |
483 | 483 | You can demote results by boosting by a factor less than one: |
... | ... | @@ -499,7 +499,7 @@ gem "gemoji-parser" |
499 | 499 | And use: |
500 | 500 | |
501 | 501 | ```ruby |
502 | -Product.search "๐จ๐ฐ", emoji: true | |
502 | +Product.search("๐จ๐ฐ", emoji: true) | |
503 | 503 | ``` |
504 | 504 | |
505 | 505 | ## Indexing |
... | ... | @@ -651,7 +651,7 @@ end |
651 | 651 | The best starting point to improve your search **by far** is to track searches and conversions. [Searchjoy](https://github.com/ankane/searchjoy) makes it easy. |
652 | 652 | |
653 | 653 | ```ruby |
654 | -Product.search "apple", track: {user_id: current_user.id} | |
654 | +Product.search("apple", track: {user_id: current_user.id}) | |
655 | 655 | ``` |
656 | 656 | |
657 | 657 | [See the docs](https://github.com/ankane/searchjoy) for how to install and use. |
... | ... | @@ -709,7 +709,7 @@ end |
709 | 709 | Reindex and search with: |
710 | 710 | |
711 | 711 | ```ruby |
712 | -Product.search "milk", boost_where: {orderer_ids: current_user.id} | |
712 | +Product.search("milk", boost_where: {orderer_ids: current_user.id}) | |
713 | 713 | ``` |
714 | 714 | |
715 | 715 | ## Instant Search / Autocomplete |
... | ... | @@ -733,7 +733,7 @@ end |
733 | 733 | Reindex and search with: |
734 | 734 | |
735 | 735 | ```ruby |
736 | -Movie.search "jurassic pa", fields: [:title], match: :word_start | |
736 | +Movie.search("jurassic pa", fields: [:title], match: :word_start) | |
737 | 737 | ``` |
738 | 738 | |
739 | 739 | Typically, you want to use a JavaScript library like [typeahead.js](https://twitter.github.io/typeahead.js/) or [jQuery UI](https://jqueryui.com/autocomplete/). |
... | ... | @@ -793,7 +793,7 @@ end |
793 | 793 | Reindex and search with: |
794 | 794 | |
795 | 795 | ```ruby |
796 | -products = Product.search "peantu butta", suggest: true | |
796 | +products = Product.search("peantu butta", suggest: true) | |
797 | 797 | products.suggestions # ["peanut butter"] |
798 | 798 | ``` |
799 | 799 | |
... | ... | @@ -804,40 +804,40 @@ products.suggestions # ["peanut butter"] |
804 | 804 |  |
805 | 805 | |
806 | 806 | ```ruby |
807 | -products = Product.search "chuck taylor", aggs: [:product_type, :gender, :brand] | |
807 | +products = Product.search("chuck taylor", aggs: [:product_type, :gender, :brand]) | |
808 | 808 | products.aggs |
809 | 809 | ``` |
810 | 810 | |
811 | 811 | By default, `where` conditions apply to aggregations. |
812 | 812 | |
813 | 813 | ```ruby |
814 | -Product.search "wingtips", where: {color: "brandy"}, aggs: [:size] | |
814 | +Product.search("wingtips", where: {color: "brandy"}, aggs: [:size]) | |
815 | 815 | # aggregations for brandy wingtips are returned |
816 | 816 | ``` |
817 | 817 | |
818 | 818 | Change this with: |
819 | 819 | |
820 | 820 | ```ruby |
821 | -Product.search "wingtips", where: {color: "brandy"}, aggs: [:size], smart_aggs: false | |
821 | +Product.search("wingtips", where: {color: "brandy"}, aggs: [:size], smart_aggs: false) | |
822 | 822 | # aggregations for all wingtips are returned |
823 | 823 | ``` |
824 | 824 | |
825 | 825 | Set `where` conditions for each aggregation separately with: |
826 | 826 | |
827 | 827 | ```ruby |
828 | -Product.search "wingtips", aggs: {size: {where: {color: "brandy"}}} | |
828 | +Product.search("wingtips", aggs: {size: {where: {color: "brandy"}}}) | |
829 | 829 | ``` |
830 | 830 | |
831 | 831 | Limit |
832 | 832 | |
833 | 833 | ```ruby |
834 | -Product.search "apples", aggs: {store_id: {limit: 10}} | |
834 | +Product.search("apples", aggs: {store_id: {limit: 10}}) | |
835 | 835 | ``` |
836 | 836 | |
837 | 837 | Order |
838 | 838 | |
839 | 839 | ```ruby |
840 | -Product.search "wingtips", aggs: {color: {order: {"_key" => "asc"}}} # alphabetically | |
840 | +Product.search("wingtips", aggs: {color: {order: {"_key" => "asc"}}}) # alphabetically | |
841 | 841 | ``` |
842 | 842 | |
843 | 843 | [All of these options are supported](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order) |
... | ... | @@ -846,31 +846,31 @@ Ranges |
846 | 846 | |
847 | 847 | ```ruby |
848 | 848 | price_ranges = [{to: 20}, {from: 20, to: 50}, {from: 50}] |
849 | -Product.search "*", aggs: {price: {ranges: price_ranges}} | |
849 | +Product.search("*", aggs: {price: {ranges: price_ranges}}) | |
850 | 850 | ``` |
851 | 851 | |
852 | 852 | Minimum document count |
853 | 853 | |
854 | 854 | ```ruby |
855 | -Product.search "apples", aggs: {store_id: {min_doc_count: 2}} | |
855 | +Product.search("apples", aggs: {store_id: {min_doc_count: 2}}) | |
856 | 856 | ``` |
857 | 857 | |
858 | 858 | Script support |
859 | 859 | |
860 | 860 | ```ruby |
861 | -Product.search "*", aggs: {color: {script: {source: "'Color: ' + _value"}}} | |
861 | +Product.search("*", aggs: {color: {script: {source: "'Color: ' + _value"}}}) | |
862 | 862 | ``` |
863 | 863 | |
864 | 864 | Date histogram |
865 | 865 | |
866 | 866 | ```ruby |
867 | -Product.search "pear", aggs: {products_per_year: {date_histogram: {field: :created_at, interval: :year}}} | |
867 | +Product.search("pear", aggs: {products_per_year: {date_histogram: {field: :created_at, interval: :year}}}) | |
868 | 868 | ``` |
869 | 869 | |
870 | 870 | For other aggregation types, including sub-aggregations, use `body_options`: |
871 | 871 | |
872 | 872 | ```ruby |
873 | -Product.search "orange", body_options: {aggs: {price: {histogram: {field: :price, interval: 10}}}} | |
873 | +Product.search("orange", body_options: {aggs: {price: {histogram: {field: :price, interval: 10}}}}) | |
874 | 874 | ``` |
875 | 875 | |
876 | 876 | ## Highlight |
... | ... | @@ -886,7 +886,7 @@ end |
886 | 886 | Highlight the search query in the results. |
887 | 887 | |
888 | 888 | ```ruby |
889 | -bands = Band.search "cinema", highlight: true | |
889 | +bands = Band.search("cinema", highlight: true) | |
890 | 890 | ``` |
891 | 891 | |
892 | 892 | View the highlighted fields with: |
... | ... | @@ -900,19 +900,19 @@ end |
900 | 900 | To change the tag, use: |
901 | 901 | |
902 | 902 | ```ruby |
903 | -Band.search "cinema", highlight: {tag: "<strong>"} | |
903 | +Band.search("cinema", highlight: {tag: "<strong>"}) | |
904 | 904 | ``` |
905 | 905 | |
906 | 906 | To highlight and search different fields, use: |
907 | 907 | |
908 | 908 | ```ruby |
909 | -Band.search "cinema", fields: [:name], highlight: {fields: [:description]} | |
909 | +Band.search("cinema", fields: [:name], highlight: {fields: [:description]}) | |
910 | 910 | ``` |
911 | 911 | |
912 | 912 | By default, the entire field is highlighted. To get small snippets instead, use: |
913 | 913 | |
914 | 914 | ```ruby |
915 | -bands = Band.search "cinema", highlight: {fragment_size: 20} | |
915 | +bands = Band.search("cinema", highlight: {fragment_size: 20}) | |
916 | 916 | bands.with_highlights(multiple: true).each do |band, highlights| |
917 | 917 | highlights[:name].join(" and ") |
918 | 918 | end |
... | ... | @@ -921,7 +921,7 @@ end |
921 | 921 | Additional options can be specified for each field: |
922 | 922 | |
923 | 923 | ```ruby |
924 | -Band.search "cinema", fields: [:name], highlight: {fields: {name: {fragment_size: 200}}} | |
924 | +Band.search("cinema", fields: [:name], highlight: {fields: {name: {fragment_size: 200}}}) | |
925 | 925 | ``` |
926 | 926 | |
927 | 927 | You can find available highlight options in the [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html). |
... | ... | @@ -950,13 +950,13 @@ end |
950 | 950 | Reindex and search with: |
951 | 951 | |
952 | 952 | ```ruby |
953 | -Restaurant.search "pizza", where: {location: {near: {lat: 37, lon: -114}, within: "100mi"}} # or 160km | |
953 | +Restaurant.search("pizza", where: {location: {near: {lat: 37, lon: -114}, within: "100mi"}}) # or 160km | |
954 | 954 | ``` |
955 | 955 | |
956 | 956 | Bounded by a box |
957 | 957 | |
958 | 958 | ```ruby |
959 | -Restaurant.search "sushi", where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}} | |
959 | +Restaurant.search("sushi", where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}}) | |
960 | 960 | ``` |
961 | 961 | |
962 | 962 | **Note:** `top_right` and `bottom_left` also work |
... | ... | @@ -964,7 +964,7 @@ Restaurant.search "sushi", where: {location: {top_left: {lat: 38, lon: -123}, bo |
964 | 964 | Bounded by a polygon |
965 | 965 | |
966 | 966 | ```ruby |
967 | -Restaurant.search "dessert", where: {location: {geo_polygon: {points: [{lat: 38, lon: -123}, {lat: 39, lon: -123}, {lat: 37, lon: 122}]}}} | |
967 | +Restaurant.search("dessert", where: {location: {geo_polygon: {points: [{lat: 38, lon: -123}, {lat: 39, lon: -123}, {lat: 37, lon: 122}]}}}) | |
968 | 968 | ``` |
969 | 969 | |
970 | 970 | ### Boost By Distance |
... | ... | @@ -972,13 +972,13 @@ Restaurant.search "dessert", where: {location: {geo_polygon: {points: [{lat: 38, |
972 | 972 | Boost results by distance - closer results are boosted more |
973 | 973 | |
974 | 974 | ```ruby |
975 | -Restaurant.search "noodles", boost_by_distance: {location: {origin: {lat: 37, lon: -122}}} | |
975 | +Restaurant.search("noodles", boost_by_distance: {location: {origin: {lat: 37, lon: -122}}}) | |
976 | 976 | ``` |
977 | 977 | |
978 | 978 | Also supports [additional options](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay) |
979 | 979 | |
980 | 980 | ```ruby |
981 | -Restaurant.search "wings", boost_by_distance: {location: {origin: {lat: 37, lon: -122}, function: "linear", scale: "30mi", decay: 0.5}} | |
981 | +Restaurant.search("wings", boost_by_distance: {location: {origin: {lat: 37, lon: -122}, function: "linear", scale: "30mi", decay: 0.5}}) | |
982 | 982 | ``` |
983 | 983 | |
984 | 984 | ### Geo Shapes |
... | ... | @@ -1005,19 +1005,19 @@ See the [Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsea |
1005 | 1005 | Find shapes intersecting with the query shape |
1006 | 1006 | |
1007 | 1007 | ```ruby |
1008 | -Restaurant.search "soup", where: {bounds: {geo_shape: {type: "polygon", coordinates: [[{lat: 38, lon: -123}, ...]]}}} | |
1008 | +Restaurant.search("soup", where: {bounds: {geo_shape: {type: "polygon", coordinates: [[{lat: 38, lon: -123}, ...]]}}}) | |
1009 | 1009 | ``` |
1010 | 1010 | |
1011 | 1011 | Falling entirely within the query shape |
1012 | 1012 | |
1013 | 1013 | ```ruby |
1014 | -Restaurant.search "salad", where: {bounds: {geo_shape: {type: "circle", relation: "within", coordinates: [{lat: 38, lon: -123}], radius: "1km"}}} | |
1014 | +Restaurant.search("salad", where: {bounds: {geo_shape: {type: "circle", relation: "within", coordinates: [{lat: 38, lon: -123}], radius: "1km"}}}) | |
1015 | 1015 | ``` |
1016 | 1016 | |
1017 | 1017 | Not touching the query shape |
1018 | 1018 | |
1019 | 1019 | ```ruby |
1020 | -Restaurant.search "burger", where: {bounds: {geo_shape: {type: "envelope", relation: "disjoint", coordinates: [{lat: 38, lon: -123}, {lat: 37, lon: -122}]}}} | |
1020 | +Restaurant.search("burger", where: {bounds: {geo_shape: {type: "envelope", relation: "disjoint", coordinates: [{lat: 38, lon: -123}, {lat: 37, lon: -122}]}}}) | |
1021 | 1021 | ``` |
1022 | 1022 | |
1023 | 1023 | ## Inheritance |
... | ... | @@ -1047,9 +1047,9 @@ Dog.reindex # equivalent, all animals reindexed |
1047 | 1047 | And to search, use: |
1048 | 1048 | |
1049 | 1049 | ```ruby |
1050 | -Animal.search "*" # all animals | |
1051 | -Dog.search "*" # just dogs | |
1052 | -Animal.search "*", type: [Dog, Cat] # just cats and dogs | |
1050 | +Animal.search("*") # all animals | |
1051 | +Dog.search("*") # just dogs | |
1052 | +Animal.search("*", type: [Dog, Cat]) # just cats and dogs | |
1053 | 1053 | ``` |
1054 | 1054 | |
1055 | 1055 | **Notes:** |
... | ... | @@ -1057,7 +1057,7 @@ Animal.search "*", type: [Dog, Cat] # just cats and dogs |
1057 | 1057 | 1. The `suggest` option retrieves suggestions from the parent at the moment. |
1058 | 1058 | |
1059 | 1059 | ```ruby |
1060 | - Dog.search "airbudd", suggest: true # suggestions for all animals | |
1060 | + Dog.search("airbudd", suggest: true) # suggestions for all animals | |
1061 | 1061 | ``` |
1062 | 1062 | 2. This relies on a `type` field that is automatically added to the indexed document. Be wary of defining your own `type` field in `search_data`, as it will take precedence. |
1063 | 1063 | |
... | ... | @@ -1562,7 +1562,7 @@ end |
1562 | 1562 | Reindex and search with: |
1563 | 1563 | |
1564 | 1564 | ```ruby |
1565 | -Business.search "ice cream", routing: params[:city_id] | |
1565 | +Business.search("ice cream", routing: params[:city_id]) | |
1566 | 1566 | ``` |
1567 | 1567 | |
1568 | 1568 | ### Partial Reindexing |
... | ... | @@ -1685,7 +1685,7 @@ end |
1685 | 1685 | And use the `body` option to search: |
1686 | 1686 | |
1687 | 1687 | ```ruby |
1688 | -products = Product.search body: {query: {match: {name: "milk"}}} | |
1688 | +products = Product.search(body: {query: {match: {name: "milk"}}}) | |
1689 | 1689 | ``` |
1690 | 1690 | |
1691 | 1691 | View the response with: |
... | ... | @@ -1697,14 +1697,14 @@ products.response |
1697 | 1697 | To modify the query generated by Searchkick, use: |
1698 | 1698 | |
1699 | 1699 | ```ruby |
1700 | -products = Product.search "milk", body_options: {min_score: 1} | |
1700 | +products = Product.search("milk", body_options: {min_score: 1}) | |
1701 | 1701 | ``` |
1702 | 1702 | |
1703 | 1703 | or |
1704 | 1704 | |
1705 | 1705 | ```ruby |
1706 | 1706 | products = |
1707 | - Product.search "apples" do |body| | |
1707 | + Product.search("apples") do |body| | |
1708 | 1708 | body[:min_score] = 1 |
1709 | 1709 | end |
1710 | 1710 | ``` |
... | ... | @@ -1736,7 +1736,7 @@ Then use `products` and `coupons` as typical results. |
1736 | 1736 | Search across multiple models with: |
1737 | 1737 | |
1738 | 1738 | ```ruby |
1739 | -Searchkick.search "milk", models: [Product, Category] | |
1739 | +Searchkick.search("milk", models: [Product, Category]) | |
1740 | 1740 | ``` |
1741 | 1741 | |
1742 | 1742 | Boost specific models with: |
... | ... | @@ -1762,7 +1762,7 @@ end |
1762 | 1762 | You can also scroll batches manually. |
1763 | 1763 | |
1764 | 1764 | ```ruby |
1765 | -products = Product.search "*", scroll: "1m" | |
1765 | +products = Product.search("*", scroll: "1m") | |
1766 | 1766 | while products.any? |
1767 | 1767 | # process batch ... |
1768 | 1768 | |
... | ... | @@ -1793,7 +1793,7 @@ Product.search("pears", body_options: {track_total_hits: true}) |
1793 | 1793 | To query nested data, use dot notation. |
1794 | 1794 | |
1795 | 1795 | ```ruby |
1796 | -User.search "san", fields: ["address.city"], where: {"address.zip_code" => 12345} | |
1796 | +User.search("san", fields: ["address.city"], where: {"address.zip_code" => 12345}) | |
1797 | 1797 | ``` |
1798 | 1798 | |
1799 | 1799 | ## Reference |
... | ... | @@ -1923,7 +1923,7 @@ Searchkick.queue_name = :search_reindex |
1923 | 1923 | Eager load associations |
1924 | 1924 | |
1925 | 1925 | ```ruby |
1926 | -Product.search "milk", includes: [:brand, :stores] | |
1926 | +Product.search("milk", includes: [:brand, :stores]) | |
1927 | 1927 | ``` |
1928 | 1928 | |
1929 | 1929 | Eager load different associations by model |
... | ... | @@ -1935,7 +1935,7 @@ Searchkick.search("*", models: [Product, Store], model_includes: {Product => [: |
1935 | 1935 | Run additional scopes on results |
1936 | 1936 | |
1937 | 1937 | ```ruby |
1938 | -Product.search "milk", scope_results: ->(r) { r.with_attached_images } | |
1938 | +Product.search("milk", scope_results: ->(r) { r.with_attached_images }) | |
1939 | 1939 | ``` |
1940 | 1940 | |
1941 | 1941 | Specify default fields to search |
... | ... | @@ -2031,13 +2031,13 @@ rake searchkick:reindex:all |
2031 | 2031 | Turn on misspellings after a certain number of characters |
2032 | 2032 | |
2033 | 2033 | ```ruby |
2034 | -Product.search "api", misspellings: {prefix_length: 2} # api, apt, no ahi | |
2034 | +Product.search("api", misspellings: {prefix_length: 2}) # api, apt, no ahi | |
2035 | 2035 | ``` |
2036 | 2036 | |
2037 | 2037 | **Note:** With this option, if the query length is the same as `prefix_length`, misspellings are turned off with Elasticsearch 7 and OpenSearch |
2038 | 2038 | |
2039 | 2039 | ```ruby |
2040 | -Product.search "ah", misspellings: {prefix_length: 2} # ah, no aha | |
2040 | +Product.search("ah", misspellings: {prefix_length: 2}) # ah, no aha | |
2041 | 2041 | ``` |
2042 | 2042 | |
2043 | 2043 | ## Gotchas | ... | ... |