Skip to content

feat: add fuzzy word-order independent item search#6

Merged
engahmed1190 merged 1 commit into
developfrom
feature/fuzzy-word-order-independent-search
Oct 24, 2025
Merged

feat: add fuzzy word-order independent item search#6
engahmed1190 merged 1 commit into
developfrom
feature/fuzzy-word-order-independent-search

Conversation

@engahmed1190

Copy link
Copy Markdown
Contributor

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.

@engahmed1190

Copy link
Copy Markdown
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.
@engahmed1190 engahmed1190 force-pushed the feature/fuzzy-word-order-independent-search branch from c62e442 to a03f89b Compare October 24, 2025 18:40
@engahmed1190 engahmed1190 merged commit c8b05cd into develop Oct 24, 2025
1 of 3 checks passed
@engahmed1190 engahmed1190 deleted the feature/fuzzy-word-order-independent-search branch December 9, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant