Conversation
|
@copilot would you start again? |
I've implemented the hyphen-ignoring search functionality. The changes are in commit 5c9261a. What was changed:
How it works:
All security checks passed with no vulnerabilities found. |
|
@copilot make it also correctly match titles with ampersand, periods, em dash, en dash, and quotes |
I've extended the search to ignore ampersands, periods, em dashes, en dashes, and quotes in addition to hyphens. Changes are in commits 5074556 and f92cb34. What was added:
Implementation:
Examples:
All security checks passed with no vulnerabilities. |
f92cb34 to
64cbab0
Compare
| ) #{sort_order == "asc" ? "ASC" : "DESC"} | ||
| SQL | ||
| end | ||
| scope :title, ->(title) { where("workshops.title like ?", "%#{ title }%") } |
| def filter_by_title | ||
| return unless params[:title].present? | ||
| @workshops = @workshops.search("title:#{params[:title]}") | ||
| @workshops = @workshops.title(params[:title]) |
There was a problem hiding this comment.
stop using SearchCop for title search so we can instead apply this stripped chars version of searching.
What is the goal of this PR and why is this important?
Improve punctuation-agnostic searching so more workshops are found
What works
Punctuation stripping (20 characters)
All of these are ignored in both DB values and search input:
-&.—–"'''""/:+!?,()…Hyphen/space/joined variants (all combos match)
self-careself careselfcareself-careself careselfcareSynonym expansion
| Search | DB | Match |
|
arts and crafts|Arts & Crafts| ✅ ||
Arts & Crafts|arts and crafts| ✅ ||
arts + crafts|arts and crafts| ✅ ||
arts and crafts|arts and crafts| ✅ ||
arts crafts|Arts & Crafts| ✅ ||
Painting with Kids|Painting w/ Kids| ✅ ||
Painting w/ Kids|Painting with Kids| ✅ |More examples
| Search | DB | Match |
|
own art|Make your own - art kit| ✅ ||
Dr Workshop|Dr. Workshop| ✅ ||
Art Music|Art/Music| ✅ ||
Create|Create!| ✅ ||
Introduction The Basics|Introduction: The Basics| ✅ |Search targets
action_text_rich_texts.plain_text_body✅utf8mb4_unicode_cicollation) ✅What doesn't work
"crafts arts"won't find"Arts & Crafts"— LIKE requires sequential substring match&since it gets stripped"the art"→ spaceless"theart"could match search"hear"sincet[hear]tis a substringREPLACE()wrapping + leading%wildcards (fine at 700-3k workshops)Original ai description
This PR makes workshop searches ignore punctuation in both user input and workshop data, improving search usability. Users can now find workshops regardless of punctuation variations in titles or text content (e.g., "self-care" vs "selfcare", "Arts & Crafts" vs "Arts Crafts", "Dr. Workshop" vs "Dr Workshop", "The 'Best' Workshop" vs "The Best Workshop").
How did you approach the change?
strip_punctuation_sql(field_name)- generates nested SQL REPLACE functions for database queriesstrip_punctuation(text)- strips punctuation from Ruby stringsPunctuationStrippableconcern and modified thetitlescope to use the helper methods for stripping punctuation from both search input and database fields, with proper SQL injection protection viasanitize_sql_likePunctuationStrippableconcern and updatedfilter_by_querymethod to use the helper methods for custom SQL that strips punctuation from search queries and applies to all searchable workshop fields (title, full_name, objective, materials, setup, introduction, demonstration, etc., including Spanish variants)Anything else to add?
The implementation ensures bidirectional matching for 11 types of punctuation:
-,--&.—–",","',','Examples:
All security checks passed with no vulnerabilities introduced. The refactoring into a reusable concern improves code maintainability and ensures consistency between the Workshop model and WorkshopSearchService.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.