-
Notifications
You must be signed in to change notification settings - Fork 119
[POS FTS] 2: Add search index builder with rebuild and search #16595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pos/fts-1-schema-model-flag
Are you sure you want to change the base?
Conversation
Introduces POSSearchIndexBuilder with full-text search capabilities: - rebuildIndex: clears and re-indexes all eligible products and variations - search/searchCount: FTS5 queries with prefix matching and BM25 ranking - needsRebuild: detects when index is stale - buildFTSQuery: handles multi-word prefix search with special char escaping Adds posEligibleProductsRequest and posAllVariationsRequest to model types for index population queries. Includes comprehensive test suite. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Generated by 🚫 Danger |
|
|
|
|
||
| /// Returns a request for all non-downloadable variations for a site | ||
| static func posAllVariationsRequest(siteID: Int64) -> QueryInterfaceRequest<PersistedProductVariation> { | ||
| return PersistedProductVariation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use a baseQuery?
| ) | ||
|
|
||
| try db.execute( | ||
| sql: "INSERT INTO pos_search_fts (searchable_text, siteID, itemType, itemID, parentProductID) VALUES (?, ?, ?, ?, ?)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check injection risk
| // MARK: - Private | ||
|
|
||
| private static func buildFTSQuery(from term: String) -> String { | ||
| let words = term.components(separatedBy: CharacterSet.alphanumerics.inverted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check non-latin languages...
| let parentProduct = try PersistedProduct.fetchOne(db, key: ["siteID": siteID, "id": variation.productID]) | ||
|
|
||
| let attributes = try PersistedProductVariationAttribute | ||
| .filter(PersistedProductVariationAttribute.Columns.siteID == siteID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps a basequery?
| @Test("search finds variations by attribute") | ||
| func test_search_finds_variations_by_attribute() async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a duplicate test?
- Add baseQuery to PersistedProductVariation for consistency with PersistedProduct pattern (reviewer comment on posAllVariationsRequest) - Fix buildFTSQuery to handle CJK ideographs correctly by splitting each character individually, matching FTS5 unicode61 tokenizer behavior (reviewer comment about non-latin language support) - Extract tokenize function and add comprehensive tests for tokenization covering CJK, Japanese kana/kanji, Korean, Arabic, Hebrew, emoji Co-Authored-By: Claude Opus 4.5 <[email protected]>

Part of: WOOMOB-2109
Merge after #16594
Description
Introduces
POSSearchIndexBuilderwith:rebuildIndex: clears and re-indexes all eligible products and variations for a sitesearch/searchCount: FTS5 queries with prefix matching and BM25 rankingneedsRebuild: detects when the index is stale by comparing entry count to eligible itemsclearIndex: removes all FTS entries for a sitebuildFTSQuery: splits search terms on non-alphanumeric characters and wraps each word as a quoted prefix queryAlso adds
posEligibleProductsRequestonPersistedProductandposAllVariationsRequestonPersistedProductVariationfor index population queries.Includes comprehensive test suite (21 tests).
Test Steps
POSSearchIndexBuilderTests— all tests should passRELEASE-NOTES.txtif necessary.