Testing Partial Text Matching Patterns in Searchkick
This test suite validates partial text matching functionality in Searchkick, focusing on various text search patterns including autocomplete, word positioning, and exact matches. The tests ensure robust text search capabilities across different matching scenarios and field configurations.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
ankane/searchkick
test/partial_match_test.rb
require_relative "test_helper"
class PartialMatchTest < Minitest::Test
def test_autocomplete
store_names ["Hummus"]
assert_search "hum", ["Hummus"], match: :text_start
end
def test_autocomplete_two_words
store_names ["Organic Hummus"]
assert_search "hum", [], match: :text_start
end
def test_autocomplete_fields
store_names ["Hummus"]
assert_search "hum", ["Hummus"], match: :text_start, fields: [:name]
end
def test_text_start
store_names ["Where in the World is Carmen San Diego"]
assert_search "where in the world is", ["Where in the World is Carmen San Diego"], fields: [{name: :text_start}]
assert_search "in the world", [], fields: [{name: :text_start}]
end
def test_text_middle
store_names ["Where in the World is Carmen San Diego"]
assert_search "where in the world is", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}]
assert_search "n the wor", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}]
assert_search "men san diego", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}]
assert_search "world carmen", [], fields: [{name: :text_middle}]
end
def test_text_end
store_names ["Where in the World is Carmen San Diego"]
assert_search "men san diego", ["Where in the World is Carmen San Diego"], fields: [{name: :text_end}]
assert_search "carmen san", [], fields: [{name: :text_end}]
end
def test_word_start
store_names ["Where in the World is Carmen San Diego"]
assert_search "car san wor", ["Where in the World is Carmen San Diego"], fields: [{name: :word_start}]
end
def test_word_middle
store_names ["Where in the World is Carmen San Diego"]
assert_search "orl", ["Where in the World is Carmen San Diego"], fields: [{name: :word_middle}]
end
def test_word_end
store_names ["Where in the World is Carmen San Diego"]
assert_search "rld men ego", ["Where in the World is Carmen San Diego"], fields: [{name: :word_end}]
end
def test_word_start_multiple_words
store_names ["Dark Grey", "Dark Blue"]
assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}]
end
def test_word_start_exact
store_names ["Back Scratcher", "Backpack"]
assert_order "back", ["Back Scratcher", "Backpack"], fields: [{name: :word_start}]
end
def test_word_start_exact_martin
store_names ["Martina", "Martin"]
assert_order "martin", ["Martin", "Martina"], fields: [{name: :word_start}]
end
# TODO find a better place
def test_exact
store_names ["[email protected]"]
assert_search "[email protected]", ["[email protected]"], fields: [{name: :exact}]
end
def test_exact_case
store_names ["Hello"]
assert_search "hello", [], fields: [{name: :exact}]
assert_search "Hello", ["Hello"], fields: [{name: :exact}]
end
end