Commit ca4216002a14799975d421d4de11bf5e388dfe5d
1 parent
9248b498
Exists in
relation
and in
1 other branch
Added defaults and emoji
Showing
3 changed files
with
25 additions
and
14 deletions
Show diff stats
README.md
... | ... | @@ -437,7 +437,7 @@ gem 'gemoji-parser' |
437 | 437 | And use: |
438 | 438 | |
439 | 439 | ```ruby |
440 | -Product.search("๐จ๐ฐ").emoji(true) | |
440 | +Product.search("๐จ๐ฐ").emoji | |
441 | 441 | ``` |
442 | 442 | |
443 | 443 | ## Indexing |
... | ... | @@ -714,7 +714,7 @@ end |
714 | 714 | Reindex and search with: |
715 | 715 | |
716 | 716 | ```ruby |
717 | -products = Product.search("peantu butta").suggest(true) | |
717 | +products = Product.search("peantu butta").suggest | |
718 | 718 | products.suggestions # ["peanut butter"] |
719 | 719 | ``` |
720 | 720 | |
... | ... | @@ -807,7 +807,7 @@ end |
807 | 807 | Highlight the search query in the results. |
808 | 808 | |
809 | 809 | ```ruby |
810 | -bands = Band.search("cinema").highlight(true) | |
810 | +bands = Band.search("cinema").highlight | |
811 | 811 | ``` |
812 | 812 | |
813 | 813 | View the highlighted fields with: |
... | ... | @@ -978,7 +978,7 @@ Animal.search("*").type(Dog, Cat) # just cats and dogs |
978 | 978 | 1. The `suggest` option retrieves suggestions from the parent at the moment. |
979 | 979 | |
980 | 980 | ```ruby |
981 | - Dog.search("airbudd").suggest(true) # suggestions for all animals | |
981 | + Dog.search("airbudd").suggest # suggestions for all animals | |
982 | 982 | ``` |
983 | 983 | 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. |
984 | 984 | |
... | ... | @@ -987,7 +987,7 @@ Animal.search("*").type(Dog, Cat) # just cats and dogs |
987 | 987 | To help with debugging queries, you can use: |
988 | 988 | |
989 | 989 | ```ruby |
990 | -Product.search("soap").debug(true) | |
990 | +Product.search("soap").debug | |
991 | 991 | ``` |
992 | 992 | |
993 | 993 | This prints useful info to `stdout`. |
... | ... | @@ -995,7 +995,7 @@ This prints useful info to `stdout`. |
995 | 995 | See how Elasticsearch scores your queries with: |
996 | 996 | |
997 | 997 | ```ruby |
998 | -Product.search("soap").explain(true).response | |
998 | +Product.search("soap").explain.response | |
999 | 999 | ``` |
1000 | 1000 | |
1001 | 1001 | See how Elasticsearch tokenizes your queries with: | ... | ... |
lib/searchkick/relation.rb
... | ... | @@ -265,11 +265,11 @@ module Searchkick |
265 | 265 | self |
266 | 266 | end |
267 | 267 | |
268 | - def highlight(value) | |
268 | + def highlight(value = true) | |
269 | 269 | spawn.highlight!(value) |
270 | 270 | end |
271 | 271 | |
272 | - def highlight!(value) | |
272 | + def highlight!(value = true) | |
273 | 273 | options[:highlight] = value |
274 | 274 | self |
275 | 275 | end |
... | ... | @@ -316,20 +316,20 @@ module Searchkick |
316 | 316 | self |
317 | 317 | end |
318 | 318 | |
319 | - def debug(value) | |
319 | + def debug(value = true) | |
320 | 320 | spawn.debug!(value) |
321 | 321 | end |
322 | 322 | |
323 | - def debug!(value) | |
323 | + def debug!(value = true) | |
324 | 324 | options[:debug] = value |
325 | 325 | self |
326 | 326 | end |
327 | 327 | |
328 | - def explain(value) | |
328 | + def explain(value = true) | |
329 | 329 | spawn.explain!(value) |
330 | 330 | end |
331 | 331 | |
332 | - def explain!(value) | |
332 | + def explain!(value = true) | |
333 | 333 | options[:explain] = value |
334 | 334 | self |
335 | 335 | end |
... | ... | @@ -352,15 +352,24 @@ module Searchkick |
352 | 352 | self |
353 | 353 | end |
354 | 354 | |
355 | - def suggest(value) | |
355 | + def suggest(value = true) | |
356 | 356 | spawn.suggest!(value) |
357 | 357 | end |
358 | 358 | |
359 | - def suggest!(value) | |
359 | + def suggest!(value = true) | |
360 | 360 | options[:suggest] = value |
361 | 361 | self |
362 | 362 | end |
363 | 363 | |
364 | + def emoji(value = true) | |
365 | + spawn.emoji!(value) | |
366 | + end | |
367 | + | |
368 | + def emoji!(value = true) | |
369 | + options[:emoji] = value | |
370 | + self | |
371 | + end | |
372 | + | |
364 | 373 | def smart_aggs(value) |
365 | 374 | spawn.smart_aggs!(value) |
366 | 375 | end | ... | ... |
test/match_test.rb
... | ... | @@ -296,12 +296,14 @@ class MatchTest < Minitest::Test |
296 | 296 | skip unless defined?(EmojiParser) |
297 | 297 | store_names ["Banana"] |
298 | 298 | assert_search "๐", ["Banana"], emoji: true |
299 | + assert_search_relation ["Banana"], Product.search("๐").emoji | |
299 | 300 | end |
300 | 301 | |
301 | 302 | def test_emoji_multiple |
302 | 303 | skip unless defined?(EmojiParser) |
303 | 304 | store_names ["Ice Cream Cake"] |
304 | 305 | assert_search "๐จ๐ฐ", ["Ice Cream Cake"], emoji: true |
306 | + assert_search_relation ["Ice Cream Cake"], Product.search("๐จ๐ฐ").emoji | |
305 | 307 | end |
306 | 308 | |
307 | 309 | # TODO find better place | ... | ... |