A responsive fuzzy search method based on front-end lightweight recursive matching
By adopting a responsive fuzzy search method based on lightweight recursive matching on the front end, the problems of repetitive calculation and untimely response in the existing technology are solved. It realizes flexible fuzzy search and real-time updates, which is suitable for front-end scenarios such as table filtering and list search, and reduces computational overhead and dependency maintenance costs.
Patent Information
- Application Number
- CN202611346025.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-01
- Publication Date
- 2026-11-27
AI Technical Summary
Existing front-end fuzzy search methods suffer from high overhead of repetitive calculations and slow response times when search keywords are continuously entered or data sources change frequently. Furthermore, they cannot automatically switch matching modes based on user input, lack incremental filtering mechanisms, and are difficult to adapt to dynamic changes in data sources in a responsive manner.
A responsive fuzzy search method based on lightweight recursive matching at the front end is adopted. The target matching pattern is automatically determined by delimiter and pattern mapping table. Nested path recursively retrieves values and matches array elements one by one. Combined with incremental filtering mechanism and responsive listening mechanism, it can achieve deep coverage and real-time updates of complex data structures.
It significantly reduces computational overhead, ensures real-time consistency and flexibility of search results, improves search response speed and adaptability, and reduces front-end package size and dependency maintenance costs.
Smart Images

