Problem:
Ransack will only search for one keyword or phrase such as, "Jumpity Jump", without quotations. Using quotations or commas such as in "Jumpity Jump" or, "Jumpity, Jump" (with or without quotations). returns a blank result.
Test conditions:
Randomly selected records were edited to include varied words/phrases in searched fields, such as in the following examples:
- jump
- jumpity jump
- jimpity jump jump
- rabbit jumpity
- jumpity rabbit
Solution:
Custom predicates added to initializer based on Stack Overflow answer linked at end.
Using "cont_all"
This returns records if:
- quotation or commas are not used
- Search phrase is found
- Search word is found
Example Sentence: "rabbit has toes that go jumpity jump jump"
Search phrases:
- rabbit (match)
- Rabbit (match)
- RABBIT (match)
- rab (match)
- bit (match)
- rabbit toes (no match)
- "rabbit toes" (no match)
- rabbit toes weasel (no match)
- rabbit has (match)
- rabbit, jump (no match)
- "rabbit has" (no match)
- rabbit, has (no match)
- jumpity jump (no match)
- jump jump (match)
Using "cont_any"
Is supposed to be different from "cont_all" but appears to work the same.
Example Sentence: "rabbit has toes that go jumpity jump jump"
Search phrases:
- rabbit (match)
- Rabbit (match)
- RABBIT (match)
- rab (match)
- bit (match)
- rabbit toes (no match)
- "rabbit toes" (no match)
- rabbit toes weasel (no match)
- rabbit has (match)
- rabbit, jump (no match)
- "rabbit has" (no match)
- rabbit, has (no match)
- jumpity jump (no match)
- jump jump (match)
Using "has_any_term"
Example Sentence: "rabbit has toes that go jumpity jump jump"
Search phrases:
- rabbit (match)
- Rabbit (match)
- RABBIT (match)
- rab (match)
- bit (match)
- rabbit toes (match)
- "rabbit toes" (no match)
- rabbit toes weasel (match)
- rabbit has (match)
- rabbit, jump (match)
- "rabbit has" (match)
- rabbit, has (match)
- jumpity jump (match)
- jump jump (match)
Using "has_every_term"
Example Sentence: "rabbit has toes that go jumpity jump jump"
Search phrases:
- rabbit (match)
- Rabbit (match)
- RABBIT (match)
- rab (match)
- bit (match)
- rabbit toes (match)
- "rabbit toes" (no match)
- rabbit toes weasel (no match)
- rabbit has (match)
- rabbit, jump (match)
- "rabbit has" (match)
- rabbit, has (match)
- jumpity jump (match)
- jump jump (match)
Conclusion
The built-in predicates don't seem to work as they should according to the documentation. The custom predicates added from Stack Overflow works as expected, but most likely also introduce performance issues that will need to be addressed in time.