Clientes API
Theclientes_firestore.js module provides functions for managing customer records with intelligent text normalization and fuzzy search capabilities.
Functions
crearCliente
Creates a new customer record with automatic text normalization for efficient searching.Customer information
The created customer document ID
nombreNorm- Normalized name with spaces for prefix searchnombreCompact- Compacted name without spaces for fuzzy matching
actualizarCliente
Updates an existing customer record with automatic normalization.The customer document ID
Object containing fields to update (partial update supported)
- Automatically clears
numeroSeriePreferidowhenomitirNumeroSerieis set totrue - Regenerates normalized search fields if name changes
- Updates
updatedAttimestamp
buscarClientesSimilares
Searches for customers using fuzzy text matching with Levenshtein distance ranking.Search query (name or partial name)
Search configuration
Array of customer objects sorted by similarity (closest match first), with
_dist field indicating edit distance- Normalizes input text (removes accents, lowercases, handles camelCase)
- Performs prefix search on
nombreNormfield - Falls back to full collection scan for legacy records
- Ranks results using Levenshtein distance on compacted names
- Returns top matches sorted by similarity
listarClientes
Lists customers ordered by most recently updated.Array of customer objects ordered by
updatedAt (newest first)obtenerClientePorId
Retrieves a single customer by document ID.The customer document ID
Customer object with
id and all customer data, or null if not foundlistarServiciosPorClienteId
Lists all services associated with a specific customer.The customer document ID
Array of service objects for the specified customer, sorted by creation date (newest first)
Utility Functions
normalizarTexto
Normalizes text for searching by removing accents, lowercasing, and handling camelCase.Text to normalize
Normalized text with spaces, lowercase, no accents
compact
Compacts text by removing all spaces (useful for fuzzy matching).Text to compact
Normalized text without spaces
Data Structure
Each customer document contains:Search Implementation Details
The fuzzy search uses Levenshtein distance algorithm to calculate edit distance between strings:- Distance 0: Exact match
- Distance 1-2: Very similar (typo, missing letter)
- Distance 3-5: Moderately similar
- Distance 6+: Less similar
- Typos
- Missing accents
- Incomplete names
- Different spacing