Figure CN123178476A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Web front-end data retrieval and responsive data processing technology, specifically to a responsive fuzzy search method based on lightweight recursive matching on the front end. Background Technology
[0002] Fuzzy search technology is a commonly used data filtering technique in web front-end business systems. It filters structured data such as tables, dropdown options, card lists, and tree-like data in real time based on user-input keywords, retaining matching data items. With the widespread adoption of responsive front-end frameworks, both data sources and search criteria change dynamically, requiring search results to update automatically. This places higher demands on the real-time performance of search methods, the determinism of matching rules, and ease of integration.
[0003] Existing methods typically implement front-end search by introducing third-party fuzzy search libraries. Among them, fuzzy scoring methods build an index for the data source, calculate the similarity score between keywords and field values based on algorithms such as edit distance, filter by threshold, and output in sorted order; component library built-in filtering methods rely on the filtering interface provided by the UI component library to perform substring inclusion matching on single fields; native script direct matching methods call the string inclusion function of the scripting language to traverse the data array item by item to determine the match.
[0004] However, the above methods have the following problems: fuzzy scoring methods increase the size of the front-end package and the cost of dependency maintenance; the scoring results are uncertain and it is difficult to meet the deterministic requirement that "keywords must appear in field values"; the deep encapsulation of the library leads to high customization and modification costs; and index building has no advantage for small and medium-sized data volumes. Rebuilding the index when the data changes frequently introduces additional overhead; the built-in filtering methods of the component library have limited capabilities and cannot support requirements such as multi-keyword combination matching and hit information marking; the native script direct matching methods lack systematic design such as multi-keyword parsing, nested path value retrieval, incremental filtering and responsive linkage, making it difficult to directly integrate into responsive data streams.
[0005] Therefore, a new front-end fuzzy search method is urgently needed to solve the above-mentioned technical problems. Summary of the Invention
[0006] This application aims to address the problems of high computational overhead and untimely search response caused by repeated full traversal matching in front-end fuzzy search scenarios where search keywords are continuously entered or data sources change frequently. It also addresses the issues of traditional solutions failing to automatically switch matching modes based on user input separators, lacking incremental filtering mechanisms, and being unable to responsively adapt to dynamic changes in data sources.
[0007] To achieve this objective, the present invention adopts the following technical solution:
[0008] A responsive fuzzy search method based on lightweight recursive matching at the front end includes the following steps:
[0009] S101. Obtain a search request and a data source, and preprocess the search keywords in the search request to obtain standardized keywords; wherein, the search request also includes field configuration information, which is used to indicate the fields to be matched in the data source;
[0010] S102. Perform multi-keyword parsing on the standardized keywords: Normalize the separators in the standardized keywords, split the standardized keywords according to the normalized separators, and filter out empty words to obtain a search term sequence; query a preset separator-pattern mapping table according to the type of separator used for splitting to determine the target matching pattern corresponding to the search term sequence; wherein, the target matching pattern is any one of AND pattern, OR pattern, or PHRASE pattern; when the standardized keywords contain multiple separators, determine the target matching pattern according to a preset priority, wherein the priority is quotation marks over commas, and commas over spaces; if there are no separators in the standardized keywords, then the preset default matching pattern is determined as the target matching pattern, wherein the preset default matching pattern is AND pattern;
[0011] S103. Traverse each data object in the data source in a linear scan manner, and take the values of each field to be matched in the current data object according to the field configuration information to obtain the set of field values corresponding to the current data object; wherein, when the field to be matched is a nested field, take the value layer by layer along the nesting path indicated by the field configuration information; determine the obtained field value as the matching object, and when the obtained field value is an array type, determine each array element in the field value as the matching object respectively;
[0012] S104. For each matching object in the set of field values, perform inclusion matching or regular expression matching one by one with each search term in the search term sequence to obtain the matching result of each search term on each field to be matched; wherein, the inclusion matching is performed on the matching object after case normalization, and the regular expression matching is performed on the original matching object without case normalization; when any array element of the same field to be matched is matched, it is determined that the field to be matched is matched, and the matching of the remaining array elements of the field to be matched is stopped;
[0013] S105. Based on the target matching mode and the matching result, determine whether each data object is matched, and obtain a set of matched objects; wherein, when the target matching mode is AND mode, the data object is determined to be matched when all search terms corresponding to the data object are matched; when the target matching mode is OR mode, the data object is determined to be matched when any search term corresponding to the data object is matched; when the target matching mode is PHRASE mode, the search terms in the search term sequence are connected in their original order with a standard delimiter to form a target phrase, and the data object is determined to be matched when any matching object of the data object contains the target phrase; wherein, after determining that the data object is matched according to the target matching mode, the matching of the remaining fields to be matched for the data object is stopped;
[0014] S106. Scoring and sorting each hit data object in the hit object set: Calculate the score of each hit data object based on the preset field weight of each hit field to be matched, the hit position of the search term and the number of hits, and sort each hit data object according to the score to obtain the sorted hit object set.
[0015] S107. Mark each hit data object in the sorted hit object set with hit information, and output the marked hit object set as a fuzzy search result to the front-end view for rendering and display; wherein, the hit information includes the hit field to be matched, the hit search term, and the hit position, and the hit information is used for the front-end view to highlight and display.
[0016] S108. Monitor the data source and the search request through a responsive monitoring mechanism; when the data source and / or the search request changes, re-execute steps S101 to S107 based on the changed data source and / or search request to obtain updated fuzzy search results and output them to the front-end view rendering display, thereby obtaining fuzzy search results that respond to data changes.
[0017] Furthermore, obtaining the search request in step S101 specifically involves: receiving the original search string input by the user on the front-end interface, and performing preprocessing on the original search string to obtain the standardized keywords; wherein, the preprocessing includes case normalization, trimming of leading and trailing spaces, and normalization of consecutive spaces; the field configuration information includes a whitelist of specified fields or a full-field search identifier.
[0018] Furthermore, step S102, which involves determining the target matching pattern according to a preset delimiter-pattern mapping table, includes the following sub-steps:
[0019] The various delimiters in the standardized keywords are unified and normalized into standard delimiters;
[0020] The standardized keywords are split according to the standard delimiter to obtain a search term sequence;
[0021] Query the preset delimiter-pattern mapping table, and determine the target matching pattern according to the delimiter type used for splitting, wherein in the mapping table, a space corresponds to the AND pattern, a comma corresponds to the OR pattern, a semicolon corresponds to the OR pattern, and a quotation mark corresponds to the PHRASE pattern;
[0022] When the standardized keyword does not contain any separators, the target matching mode is determined to be the preset default mode, which is the AND mode.
[0023] Furthermore, in step S103, the values of each field to be matched in the current data object are retrieved according to the field configuration information, specifically as follows:
[0024] When the field configuration information contains a whitelist of specified fields, the value retrieval operation is performed only on the fields specified in the whitelist.
[0025] When the field configuration information contains a full-field search identifier, all fields of the data object are automatically traversed;
[0026] For fields containing nested paths separated by dots, parse the path nodes layer by layer and retrieve their values sequentially until the values of the leaf nodes are obtained;
[0027] When the result is an array, each element in the array is treated as an independent matching object and participates in subsequent matching.
[0028] Furthermore, in step S104, for each matching object in the set of field values, an inclusion match or regular expression match is performed one by one with each search term in the search term sequence, specifically as follows:
[0029] For each of the matched objects, character normalization processing is performed, which includes case conversion and full-width character to half-width character conversion.
[0030] Perform string inclusion matching between the normalized matching object and each of the search terms;
[0031] When the search request specifies that regular expression matching is enabled, the search term is compiled into a regular expression and regular expression matching is performed. During the regular expression compilation process, a maximum length limit for the regular expression is set. If a compilation error occurs or the maximum length limit is exceeded, the matching is automatically downgraded to string inclusion matching.
[0032] Furthermore, in step S105, the matching results of each search term are combined and determined according to the target matching pattern, specifically as follows:
[0033] When the target matching mode is AND mode, each search term in the search term sequence is required to hit at least one field to be matched in the current data object before the current data object is determined to be a matched object.
[0034] When the target matching mode is OR mode, at least one search term in the search term sequence must hit at least one field to be matched in the current data object in order to determine that the current data object is a matched object.
[0035] When the target matching mode is PHRASE mode, at least one field value of the current data object is required to contain a complete phrase consisting of all search terms connected in their original order by a standard delimiter in order to determine that the current data object is a hit object.
[0036] Furthermore, step S106, which involves scoring and sorting the set of hit objects, specifically involves:
[0037] Calculate the field weight score based on the preset weight value of the hit field in each hit object;
[0038] The hit position score is calculated based on the starting position of the matching keyword in the field value of each hit object, and the earlier the starting position, the higher the score.
[0039] The hit count score is calculated based on the number of times the search term is hit in each hit object. The number of times the search term is hit is the number of hits recorded within the scanned range up to the time when the short circuit stops matching.
[0040] The total field weight score is obtained by summing the field weight scores of each hit field to be matched, and the total hit position score is obtained by taking the maximum value of the hit position score of each hit position. The total field weight score, the total hit position score and the hit count score are weighted and summed to obtain the comprehensive score of each hit object.
[0041] The set of hit objects is sorted from highest to lowest according to the comprehensive score.
[0042] Furthermore, after obtaining the standardized keywords in step S101, an incremental filtering step is also included, specifically:
[0043] Determine whether the current input keyword meets the incremental filtering activation conditions compared to the previously input keyword. The activation conditions include: regular expression matching is not currently enabled, the current keyword is prefixed with the previous keyword and its length has increased, the target matching mode has not changed, the field configuration has not changed, the data source has not changed, and the current keyword does not cross a separator and the number of search terms has not increased.
[0044] When the aforementioned activation conditions are met, filtering continues based on the set of hit objects obtained in the previous round of search;
[0045] When the target matching mode is OR mode and the current keyword crosses the separator to generate a new search term, the set of hit objects from the previous round is retained, and the new search term is used to perform matching only on the complement data that was not hit in the previous round, and the matching result is merged with the set of hit objects from the previous round.
[0046] If the activation conditions are not met and the above OR pattern complement set is not included, the process reverts to re-execute steps S103 to S106 on the complete data source.
[0047] Furthermore, the mark-hit information in step S107 specifically involves recording the hit field identifier, hit keyword identifier, and hit position information for the hit field in each hit object. The hit position information includes the start offset and end offset of the keyword in the field value, so that the front-end view can perform keyword highlight rendering based on the hit position information.
[0048] Furthermore, the reactive listening in step S108 specifically includes:
[0049] Dependency tracking for the data source and the search request is registered through the listener mechanism of the reactive framework;
[0050] When the addition, deletion or change of the data source is detected, or the keyword or field configuration in the search request is updated, the re-execution of steps S101 to S107 is automatically triggered;
[0051] During the re-execution process, if the conditions for incremental filtering to take effect are met, incremental filtering will be executed; otherwise, a full recalculation will be performed, and the updated fuzzy search results will be synchronized to the front-end view.
[0052] The technical solution provided by this invention can include the following beneficial effects: It automatically determines the target matching pattern through a delimiter and pattern mapping table, eliminating the need for manual switching by the user and improving search flexibility; it achieves deep coverage of complex data structures by recursively matching nested path values with array elements one by one; it reuses the previous round of hit sets when appending keywords through an incremental filtering mechanism, avoiding full recalculation and significantly reducing computational overhead; and it automatically senses changes in the data source and search request and triggers recalculation through a reactive listening mechanism, ensuring real-time consistency of search results. Attached Figure Description
[0053] Figure 1 This is a flowchart of the steps of the responsive fuzzy search method based on front-end lightweight recursive matching provided in the embodiments of the present invention. Detailed Implementation
[0054] The present invention will be further illustrated below with reference to specific embodiments. It should be understood that the specific embodiments described herein are for illustrative and explanatory purposes only and are not intended to limit the present invention.
[0055] This implementation can be applied to front-end scenarios such as table filtering, list searching, dropdown option filtering, data card retrieval, tree-structured data fragment filtering, configuration item list filtering, and enumeration item set retrieval. The data source can be an array of ordinary objects, and each data object can contain strings, numbers, booleans, null values, arrays, nested objects, and mixed structure fields.
[0056] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating the steps of a responsive fuzzy search method based on lightweight recursive matching provided in this invention. The responsive fuzzy search method based on lightweight recursive matching includes the following steps:
[0057] In one implementation, the above method can be executed collaboratively by a search parameter input module, a keyword preprocessing module, a multi-keyword parsing module, a nested path value retrieval module, a recursive matching module, an object filtering and scoring module, a hit information marking module, a regular expression security protection module, a caching and incremental optimization module, a responsive monitoring module, and a result output module. The search parameter input module receives the data source and search configuration; the keyword preprocessing module and the multi-keyword parsing module standardize the input content; the nested path value retrieval module and the recursive matching module read and match field values; the object filtering and scoring module generates hit results; the hit information marking module records hit details; the regular expression security protection module, the caching and incremental optimization module, and the responsive monitoring module respectively perform anomaly protection, computation reuse, and automatic updating; and the result output module outputs the filtered results to the front-end view.
[0058] The aforementioned multi-keyword parsing, nested path retrieval, recursive matching, regular expression safety protection, lightweight scoring, hit marking, caching optimization, and reactive updates are all integrated into a unified search execution process, rather than existing as separate external extensions. Since the matching process is executed by a custom front-end module, there is no need to import third-party search libraries. The matching rules are transparent and easy to debug, and the front-end package size and dependency maintenance overhead are reduced.
[0059] S101. Obtain the search request and data source, and preprocess the search keywords in the search request to obtain standardized keywords; wherein, the search request also includes field configuration information, which is used to indicate the fields to be matched in the data source.
[0060] In one implementation, the search request can be represented using a SearchOptions structure. The SearchOptions structure includes keyword, keys, and isRegex, where keyword represents the user-input search terms, keys represents an optional whitelist of fields, and isRegex indicates whether regular expression matching is enabled. When keys is empty, all field values of the current data object can be searched. This input structure allows the same search logic to be reused across multiple front-end pages and various data lists.
[0061] Step S101, by preprocessing the search keywords, can avoid invalid traversal triggered by blank input and ensure that subsequent fields are matched according to a unified standard.
[0062] S102. Perform multi-keyword parsing on the standardized keywords: Normalize the separators in the standardized keywords, split the standardized keywords according to the normalized separators, and filter out empty words to obtain a search term sequence; query a preset separator-pattern mapping table according to the type of separator used for splitting to determine the target matching pattern corresponding to the search term sequence; wherein, the target matching pattern is any one of AND pattern, OR pattern, or PHRASE pattern; when the standardized keywords contain multiple separators, determine the target matching pattern according to a preset priority, wherein the priority is quotation marks over commas, and commas over spaces; if there are no separators in the standardized keywords, then the preset default matching pattern is determined as the target matching pattern, wherein the preset default matching pattern is AND pattern.
[0063] The multi-keyword parsing is used to parse a single input into one or more search terms, and determine the combination relationship between these search terms through target matching patterns. Spaces, commas, semicolons, and other separators can first undergo normalization processing, and then the mapping table is queried based on the separator type. The target matching pattern corresponding to a semicolon is the OR pattern, consistent with that of a comma. When a standardized keyword contains multiple separators simultaneously, the target matching pattern is determined according to a preset priority, with quotation marks taking precedence over commas, and commas taking precedence over spaces. By separating separator normalization and pattern querying, separator recognition rules and matching combination rules can be maintained separately.
[0064] S103. Traverse each data object in the data source in a linear scan manner, and take the values of each field to be matched in the current data object according to the field configuration information to obtain the set of field values corresponding to the current data object; wherein, when the field to be matched is a nested field, take the value layer by layer along the nesting path indicated by the field configuration information; determine the obtained field value as the matching object, and when the obtained field value is an array type, determine each array element in the field value as the matching object respectively.
[0065] In one implementation, nested paths can be represented using dot-separated field paths. For example, field configuration information may include user.name, user.department.title, and tags. The nested path value retrieval module first determines whether the field configuration contains path separators. If not, it directly reads the first-level attribute of the data object; if it does, it reads the attributes of the data object layer by layer according to the path fragments. When any intermediate layer is empty, it returns an empty value and determines that the path is not matched. When the final value obtained is an array or object, it is passed to the subsequent recursive matching process for processing. In this way, ordinary objects, nested objects, array fields, and mixed structure fields can all enter a unified matching process.
[0066] S104. For each matching object in the set of field values, perform inclusion matching or regular expression matching one by one with each search term in the search term sequence to obtain the matching result of each search term on each field to be matched; wherein, the inclusion matching is performed on the matching object after case normalization, and the regular expression matching is performed on the original matching object without case normalization; when any array element of the same field to be matched is matched, it is determined that the field to be matched is matched, and the matching of the remaining array elements of the field to be matched is stopped.
[0067] The recursive matching process in step S104 may include the following rules: If the matching object is null or undefined, it is determined to be a mismatch; if the matching object is an array, each element in the array is traversed and the matching logic is recursively called. When any element matches successfully, the current array field is determined to be a successful match; if the matching object is a string, number, or boolean value or other ordinary type, the matching object is first converted to a string, then uniformly converted to lowercase and inclusion matching is performed, or regular expression matching is performed based on the original string; if the matching object is a nested object that has not been pre-expanded through the nested path, it does not directly participate in string matching and is determined to be a mismatch. The nested object should be retrieved by the nested path value retrieval module according to the path before matching.
[0068] By using the above recursive matching rules, various business data formats such as strings, numbers, booleans, arrays, mixed arrays, and null values can adopt a unified judgment entry point, reducing the need to write matching logic for each data type separately.
[0069] S105. Based on the target matching mode and the matching result, determine whether each data object is matched, and obtain a set of matched objects; wherein, when the target matching mode is AND mode, the data object is determined to be matched when all search terms corresponding to the data object are matched; when the target matching mode is OR mode, the data object is determined to be matched when any search term corresponding to the data object is matched; when the target matching mode is PHRASE mode, the search terms in the search term sequence are connected in their original order with a standard delimiter to form a target phrase, and the data object is determined to be matched when any matching object of the data object contains the target phrase; wherein, after determining that the data object is matched according to the target matching mode, the matching of the remaining fields to be matched for the data object is stopped.
[0070] When making a combination judgment, the hit status of each search term on the current data object can be determined first, and then the hit status of each search term can be combined according to the target matching pattern. For a single search term, when the search term hits any of the fields to be matched, it can be determined that the search term has hit the current data object, and the checking of the remaining fields to be matched by the search term in the current data object can be stopped. For the AND mode, each search term needs to hit the current data object separately, and each search term can hit different fields to be matched; for the OR mode, any search term only needs to hit the current data object; for the PHRASE mode, the current data object needs to contain the complete phrase.
[0071] S106. Scoring and sorting each hit data object in the hit object set: Calculate the score of each hit data object based on the preset field weight of each hit field to be matched, the hit position of the search term, and the number of hits, and sort each hit data object according to the score to obtain the sorted hit object set.
[0072] In one implementation, the hit determination phase employs a short-circuit strategy in both scenarios where sorting is required and those where it is not. Once a matching field is determined to meet the hit condition, the remaining matching fields of the current data object are no longer checked. For scenarios requiring sorting, after a short-circuit hit, a lightweight score is calculated and sorted based on the recorded hit fields, hit positions, and hit counts. For scenarios where sorting is not required, the filtering result is returned directly after a short-circuit hit, without performing score calculation. Whether sorting is enabled only affects the scoring and sorting phases after the hit determination, and does not affect the short-circuit strategy in the hit determination phase.
[0073] The preset field weights can be set according to the importance of the fields in the business display. For example, key fields such as title, name, and code have a higher weight than auxiliary fields such as remarks and description. The earlier a keyword appears, the higher its position score; the more times it is hit, the higher its frequency score. The number of times a search term is hit is the number of hits recorded within the scanned range up to the point where short-circuiting stops matching. Through this lightweight scoring, more relevant data items can be prioritized for display without introducing complex full-text relevance algorithms.
[0074] S107. Mark each hit data object in the sorted hit object set with hit information, and output the marked hit object set as a fuzzy search result to the front-end view for rendering and display; wherein, the hit information includes the hit field to be matched, the hit search term, and the hit position, and the hit information is used for the front-end view to highlight and display.
[0075] In one implementation, the output fuzzy search results can be represented using a SearchResult structure. The SearchResult structure includes item, matched, matchedKeys, matchedKeywords, and score, where item represents the original data item, matched indicates whether a match was found, matchedKeys represents the matched fields or nested paths, matchedKeywords represents the matched keywords, and score represents a lightweight relevance score. This result structure allows search results to be used for list filtering, page highlighting, match descriptions, and sorting criteria display.
[0076] S108. Monitor the data source and the search request through a responsive monitoring mechanism; when the data source and / or the search request changes, re-execute steps S101 to S107 based on the changed data source and / or search request to obtain updated fuzzy search results and output them to the front-end view rendering display, thereby obtaining fuzzy search results that respond to data changes.
[0077] In one implementation, the reactive listener module can receive a reactive data source or a regular array, and can also receive a reactive search configuration or a regular configuration object. The reactive listener module unpacks the input values into their raw values, performs filtering immediately upon initialization, and re-executes filtering whenever the data source, keywords, field configurations, matching patterns, or regular expression configurations change, outputting a reactive filtered result list for direct rendering by the view layer. In this way, the search logic can be applied as a reusable hook or utility function to multiple pages.
[0078] Furthermore, obtaining the search request in step S101 specifically involves: receiving the original search string input by the user on the front-end interface, and performing preprocessing on the original search string to obtain the standardized keywords; wherein, the preprocessing includes case normalization, trimming of leading and trailing spaces, and normalization of consecutive spaces; the field configuration information includes a whitelist of specified fields or a full-field search identifier.
[0079] In one implementation, keyword preprocessing also includes determining if a keyword is empty and optionally escaping special characters. If a keyword is empty, the original data source list is returned directly, avoiding meaningless traversal. A unified textualization strategy is used for Chinese, English, numbers, encoded values, and enumerated values, enabling different field types to use the same matching process. Optional escaping of special characters can prevent ordinary searches from accidentally triggering regular expression semantics. Keyword preprocessing can reduce redundant calculations in subsequent matching processes and ensure that different fields use a unified matching standard.
[0080] Furthermore, step S102, which involves determining the target matching pattern according to a preset delimiter-pattern mapping table, includes the following sub-steps:
[0081] The various delimiters in the standardized keywords are unified and normalized into standard delimiters;
[0082] The standardized keywords are split according to the standard delimiter to obtain a search term sequence;
[0083] Query the preset delimiter-pattern mapping table, and determine the target matching pattern according to the delimiter type used for splitting, wherein in the mapping table, a space corresponds to the AND pattern, a comma corresponds to the OR pattern, a semicolon corresponds to the OR pattern, and a quotation mark corresponds to the PHRASE pattern;
[0084] When the standardized keyword does not contain any separators, the target matching mode is determined to be the preset default mode, which is the AND mode.
[0085] The mapping table decouples user input habits from the target matching pattern. When it is necessary to adjust the matching pattern corresponding to a certain delimiter, only the corresponding relationship in the mapping table needs to be adjusted, without changing the field values, recursive matching, and object filtering process. When the standardized keyword contains multiple delimiters, the target matching pattern is determined according to a preset priority, where quotation marks take precedence over commas, and commas take precedence over spaces.
[0086] Furthermore, in step S103, the values of each field to be matched in the current data object are retrieved according to the field configuration information, specifically as follows:
[0087] When the field configuration information contains a whitelist of specified fields, the value retrieval operation is performed only on the fields specified in the whitelist.
[0088] When the field configuration information contains a full-field search identifier, all fields of the data object are automatically traversed;
[0089] For fields containing nested paths separated by dots, parse the path nodes layer by layer and retrieve their values sequentially until the values of the leaf nodes are obtained;
[0090] When the result is an array, each element in the array is treated as an independent matching object and participates in subsequent matching.
[0091] When the field configuration information includes a full-field search flag, the system automatically iterates through each first-level field of the current data object. For nested objects that are not pre-expanded using a nesting path, string matching is not performed directly on those nested objects. If you need to search for attributes within a nested object, you can configure the corresponding nesting path in the field whitelist. This approach clearly defines the boundaries of the full-field search and avoids performing unpredictable string conversions on complex nested objects during the traversal process.
[0092] Furthermore, in step S104, for each matching object in the set of field values, an inclusion match or regular expression match is performed one by one with each search term in the search term sequence, specifically as follows:
[0093] For each of the matched objects, character normalization processing is performed, which includes case conversion and full-width character to half-width character conversion.
[0094] Perform string inclusion matching between the normalized matching object and each of the search terms;
[0095] When the search request specifies that regular expression matching is enabled, the search term is compiled into a regular expression and regular expression matching is performed. During the regular expression compilation process, a maximum length limit for the regular expression is set. If a compilation error occurs or the maximum length limit is exceeded, the matching is automatically downgraded to string inclusion matching.
[0096] In one implementation, regular expression matching is disabled by default and is only used when explicitly enabled in the search request. The regular expression security protection module limits the length of the regular expression input by the user, provides optional escaping capabilities for special characters, catches exceptions when regular expression construction fails, and automatically downgrades to ordinary containment matching when construction fails. The regular expression security protection module can also monitor the matching time. When the time exceeds a preset threshold, subsequent matches are rolled back to ordinary containment matching, and the results of each regular expression construction are temporarily reused to avoid repeatedly constructing the same regular expression.
[0097] Regular expression patterns are suitable for scenarios where matching is based on patterns rather than literal content. For example, `^EMP-` can be used to match employee IDs that begin with `EMP-`, `^\d{6}$` can be used to match order numbers that are exactly six digits long, `pending|processing|done` can be used to match any status value, and `\d{4}-\d{2}-\d{2}` can be used to match date format strings. If the above regular expression is invalid or fails to be constructed, it will automatically fall back to a normal containment match to avoid interrupting the search process due to abnormal user input.
[0098] Furthermore, the step S105, which combines and determines the matching results of each search term according to the target matching pattern, specifically involves:
[0099] When the target matching mode is AND mode, each search term in the search term sequence is required to hit at least one field to be matched in the current data object before the current data object is determined to be a matched object.
[0100] When the target matching mode is OR mode, at least one search term in the search term sequence must hit at least one field to be matched in the current data object in order to determine that the current data object is a matched object.
[0101] When the target matching mode is PHRASE mode, at least one field value of the current data object is required to contain a complete phrase consisting of all search terms connected in their original order by a standard delimiter in order to determine that the current data object is a hit object.
[0102] By combining multi-keyword combination results with field matching results, a single search box can cover scenarios involving multiple words in parallel, multiple words selected, and complete phrase matching, while maintaining consistent processing rules for each search term during the field-level matching process.
[0103] Furthermore, step S106, which involves scoring and sorting the set of hit objects, specifically involves:
[0104] Calculate the field weight score based on the preset weight value of the hit field in each hit object;
[0105] The hit position score is calculated based on the starting position of the matching keyword in the field value of each hit object, and the earlier the starting position, the higher the score.
[0106] The hit count score is calculated based on the number of times the search term is hit in each hit object. The number of times the search term is hit is the number of hits recorded within the scanned range up to the time when the short circuit stops matching.
[0107] The total field weight score is obtained by summing the field weight scores of each hit field to be matched, and the total hit position score is obtained by taking the maximum value of the hit position score of each hit position. The total field weight score, the total hit position score and the hit count score are weighted and summed to obtain the comprehensive score of each hit object.
[0108] The set of hit objects is sorted from highest to lowest according to the comprehensive score.
[0109] The above-mentioned ranking is a lightweight ranking. Its purpose is not to build complex indexes or perform large-scale full-text relevance calculations, but to adjust the display order of data objects that have already been definitively matched, based on field importance, keyword position, and number of matches.
[0110] Furthermore, after obtaining the standardized keywords in step S101, an incremental filtering step is also included, specifically:
[0111] Determine whether the current input keyword meets the incremental filtering activation conditions compared to the previously input keyword. The activation conditions include: regular expression matching is not currently enabled, the current keyword is prefixed with the previous keyword and its length has increased, the target matching mode has not changed, the field configuration has not changed, the data source has not changed, and the current keyword does not cross a separator and the number of search terms has not increased.
[0112] When the said activation condition is satisfied, filtering is continuously performed on the basis of the hit object set obtained in the previous round of search;
[0113] When the target matching mode is the OR mode and the current keyword crosses a delimiter to generate a new search term, the hit object set of the previous round is retained, only the complement data that was not hit in the previous round is matched using the said new search term, and the matching result is merged with the hit object set of the previous round;
[0114] When the said activation condition is not satisfied and the above OR mode complement merging situation does not apply, the process returns to re-executing steps S103 to S106 on the complete data source.
[0115] In one embodiment, the caching and incremental optimization module may cache field stringization results and field lowercasing results to avoid repeated type conversion and case conversion during each search. When the data source remains unchanged and only the keyword changes, the field expansion result can be reused. Incremental input means that a new keyword continues to append characters on the basis of the previous keyword, with the new keyword using the previous keyword as a prefix and having an increased length, for example, first inputting "搜" (search), then inputting "搜索" (search), and continuing to input "搜索框" (search box).
[0116] It should be noted that the absence of crossing a delimiter and the unchanged number of search terms are the premise of subset-based incremental filtering that continues to narrow the result range on the basis of the hit object set of the previous round. When the target matching mode is the OR mode and the current keyword crosses a delimiter to generate a new search term, since the new search term may hit data items that were not hit in the previous round, the method of only filtering within the hit object set of the previous round is not adopted. Instead, the hit object set of the previous round is retained, only the complement data that was not hit in the previous round is matched using the new search term, and the newly hit result is merged with the hit object set of the previous round. This merged incremental update path is parallel to the subset-based incremental filtering path, and only when neither of the two incremental update paths is satisfied does the process return to recalculating on the complete data source.
[0117] When the new keyword and the previous keyword do not satisfy the prefix relationship, or character deletion, intermediate insertion, character replacement, keyword shortening, matching mode change, field configuration change, or data source change occurs, the process automatically returns to recalculating on the complete data source. When regular expression matching is enabled, since regular expression matching does not satisfy the property that the hit set monotonically contracts with prefix growth, the process also returns to recalculating on the complete data source. When the data source changes, the old cache is cleared and a lightweight field cache is rebuilt. Through caching and incremental filtering, repeated type conversion and repeated full traversal during continuous input search can be reduced.
[0118] Furthermore, the mark-hit information in step S107 specifically involves recording the hit field identifier, hit keyword identifier, and hit position information for the hit field in each hit object. The hit position information includes the start offset and end offset of the keyword in the field value, so that the front-end view can perform keyword highlight rendering based on the hit position information.
[0119] By recording the hit fields, hit keywords, hit positions, and scores, the front-end view can accurately determine the fields and text ranges that need to be highlighted, and the debugging process can trace the reason why each data object is retained.
[0120] Furthermore, the reactive listening in step S108 specifically includes:
[0121] Dependency tracking for the data source and the search request is registered through the listener mechanism of the reactive framework;
[0122] When the addition, deletion or change of the data source is detected, or the keyword or field configuration in the search request is updated, the re-execution of steps S101 to S107 is automatically triggered;
[0123] During the re-execution process, if the conditions for incremental filtering to take effect are met, incremental filtering will be executed; otherwise, a full recalculation will be performed, and the updated fuzzy search results will be synchronized to the front-end view.
[0124] With the reactive listening mechanism, changes in data sources and search criteria can automatically trigger updates to the filter results. Business pages do not need to write separate logic for data change listening, search instance reconstruction, and result synchronization, thereby reducing redundant encapsulation when integrating search functionality with a responsive front-end framework.
[0125] In one implementation, the basic filtering complexity can be expressed as O(n×m×k), where n represents the number of data items, m represents the number of fields involved in the search for each data item, and k represents the length of the field value string or the average matching cost after array expansion. For data volumes within the thousands or tens of thousands, if the number of fields is limited and the field text is short, this complexity can meet the real-time search requirements of the front end. Due to the short-circuit strategy used after a match, the actual average time consumption is lower than the worst case.
[0126] Compared to index-based search methods, this implementation eliminates steps such as search instance initialization, index building, and complex scoring and sorting. In simple containment matching scenarios with frequent data source changes, few search fields, and short keywords, lightweight linear scans can achieve more direct performance improvements.
[0127] In other implementations, when the data volume increases but the search still needs to be performed on the front end, the filtering logic can be migrated to a Web Worker to avoid blocking the front end's main thread during the search process. This alternative implementation can still reuse the aforementioned keyword preprocessing, nested path retrieval, recursive matching, regular expression security protection, caching and incremental optimization, and result labeling processes.
[0128] The technical solution provided by this invention can include the following beneficial effects: It automatically determines the target matching pattern through a delimiter and pattern mapping table, eliminating the need for manual switching by the user and improving search flexibility; it achieves deep coverage of complex data structures by recursively matching nested path values with array elements one by one; it reuses the previous round of hit sets when appending keywords through an incremental filtering mechanism, avoiding full recalculation and significantly reducing computational overhead; and it automatically senses changes in the data source and search request and triggers recalculation through a reactive listening mechanism, ensuring real-time consistency of search results.
[0129] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0130] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0131] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as read-only memory / random access memory, magnetic disk, optical disk) and includes several instructions to cause a multimedia terminal device (which may be a mobile phone, computer, television receiver, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0132] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A responsive fuzzy search method based on lightweight recursive matching at the front end, characterized in that, Includes the following steps: S101. Obtain a search request and a data source, and preprocess the search keywords in the search request to obtain standardized keywords; wherein, the search request also includes field configuration information, which is used to indicate the fields to be matched in the data source; S102. Perform multi-keyword parsing on the standardized keywords: Normalize the separators in the standardized keywords, split the standardized keywords according to the normalized separators, and filter out empty words to obtain a search term sequence; query a preset separator-pattern mapping table according to the type of separator used for splitting to determine the target matching pattern corresponding to the search term sequence; wherein, the target matching pattern is any one of AND pattern, OR pattern, or PHRASE pattern; when the standardized keywords contain multiple separators, determine the target matching pattern according to a preset priority, wherein the priority is quotation marks over commas, and commas over spaces; if there are no separators in the standardized keywords, then the preset default matching pattern is determined as the target matching pattern, wherein the preset default matching pattern is AND pattern; S103. Traverse each data object in the data source in a linear scan manner, and take the values of each field to be matched in the current data object according to the field configuration information to obtain the set of field values corresponding to the current data object; wherein, when the field to be matched is a nested field, take the value layer by layer along the nesting path indicated by the field configuration information; determine the obtained field value as the matching object, and when the obtained field value is an array type, determine each array element in the field value as the matching object respectively; S104. For each matching object in the set of field values, perform inclusion matching or regular expression matching one by one with each search term in the search term sequence to obtain the matching result of each search term on each field to be matched; wherein, the inclusion matching is performed on the matching object after case normalization, and the regular expression matching is performed on the original matching object without case normalization; when any array element of the same field to be matched is matched, it is determined that the field to be matched is matched, and the matching of the remaining array elements of the field to be matched is stopped; S105. Based on the target matching mode and the matching result, determine whether each data object is matched, and obtain a set of matched objects; wherein, when the target matching mode is AND mode, the data object is determined to be matched when all search terms corresponding to the data object are matched; when the target matching mode is OR mode, the data object is determined to be matched when any search term corresponding to the data object is matched; when the target matching mode is PHRASE mode, the search terms in the search term sequence are connected in their original order with a standard delimiter to form a target phrase, and the data object is determined to be matched when any matching object of the data object contains the target phrase; wherein, after determining that the data object is matched according to the target matching mode, the matching of the remaining fields to be matched for the data object is stopped; S106. Scoring and sorting each hit data object in the hit object set: Calculate the score of each hit data object based on the preset field weight of each hit field to be matched, the hit position of the search term and the number of hits, and sort each hit data object according to the score to obtain the sorted hit object set. S107. Mark each hit data object in the sorted hit object set with hit information, and output the marked hit object set as a fuzzy search result to the front-end view for rendering and display; wherein, the hit information includes the hit field to be matched, the hit search term, and the hit position, and the hit information is used for the front-end view to highlight and display. S108. Monitor the data source and the search request through a responsive monitoring mechanism; when the data source and / or the search request changes, re-execute steps S101 to S107 based on the changed data source and / or search request to obtain updated fuzzy search results and output them to the front-end view rendering display, thereby obtaining fuzzy search results that respond to data changes.
2. The responsive fuzzy search method based on lightweight recursive matching at the front end as described in claim 1, characterized in that, The step S101 of obtaining the search request specifically involves: receiving the original search string input by the user on the front-end interface, and performing preprocessing on the original search string to obtain the standardized keywords; wherein, the preprocessing includes case normalization, trimming of leading and trailing spaces, and normalization of consecutive spaces; the field configuration information includes a whitelist of specified fields or a full-field search identifier.
3. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, Step S102, which involves determining the target matching pattern according to a preset delimiter-pattern mapping table, includes the following sub-steps: The various delimiters in the standardized keywords are unified and normalized into standard delimiters; The standardized keywords are split according to the standard delimiter to obtain a search term sequence; Query the preset delimiter-pattern mapping table, and determine the target matching pattern according to the delimiter type used for splitting, wherein in the mapping table, a space corresponds to the AND pattern, a comma corresponds to the OR pattern, a semicolon corresponds to the OR pattern, and a quotation mark corresponds to the PHRASE pattern; When the standardized keyword does not contain any separators, the target matching mode is determined to be the preset default mode, which is the AND mode.
4. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, Step S103, which involves retrieving values from each field to be matched in the current data object based on the field configuration information, specifically includes: When the field configuration information contains a whitelist of specified fields, the value retrieval operation is performed only on the fields specified in the whitelist. When the field configuration information contains a full-field search identifier, all fields of the data object are automatically traversed; For fields containing nested paths separated by dots, parse the path nodes layer by layer and retrieve their values sequentially until the values of the leaf nodes are obtained; When the result is an array, each element in the array is treated as an independent matching object and participates in subsequent matching.
5. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, Step S104 involves performing containment matching or regular expression matching on each matching object in the set of field values and each search term in the search term sequence, specifically as follows: For each of the matched objects, character normalization processing is performed, which includes case conversion and full-width character to half-width character conversion. Perform string inclusion matching between the normalized matching object and each of the search terms; When the search request specifies that regular expression matching is enabled, the search term is compiled into a regular expression and regular expression matching is performed. During the regular expression compilation process, a maximum length limit for the regular expression is set. If a compilation error occurs or the maximum length limit is exceeded, the matching is automatically downgraded to string inclusion matching.
6. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, Step S105, which involves combining and determining the matching results of each search term according to the target matching pattern, specifically includes: When the target matching mode is AND mode, each search term in the search term sequence is required to hit at least one field to be matched in the current data object before the current data object is determined to be a matched object. When the target matching mode is OR mode, at least one search term in the search term sequence must hit at least one field to be matched in the current data object in order to determine that the current data object is a matched object. When the target matching mode is PHRASE mode, at least one field value of the current data object is required to contain a complete phrase consisting of all search terms connected in their original order by a standard delimiter in order to determine that the current data object is a hit object.
7. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, Step S106, which involves scoring and sorting the set of hit objects, specifically includes: Calculate the field weight score based on the preset weight value of the hit field in each hit object; The hit position score is calculated based on the starting position of the matching keyword in the field value of each hit object, and the earlier the starting position, the higher the score. The hit count score is calculated based on the number of times the search term is hit in each hit object. The number of times the search term is hit is the number of hits recorded within the scanned range up to the time when the short circuit stops matching. The total field weight score is obtained by summing the field weight scores of each hit field to be matched, and the total hit position score is obtained by taking the maximum value of the hit position score of each hit position. The total field weight score, the total hit position score and the hit count score are weighted and summed to obtain the comprehensive score of each hit object. The set of hit objects is sorted from highest to lowest according to the comprehensive score.
8. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, After obtaining the standardized keywords in step S101, an incremental filtering step is also included, specifically: Determine whether the current input keyword meets the incremental filtering activation conditions compared to the previously input keyword. The activation conditions include: regular expression matching is not currently enabled, the current keyword is prefixed with the previous keyword and its length has increased, the target matching mode has not changed, the field configuration has not changed, the data source has not changed, and the current keyword does not cross a separator and the number of search terms has not increased. When the aforementioned activation conditions are met, filtering continues based on the set of hit objects obtained in the previous round of search; When the target matching mode is OR mode and the current keyword crosses the separator to generate a new search term, the set of hit objects from the previous round is retained, and the new search term is used to perform matching only on the complement data that was not hit in the previous round, and the matching result is merged with the set of hit objects from the previous round. If the activation conditions are not met and the above OR pattern complement set is not included, the process reverts to re-execute steps S103 to S106 on the complete data source.
9. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, The mark-hit information in step S107 specifically involves recording the hit field identifier, hit keyword identifier, and hit position information for each hit object's hit field. The hit position information includes the starting offset and ending offset of the keyword in the field value, so that the front-end view can perform keyword highlight rendering based on the hit position information.
10. The responsive fuzzy search method based on lightweight recursive matching at the front end according to claim 1, characterized in that, The reactive listening in step S108 is specifically as follows: Dependency tracking for the data source and the search request is registered through the listener mechanism of the reactive framework; When the addition, deletion or change of the data source is detected, or the keyword or field configuration in the search request is updated, the re-execution of steps S101 to S107 is automatically triggered; During the re-execution process, if the conditions for incremental filtering to take effect are met, incremental filtering will be executed; otherwise, a full recalculation will be performed, and the updated fuzzy search results will be synchronized to the front-end view.
