Commit Graph

62 Commits

Author SHA1 Message Date
Fernando Olivares 554182f4b4 Fix stemmer stripping hyphens instead of splitting on them
The stemmer was concatenating tokens across hyphens (e.g. "BC3-IOS-1D8B"
→ "bc3ios1d8b") while the query sanitizer split on them, causing MySQL
MATCH AGAINST to never find the indexed token. Replace non-word chars
with spaces instead of stripping them so indexing and querying tokenize
consistently.

Requires search:reindex after deploy to rebuild existing search records.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 16:16:39 -06:00
Jorge Manrubia 3457c871e1 Revert "Add CJK (Chinese, Japanese, Korean) search support" 2026-01-08 21:07:14 +01:00
LU 366588e263 Add SQLite FTS5 support for CJK search
- Split each CJK character into individual tokens for FTS5 indexing
- Add stem_content callback to SQLite adapter to pre-process content
- Stem search queries before matching against FTS5 index
- Update stemmer tests to reflect character-splitting behavior

This enables CJK search on SQLite installations where the FTS5
tokenizer cannot natively segment CJK text.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 17:51:20 +09:00
LU 2a4fbecbda Add CJK (Chinese, Japanese, Korean) search support
The search functionality was silently dropping CJK characters because:

1. Query sanitization used `\w` which only matches ASCII word characters
2. Stemmer split by whitespace, which doesn't work for CJK languages
3. Highlighter used `\b` word boundaries that don't apply to CJK

This commit fixes all three issues:

- Query: Use `\p{L}\p{N}` (Unicode letters/numbers) instead of `\w`
- Stemmer: Preserve CJK characters as-is without stemming, since CJK
  languages don't have stemming rules like English
- Highlighter: Skip word boundary matching for CJK terms

Also extracts `CJK_PATTERN` to `Search` module to avoid duplication.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-06 17:22:42 +09:00
Donal McBreen 13db384648 Auto default for UUID primary keys
Patch load_schmema! to set the default value for UUID primary keys. This
removes the need to patch ApplicationRecord + Rails models individually.

It also means we no longer need to patch the default in for the integer
primary key in Search::Record::SQLite.
2025-12-03 14:27:52 +00:00
Donal McBreen b571303385 Don't use Current.account for search records
It doesn't actually work, and even if we could make it work reliably
we are better off if the records always know to go to the right shard.

