feat: add fuzzy word-order independent item search#6
Merged
engahmed1190 merged 1 commit intoOct 24, 2025
Conversation
Contributor
Author
|
Fixes #5 |
Implement multi-word search that finds items regardless of search term word order. Searching for "Blue Large" now correctly finds "Large Blue Plastic Widget". Implementation details: Backend (pos_next/api/items.py): - Dual search strategy for optimal performance and compatibility 1. Primary: MySQL fulltext boolean mode (MATCH AGAINST) with relevance scoring 2. Fallback: Pattern-based LIKE search with AND logic between words - Each word in the search query must match at least one field (item_code, item_name, or description) - Words can appear in any order across any field - Added `_build_item_base_conditions()` helper to centralize filter logic - Extracted field list to `ITEM_RESULT_FIELDS` constant for reusability - Search term deduplication prevents redundant LIKE predicates - Alphanumeric normalization handles special characters in search terms - Prefix matching for words ≥3 chars (+word*) and exact match for shorter tokens - Limit boolean terms to 8 for query performance Frontend (POS/src/utils/offline/items.js): - Updated `searchCachedItems()` for consistent word-order independence - Single-word queries use optimized IndexedDB index lookups (startsWithIgnoreCase) - Multi-word queries filter JavaScript-side using Array.every() for AND logic - Searches across item_code, item_name, description, and barcodes fields - Fetches 5x limit for multi-word to ensure adequate filtered results Technical notes: - Boolean search depends on `search_index` fulltext index on Item doctype - LIKE search provides compatibility when fulltext fails or is unavailable - Both online and offline search use consistent word-order-independent logic Fixes issue where multi-word searches required exact phrase order.
c62e442 to
a03f89b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement multi-word search that finds items regardless of search term word order. Searching for "Blue Large" now correctly finds "Large Blue Plastic Widget".
Implementation details:
Backend (pos_next/api/items.py):
_build_item_base_conditions()helper to centralize filter logicITEM_RESULT_FIELDSconstant for reusabilityFrontend (POS/src/utils/offline/items.js):
searchCachedItems()for consistent word-order independenceTechnical notes:
search_indexfulltext index on Item doctypeFixes issue where multi-word searches required exact phrase order.