It does make the interface a bit more complicated as we need to select
the right shard class with `for(account_id)`.
2025-11-25 11:34:41 +00:00
Donal McBreen 2199dcc0c8 Fix name in SQL string 2025-11-21 16:01:05 +00:00
Donal McBreen 6f02cb40b1 Drop unnecessary html_safes 2025-11-21 15:46:31 +00:00
Donal McBreen d09deca038 Fallback to search_records_0, so eager loading has a valid table 2025-11-21 15:35:58 +00:00
Donal McBreen 0989017f62 Fix rubocop 2025-11-21 15:31:00 +00:00
Donal McBreen d48eb523b8 Fix rubocop 2025-11-21 15:30:14 +00:00
Donal McBreen be0ce5efa0 Use dependant delete on fts table 2025-11-21 15:28:25 +00:00
Donal McBreen 525e53a2f7 Add FTS ActiveRecord model
Needs some special handling for the FTS virtual table format. Set the
primary key to rowid and manually specify the columns.
2025-11-21 15:21:11 +00:00
Donal McBreen 04c9d9268b Remove wrapper methods and kwargs 2025-11-21 14:53:17 +00:00
Donal McBreen eecdb486b7 Remove unused attribute 2025-11-21 14:42:28 +00:00
Donal McBreen bef4b86212 Use card_search_records instead of join class method 2025-11-21 14:42:09 +00:00
Donal McBreen ea06b2d46f Simplify and test highlighing 2025-11-21 14:25:38 +00:00
Donal McBreen 6e749d2b5f Drop for_user 2025-11-21 12:39:47 +00:00
Donal McBreen aebe3f97ed Drop parentheses 2025-11-21 12:37:29 +00:00
Donal McBreen 02da6dbf8f Parameterised queries 2025-11-21 12:36:45 +00:00
Donal McBreen 463a5f089a Consolidate scopes and extract search_fields 2025-11-21 12:31:25 +00:00
Donal McBreen f91c41d75a Drop variables 2025-11-21 12:11:15 +00:00
Donal McBreen 01d16f96d4 Remove Search::Record.for_account
Instead we'll compute the table name dynamically based on
Current.account where needed. Also we'll prevent searchable records
from being saved if Current.account is not set, otherwise the after
commit callbacks will fail.
2025-11-21 12:09:21 +00:00
Donal McBreen 4008819390 Use table_name with Current.account to drop for_account 2025-11-21 11:54:21 +00:00
Donal McBreen b92aba383e account_key is MySQL specific 2025-11-21 11:47:28 +00:00
Donal McBreen 2e4d0b38db Fix matching scope after merge 2025-11-21 11:43:01 +00:00
Donal McBreen 366dbd393c Merge branch 'main' into sqlite 2025-11-21 11:39:47 +00:00
Donal McBreen adff4591fe Search with the tenant key
The key has been added and populated so use it for searching.
2025-11-21 11:09:06 +00:00
Donal McBreen 74d1cf735b Only add and fill account_key 2025-11-21 10:20:27 +00:00
Donal McBreen 70dd754cf7 Account key for search records
Add an account key field to improve search performance. This field
allows us to filter the records by account directly in the fulltext
index, so we only need to examine rows belonging to the relevant account.
2025-11-21 09:38:35 +00:00
Donal McBreen 4f6ec19491 Drop comments 2025-11-21 09:15:19 +00:00
Donal McBreen 0e11a139a5 Move quoting 2025-11-21 09:15:19 +00:00
Donal McBreen 62d102578f Table name already correct 2025-11-21 09:15:19 +00:00
Donal McBreen ca17193620 Belongs_to not optional 2025-11-21 09:15:19 +00:00
Donal McBreen 6dfb961b83 Delegate to_s to terms 2025-11-21 09:15:19 +00:00
Donal McBreen 19b0e25eac Split sqlite/mysql record stuff 2025-11-21 09:15:19 +00:00
Donal McBreen a4850fbe73 Remove adapter specific logic from searchable 2025-11-21 09:15:19 +00:00
Donal McBreen bb36b4846f Support SQLite searching 2025-11-21 09:15:19 +00:00
Mike Dalessio 2c765fa03f rubocop: style fixes 2025-11-17 09:12:41 -05:00
Donal McBreen 28efe28f24 Replace Search::Index with Search::Records
Lean on ActiveRecord models for searching and strip out the raw SQL.
Replaces the search_index_* tables with sharded search_records_* tables
as that allows us to use a Search::Record model name.

A Class is dynamically created for each record table shard so that we
and we can access it via the Search::Record.for_account(account_id)
method.
2025-11-17 09:12:40 -05:00
Mike Dalessio fe6df7085f Finish the rollout of account_id to all core data models
Schema:
- add account_id to tables it was missing from
- make account_id a required column everywhere
- add [account_id] indexes, or add `account_id` to existing indices

Models:
- add `belongs_to :account` to all models (default to using a domain
  model's account whenever possible)
- add account_id in all the necessary fixtures
- add account_id to insert_all hashes
- pass account_id to a few initialize calls

Miscellaneous:
- update the import script to set account_id

Note that I'm not adding account_id to the join tables primarily
because I couldn't think of an easy way to populate it without making
it a full Join model, and that was more work than I have time to take
on right now.
2025-11-17 09:12:40 -05:00
Mike Dalessio 6df681991f rubocop: fix style warnings 2025-11-17 09:12:36 -05:00
Donal McBreen 436d2b525b Set creator_id as a UUID 2025-11-17 09:12:36 -05:00
Donal McBreen fc56ad9d7c Combine uuid-old and uuid branch changes
- Switch to binary 16 for UUID keys
- Remove AccountScopedRecord base class, all model use binary uuids now
- Fix the search sql to serialize uuids properly
- Patch the MySQL schema dumper to output binary lengths
2025-11-17 09:12:34 -05:00
Mike Dalessio e4011ef211 Update primary keys on customer data to UUIDs
- schema changes to primary and foreign keys
- fixture changes
- customer data models subclass AccountScopedRecord
- import script updated
2025-11-17 09:12:30 -05:00
Stanko K.R. 6858b96619 Simplify join codes 2025-11-17 09:12:17 -05:00
Stanko K.R. 2f62d91bc3 Remove all special charaters when stemming 2025-11-17 09:12:17 -05:00
Stanko K.R. 1b8828da1d Add tests for the highlighter and stemmer 2025-11-17 09:12:17 -05:00
Stanko K.R. a41085fe00 Show full comment, description or title 2025-11-17 09:12:17 -05:00
Stanko K.R. 2c3062fd86 Add a stemmer and highlighter 2025-11-17 09:12:17 -05:00