Boolean retrieval type analysis method and retrieval method based on regular expression

By analyzing the Boolean search form based on regular expressions, building a parse tree and converting it into an Elasticsearch query structure, the problems of inefficient parsing efficiency and high error rate in the existing technology are solved, and efficient and accurate information retrieval is achieved.

CN119202333APending Publication Date: 2024-12-27BEIJING ZHIGUAGUA TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411699936.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

Existing Boolean retrieval parsing methods are inefficient and error-prone when dealing with complex expressions, especially when they contain a large number of logical operators, brackets, and nested structures.

Method used

Using a regular expression-based parsing method, the Boolean search term is disassembled into subexpressions through preprocessing and predefined regular expression rules, and the parsing tree is constructed, and it is converted into Elasticsearch's query structure DSL, using regular expressions The powerful text matching ability of formula accurately recognizes and processes various elements and structures.

Benefits of technology

Significantly improve analysis efficiency, reduce error rate, and can flexibly handle complex query formats, simplify analysis processes, reduce calculation amounts, and enhance the accuracy and stability of analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119202333A_ABST
    Figure CN119202333A_ABST
Patent Text Reader

Abstract

The invention discloses a Boolean retrieval formula analysis method and retrieval method based on a regular expression, relates to the technical field of information retrieval, and aims at solving the technical problems that an existing Boolean retrieval formula analysis method is low in efficiency and prone to making mistakes. The analysis method comprises the steps that a pre-defined regular expression rule is used for analyzing a preprocessed Boolean retrieval formula, the Boolean retrieval formula is disassembled into a plurality of sub-expressions, each sub-expression can be directly recognized and processed, and the type and the corresponding value of each matching item in the Boolean retrieval formula are obtained; according to the analysis result, an analysis tree of a Boolean retrieval formula is constructed, each node in the analysis tree represents a keyword or an operator, and the connection relation between the nodes reflects the logic relation in the Boolean retrieval formula; and converting the parse tree into a query structure DSL. The calculation amount in the analysis process can be remarkably reduced, the analysis efficiency of the Boolean retrieval formula is improved, and meanwhile the analysis error rate of the Boolean retrieval formula is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of information retrieval, and in particular to a Boolean retrieval analysis method and a retrieval method. Background Art

[0002] Boolean search is a query expression method widely used in information retrieval systems. It constructs complex query conditions by combining keywords such as logical operators (such as AND, OR, NOT), logical priority operators (such as infinitely nested parentheses), interval operators (such as APD:[2024-07-02 TO 2024-09-20]), phrase operators (such as "computer"), escape operators (such as \"), etc. This method allows users to flexibly express their search needs, thereby effectively filtering out relevant information from massive data. Boolean search is designed to improve the accuracy and relevance of information retrieval and is suitable for various databases and search engines.

[0003] With the advent of the big data era, the amount of information has increased dramatically. How to efficiently and accurately retrieve the content required by users from massive amounts of information has become an important task that needs to be solved urgently. Boolean search is a commonly used information retrieval technology, and its parsing efficiency and accuracy directly affect the retrieval effect. An efficient parsing method can improve user experience, shorten the time of information retrieval, and ensure that users can quickly obtain the required data, thereby gaining an advantage in information competition.

[0004] At present, the analysis of Boolean search expressions mainly adopts a combination of lexical analysis and grammatical analysis. However, the inventors have realized that this method is prone to parsing errors or low efficiency when processing complex Boolean expressions. In particular, when the expression contains a large number of logical operators, brackets and nested structures, traditional parsing methods are often difficult to cope with. Summary of the invention

[0005] The present application provides a Boolean search formula parsing method and a retrieval method based on regular expressions, aiming to solve the technical problems that the existing Boolean search formula parsing methods are inefficient and prone to errors.

[0006] In a first aspect, a Boolean search parsing method based on regular expressions is applied to a server, and the method comprises:

[0007] S1, preprocessing the input Boolean search expression;

[0008] S2, using predefined regular expression rules, parsing the preprocessed Boolean search expression, breaking the Boolean search expression into multiple sub-expressions, each of which can be directly identified and processed, to obtain the type and corresponding value of each matching item in the Boolean search expression;

[0009] S3, constructing a parse tree of the Boolean search expression based on the parsing results, where each node in the parse tree represents a keyword or operator, and the connection relationship between the nodes reflects the logical relationship in the Boolean search expression;

[0010] S4, converts the parse tree into the Elasticsearch-based query structure DSL.

[0011] In the above solution, optionally, step S1 includes:

[0012] Remove spaces from Boolean search terms;

[0013] Convert all letters in the Boolean search query to uppercase / lowercase.

[0014] In the above solution, optionally, in the predefined regular expression rule, different aliases are used to identify different types of matching items.

[0015] In the above scheme, further optionally, in the predefined regular expression rule, the alias of the matching item of the phrase content type is phrase, the alias of the matching item of the single isolated double quote type is quote, the alias of the matching item of the blank character type is space, the alias of the matching item of the single character symbol type is match, the alias of the matching item of the slop configuration type is slop, the alias of the matching item of the interval symbol type is brace, the alias of the matching item of the Boolean operator type is bool, the alias of the matching item of the positional operator type is operator, and the alias of the matching item of the keyword content is value.

[0016] In the above solution, further optionally, the predefined regular expression rules include:

[0017] The regular expression used to match phrase content in Boolean search terms is:? <phrase>"[^"]*";

[0018] The regular expression used to match a single isolated double quote in a Boolean search is:? <quote>";

[0019] The regular expression used to match whitespace characters in Boolean search terms is:? <space>\s+;

[0020] The regular expression used to match single-character symbols in Boolean search terms is: ? <match>(==)|[=:]);

[0021] The regular expression used to match the slop configuration in the Boolean search formula is:? <slop>([~](\d+)));

[0022] The regular expression used to match interval symbols in Boolean search expressions is:? <brace>[()\[\]]);

[0023] The regular expression used to match Boolean operators in Boolean search terms is:? <bool>((\b(and|or|not)\b)|[&|+]|[\x21]));

[0024] The regular expression used to match positional operators in Boolean searches is:? <operator>\$\w+);

[0025] The regular expression used to match the keyword content in the Boolean search formula is:? <value>(\w|(-?\d)|[^\x00-\xff]|[%*\'·\?#,]|\.|\ / |(?<=\w)-(?=\w)|\b[(](\b|$))+).

[0026] In the above solution, further optionally, step S3 includes:

[0027] According to the type and corresponding value of each matching item in the Boolean search formula, steps S31-S36 are respectively performed for each matching item in the Boolean search formula until all matching items in the Boolean search formula are traversed; wherein:

[0028] S31, determine whether the type of the current matching item is match; if it is determined to be a match, determine the corresponding search field and add the corresponding parse tree node; if it is determined not to be a match, execute step S32;

[0029] S32, determine whether the type of the current matching item is brace; if it is determined to be brace, determine whether the corresponding interval symbol is paired; if it is determined not to be brace, execute step S33; when it is determined that the corresponding interval symbol is paired, obtain the content in the paired interval symbol and add the corresponding parse tree node; when it is determined that the corresponding interval symbol is not paired, mark the current matching item as error information;

[0030] S33, determine whether the type of the current matching item is bool; if it is determined to be bool, obtain the corresponding Boolean operator and add the corresponding parse tree node; if it is determined not to be bool, execute step S34;

[0031] S34, determine whether the type of the current matching item is an operator; if it is determined to be an operator, obtain the corresponding position operator and add the corresponding parse tree node; if it is determined not to be an operator, execute step S35;

[0032] S35, determine whether the type of the current matching item is value; if it is determined to be value, determine whether the corresponding keyword content has a nested search field; if it is determined not to be value, execute step S36; when it is determined that the corresponding keyword content has a nested search field, obtain the corresponding keyword content and add a corresponding parse tree node; when it is determined that the corresponding keyword content does not have a nested search field, mark the current matching item as an error message;

[0033] S36, determining whether the type of the current matching item is a phrase; if it is determined to be a phrase, obtaining the corresponding phrase content and adding a corresponding parse tree node; if it is determined not to be a phrase, marking the current matching item as an error message.

[0034] In the above solution, optionally, RegExp.exec is used to parse the preprocessed Boolean search expression.

[0035] In a second aspect, a Boolean search method is applied to a server, and the method comprises:

[0036] Receive Boolean search expression input by user;

[0037] Parsing the input Boolean search expression using any of the methods described in the first aspect to obtain a corresponding query structure DSL of the Boolean search expression;

[0038] Execute retrieval based on the query structure DSL and return the retrieval results to the user.

[0039] According to a third aspect, a server comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods according to the first aspect when executing the computer program.

[0040] In a fourth aspect, a computer program product comprises a computer program / instruction, wherein when the computer program / instruction is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.

[0041] Compared with the prior art, this application has at least the following beneficial effects:

[0042] In the method provided in the embodiment of the present application, the pre-processed Boolean search expression is parsed using pre-defined regular expression rules to obtain the type and corresponding value of each matching item in the Boolean search expression, and then a parse tree of the Boolean search expression is constructed according to the parsing results, and the parse tree is converted into a query structure DSL based on Elasticsearch, thereby completing the parsing of the Boolean search expression; since regular expressions have powerful text matching capabilities, they can flexibly handle a variety of complex query formats. By defining specific regular expressions, various elements and structures in the Boolean search expression can be accurately identified, reducing errors and omissions during parsing, thereby reducing the parsing error rate; by using regular expressions, complex Boolean search expressions can be decomposed into simple matching rules, thereby simplifying the parsing process. This simplification not only significantly reduces the amount of calculation in the parsing process and improves the efficiency of the parsing, but also reduces the probability of parsing errors because each part has been clearly matched and verified. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 A schematic diagram of a flow chart of a Boolean search parsing method based on regular expressions provided in one embodiment of the present application;

[0044] Figure 2 A schematic diagram of a specific process of constructing a parsing tree in one embodiment of the present application;

[0045] Figure 3 A schematic diagram of a parsing tree constructed in one embodiment of the present application;

[0046] Figure 4 A schematic diagram of a Boolean search method provided for an embodiment of the present application;

[0047] Figure 5 An internal structure diagram of a computer device provided for one embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0049] In the description of the present application: unless otherwise specified, expressions such as "include", "comprise", "have", etc. also mean "not limited to" (certain units, components, materials, steps, etc.).

[0050] Traditional parsing methods are often inefficient and error-prone when dealing with complex or ambiguous query expressions. Therefore, it is particularly important to develop an efficient and accurate Boolean retrieval parsing method.

[0051] In one embodiment, Figure 1 As shown, a Boolean search parsing method based on regular expressions is provided, which is applied to a server and includes the following steps:

[0052] S1, preprocessing the input Boolean search expression.

[0053] Specifically, step S1 includes:

[0054] Remove spaces in Boolean search expressions; this can be done by removing spaces before and after the string, or by normalizing multiple spaces in the middle into a single space;

[0055] Convert all letters in Boolean search terms to uppercase or lowercase to ensure consistency.

[0056] S2, using predefined regular expression rules, parses the preprocessed Boolean search expression, decomposes the Boolean search expression into multiple sub-expressions, each of which can be directly identified and processed to obtain the type and corresponding value of each matching item in the Boolean search expression.

[0057] Specifically, RegExp.exec is used to parse the preprocessed Boolean search expression.

[0058] Furthermore, in the predefined regular expression rules, different aliases are used to identify different types of matching items.

[0059] Specifically, in the predefined regular expression rules, the alias of the match item of the phrase content type is phrase, the alias of the match item of the single isolated double quote type is quote, the alias of the match item of the blank character type is space, the alias of the match item of the single character symbol type is match, the alias of the match item of the slop configuration type is slop, the alias of the match item of the interval symbol type is brace, the alias of the match item of the Boolean operator type is bool, the alias of the match item of the positional operator type is operator, and the alias of the match item of the keyword content is value.

[0060] Furthermore, the predefined regular expression rules include:

[0061] The regular expression used to match phrase content in Boolean search terms is:? <phrase>"[^"]*";

[0062] The regular expression used to match a single isolated double quote in a Boolean search is:? <quote>";

[0063] The regular expression used to match whitespace characters in Boolean search terms is:? <space>\s+;

[0064] The regular expression used to match single-character symbols in Boolean search terms is: ? <match>(==)|[=:]);

[0065] The regular expression used to match the slop configuration in the Boolean search formula is:? <slop>([~](\d+)));

[0066] The regular expression used to match interval symbols in Boolean search expressions is:? <brace>[()\[\]]);

[0067] The regular expression used to match Boolean operators in Boolean search terms is:? <bool>((\b(and|or|not)\b)|[&|+]|[\x21]));

[0068] The regular expression used to match positional operators in Boolean searches is:? <operator>\$\w+);

[0069] The regular expression used to match the keyword content in the Boolean search formula is:? <value>(\w|(-?\d)|[^\x00-\xff]|[%*\'·\?#,]|\.|\ / |(?<=\w)-(?=\w)|\b[(](\b|$))+).

[0070] S3, based on the parsing results, construct a parsing tree of the Boolean search expression. Each node in the parsing tree represents a keyword or operator, and the connection relationship between the nodes reflects the logical relationship in the Boolean search expression.

[0071] like Figure 2 The flowchart of constructing the parse tree shown in step S3 includes:

[0072] According to the type and corresponding value of each matching item in the Boolean search formula, steps S31-S36 are respectively performed for each matching item in the Boolean search formula until all matching items in the Boolean search formula are traversed; wherein:

[0073] S31, determine whether the type of the current matching item is match; if it is determined to be a match, determine the corresponding search field (i.e., field field) and add the corresponding parse tree node; if it is determined not to be a match, execute step S32;

[0074] S32, determine whether the type of the current matching item is brace; if it is determined to be brace, determine whether the corresponding interval symbol is paired; if it is determined not to be brace, execute step S33; when it is determined that the corresponding interval symbol is paired, obtain the content in the paired interval symbol and add the corresponding parse tree node; when it is determined that the corresponding interval symbol is not paired, mark the current matching item as error information;

[0075] S33, determine whether the type of the current matching item is bool; if it is determined to be bool, obtain the corresponding Boolean operator and add the corresponding parse tree node; if it is determined not to be bool, execute step S34;

[0076] S34, determine whether the type of the current matching item is an operator; if it is determined to be an operator, obtain the corresponding position operator (also known as a position frequency symbol) and add the corresponding parse tree node; if it is determined not to be an operator, execute step S35;

[0077] S35, determine whether the type of the current matching item is value; if it is determined to be value, determine whether the corresponding keyword content has a search field nesting (i.e., field nesting); if it is determined not to be value, execute step S36; when it is determined that the corresponding keyword content has a search field nesting, obtain the corresponding keyword content and add a corresponding parse tree node; when it is determined that the corresponding keyword content does not have a search field nesting, mark the current matching item as an error message;

[0078] S36, determining whether the type of the current matching item is a phrase; if it is determined to be a phrase, obtaining the corresponding phrase content and adding a corresponding parse tree node; if it is determined not to be a phrase, marking the current matching item as an error message.

[0079] S4, converts the parse tree into the Elasticsearch-based query structure DSL.

[0080] In other words, the embodiment of the present application provides a method for generating a query structure statement DSL required by Elasticsearch based on a Boolean search formula based on regular expression parsing, and then further using the query structure statement DSL to return the results that the user wants to query. The method includes the following steps:

[0081] Step 1. Regular expression definition:

[0082] (1) Design a set of regular expression rules to accurately match keywords, logical operators, and special symbols (such as brackets, positive lookbehind assertions, positive lookahead, etc.) in Boolean search expressions.

[0083] (2) Use subpattern aliases to identify different types of matches to facilitate subsequent logical processing.

[0084] For example, the designed regular expression can be as follows:

[0085] (1) Analyze the phrase content: <phrase>"[^"]*"

[0086] (2) A single isolated double quote: ? <quote>"

[0087] (3) White characters: ? <space>\s+

[0088] (4) Single character symbol: ? <match>(==)|[=:])

[0089] (5) Slop configuration: <slop>([~](\d+)))

[0090] (6) Interval: ? <brace>[()\[\]])

[0091] (7) Boolean operator: ? <bool>((\b(and|or|not)\b)|[&|+]|[\x21]))

[0092] (8) Positional operator: ? <operator>\$\w+)

[0093] (9) Contents: ? <value>(\w|(-?\d)|[^\x00-\xff]|[%*\'·\?#,]|\.|\ / |(?<=\w)-(?=\w)|\b[(](\b|$))+)

[0094] Step 2: Expression preprocessing:

[0095] Preprocess the input Boolean search expression, including removing spaces, converting uppercase and lowercase letters, etc., to ensure that subsequent regular expression matching can proceed smoothly.

[0096] Step 3: Scan and parse the Boolean search expression:

[0097] (1) Use the designed regular expression pattern to scan, match and parse the preprocessed Boolean search expression.

[0098] (2) Use advanced features such as positive lookbehind assertions to handle complex logical relationships and nested structures.

[0099] (3) Through recursion or iteration, complex Boolean expressions are gradually broken down into simple sub-expressions until each sub-expression can be directly recognized and processed.

[0100] In other words, create a regular expression object using step 1, and use RegExp.exec to scan and match in a Boolean search.

[0101] Step 4: Build the parse tree:

[0102] (1) Use the defined regular expression to parse the preprocessed Boolean search expression, and dynamically construct the parse tree of the Boolean search expression based on the parsing result.

[0103] (2) Each node in the parse tree represents a keyword or logical operator, and the connection between nodes reflects the logical relationship in the search formula.

[0104] Based on the parsing results, the parsing tree of the Boolean search expression is dynamically constructed, and the search tree contains the matching results. The returned search tree will contain the matched text and the contents of any capture groups.

[0105] The code for constructing the parse tree can be illustrated as follows:

[0106] interface Element {

[0107] / ** The first element * /

[0108] pos: number,

[0109] value: string,

[0110] cls?: ElementClassEnum,

[0111] type: 'field' | 'value' | 'brace' | 'match' | 'bool' | 'operator' | 'phrase' | 'quote' | 'boost' | 'slop''filter' | 'context' ,

[0112] / ** When value has multiple variants with the same meaning, unify them into subType to facilitate unified processing of the same rules* /

[0113] subType?: 'AND' | 'OR' | 'NOT' | '';

[0114] error?: string,

[0115] / ** field: the field does not exist, value: the value format does not match, if there is an error but no type, it is a context error by default* /

[0116] errType?: 'field' | 'value',

[0117] / ** The space on the right side of the element* /

[0118] rightSpace?: string,

[0119] / ** boost, string type, to restore the front-end expression; generate es query and maintain it* /

[0120] boost?: string,

[0121] / ** value slop, match_phrase .unigram field* /

[0122] slop?: string,

[0123] / ** minimum_should_match * /

[0124] msm?: string,

[0125] / ** context type, field generation, left bracket generation* /

[0126] ctxType?: ':' | '(' | '[' | '{' | '@' | '=' | '#' | '==',

[0127] / ** End position of context (branch)* /

[0128] ctxEndPos?: number,

[0129] / ** Starting character position (inclusive) * /

[0130] sCharPos: number,

[0131] / ** End character position (not included) * /

[0132] eCharPos: number,

[0133] / ** If the element is in a field context, bind the field name. Used to recommend options by field* /

[0134] fieldName?: string,

[0135] / ** Is it a suffix class? * /

[0136] suffix?: boolean;

[0137] }

[0138] Step 5. Change the query conditions:

[0139] Convert the parse tree into a query structure DSL based on Elasticsearch. The converted query structure DSL example is as follows:

[0140] {

[0141] "query": {

[0142] "bool": {

[0143] "must": [

[0144] { "match": { "title": "Computer"}},

[0145] { "match": { "content": "space"}}

[0146] ],

[0147] }

[0148] }

[0149] }

[0150] Step 6. Execute:

[0151] Execute queries based on the DSL and return results.

[0152] Step 7: Test and verify:

[0153] The parsing functions are tested and verified through a large number of test cases to ensure their correctness and stability in various situations.

[0154] The following is an example of a specific implementation:

[0155] The search formula entered by the user is: "TTL_ALL:(sorghum OR millet) AND (APD:[20000101 TO20221231] NOT IPC:(E OR C05))".

[0156] First, the search expression is parsed to identify the logical relationships and conditions. Then, a parse tree is constructed based on these data. The constructed parse tree is as follows: Figure 3 shown.

[0157] Finally, the query statement generated by the Elasticsearch through the parsing tree is as follows:

[0158] {

[0159] "query": {

[0160] "bool": {

[0161] "must": {

[0162] "bool": {

[0163] "must": [

[0164] {

[0165] "bool": {

[0166] "should": [

[0167] {

[0168] "match": {

[0169] "title": {

[0170] "query": "sorghum",

[0171] "operator": "AND",

[0172] "boost": 1

[0173] }

[0174] }

[0175] },

[0176] {

[0177] "match": {

[0178] "title": {

[0179] "query": "Foxtail millet",

[0180] "operator": "AND",

[0181] "boost": 1

[0182] }

[0183] }

[0184] }

[0186] }

[0187] },

[0188] {

[0189] "bool": {

[0190] "must":

[0191] {

[0192] "range": {

[0193] "app_date": {

[0194] "gte": "20000101",

[0195] "lte": "20221231"

[0196] }

[0197] }

[0198] }

[0199] ,

[0200] "must_not":

[0201] {

[0202] "bool": {

[0203] "should":​

[0204] {

[0205] "match": {

[0206] "ipc_array": {

[0207] "query": "E",

[0208] "operator": "AND",

[0209] "boost": 1

[0210] }

[0211] }

[0212] },

[0213] {

[0214] "match": {

[0215] "ipc_array": {

[0216] "query": "C05",

[0217] "operator": "AND",

[0218] "boost": 1

[0219] }

[0220] }

[0221] } ]

[0223] }

[0224] } ]

[0226] }

[0227] } ]

[0229] }

[0230] },

[0231] }

[0232] }

[0233] }

[0234] Using the method provided in the embodiment of the present application, the measured records of parsing the search formula to generate Query Dsl are shown in Table 1 below:

[0235] Table 1 Measured records from parsing search terms to generating Query DSL

[0236] Search Time ANH: Shandong Zhongkang Runke Bioengineering Co., Ltd. AND PN: (CN106957810B) 0ms TTL_ALL:(sorghum OR millet) AND (APD:[20000101 TO 20221231]NOT IPC:(E OR C05)) 1ms ((TTL_ALL:(High-purity copper OR "high pure copper" OR "ultra-high-purity copper" or "high-purity copper" or "high-purityelectrolytic copper" or "Ultrahigh-purity copper" or high-purity copper) AND TTL_ALL:(Preparation OR preparing OR prepare OR Refining OR refining or producing)) or (TA_ALL:(High-purity copper OR "high purecopper" OR "ultra-high-purity copper" or "high-puritycopper" or "high-purity electrolytic copper" or "Ultrahigh-purity copper" or high-purity copper) AND TAC_ALL:(electrolysisORelectrolytic OR primary electrolysisOR "primary electrolysis")) or(TAC_ALL:(high-purity copperOR "high pure copper" OR "ultra-high-purity copper" OR "high-purity copper" OR "high-purityelectrolytic copper" OR "Ultrahigh-purity copper" OR High purity copper) AND IPC:(C25C1 / 12 OR C22B15 / 00 OR C22B15 / 14 ORC25C7 / 02 OR C22B9 / 00 OR C22B9 / 04))) not (IPC:(A or D or Gor F02 or F23)) 4ms (((TTL_ALL:(high-purity copper OR "high pure copper" OR "ultra-high-purity copper" or "high-purity copper" or "high-purity electrolytic copper" or "Ultrahigh-purity copper" or high-purity copper) AND TTL_ALL:(preparation OR preparing OR prepare OR refining OR refining or producing)) or (TA_ALL:(high-purity copper OR "high pure copper" OR "ultra-high-purity copper" or "high-purity copper" or "high-purity electrolytic copper" or "Ultrahigh-purity copper" or high-purity copper) AND TAC_ALL:(electrolysis OR electrolytic OR primary electrolysis OR "primary electrolysis")) or (TAC_ALL:(high-purity copper OR "high pure copper" OR "ultra-high-purity copper" OR "high-purity copper" OR "high-purity electrolytic copper" OR "Ultrahigh-purity copper" OR high-purity copper) AND IPC:(C25C1 / 12 OR C22B15 / 00 OR C22B15 / 14 OR C25C7 / 02 OR C22B9 / 00 OR C22B9 / 04))) not (IPC:(A or D or G or F02 or F23))) and (((TTL_ALL:(high-purity copper OR "high pure copper" OR "ultra-high-purity copper" or "high-purity copper" or "high-purity electrolytic copper" or "Ultrahigh-purity copper" or high-purity copper) AND TTL_ALL:(preparation OR preparing OR prepare OR refining OR refining or producing))or(TA_ALL:(high-purity copper OR "high pure copper" OR "ultra-high-purity copper" or "high-purity copper" or "high-purity electrolytic copper" or "Ultrahigh-purity copper" or high-purity copper) AND TAC_ALL:(electrolysis OR electrolytic OR primary electrolysis OR "primary electrolysis")) or (TAC_ALL:(high-purity copper OR "high pure copper" OR "ultra-high-purity copper" OR "high-purity copper" OR "high-purity electrolytic copper" OR "Ultrahigh-purity copper" OR high-purity copper) AND IPC:(C25C1 / 12 OR C22B15 / 00 OR C22B15 / 14 OR C25C7 / 02 OR C22B9 / 00 OR C22B9 / 04))) not (IPC:(A or D or G or F02 or F23))) 5ms

[0237] After testing, the generated DSL is completely correct and the parsing process is very fast.

[0238] The regular parsing Boolean search method provided in the embodiment of the present application has the following advantages:

[0239] 1. Improve parsing efficiency: The regular expression-based parsing method can significantly reduce the amount of calculation in the parsing process and improve parsing efficiency.

[0240] 2. Reduce the error rate: Regular expressions have powerful text matching capabilities and can accurately identify various elements and structures in Boolean search expressions, thereby reducing the parsing error rate.

[0241] 3. Enhanced flexibility: The method provided in the embodiment of the present application can adjust the regular expression pattern according to actual needs, support multiple operations on the parse tree, and facilitate subsequent information retrieval and processing.

[0242] The method provided in the embodiment of the present application is specifically a method for parsing and processing Boolean search expressions by using a variety of technical means such as regular expressions, sub-pattern aliases in regular expressions, positive lookbehind assertions in regular expressions, and positive pre-checks in regular expressions to accurately match the content of operators and keywords, and to improve the accuracy and efficiency of information retrieval.

[0243] The method for parsing Boolean search expressions based on regular expressions provided in the embodiments of the present application can significantly improve the parsing efficiency and accuracy in the following aspects:

[0244] (1) Strong pattern matching capability: Regular expressions have powerful pattern matching capabilities and can flexibly handle a variety of complex query formats. By defining specific regular expressions, they can accurately identify logical operators, brackets, phrases, and other operators in Boolean search expressions, reducing errors and omissions during parsing.

[0245] (2) Efficient lexical analysis: Traditional parsing methods often require step-by-step analysis and construction of an abstract syntax tree, while regular expression-based methods can perform lexical analysis on the entire search expression at one time, greatly reducing the complexity of processing. This batch processing method improves the overall parsing speed and is suitable for processing large-scale data input.

[0246] (3) Simplify the parsing process: By using regular expressions, complex Boolean search expressions can be broken down into simple matching rules, thereby simplifying the parsing process. This simplification not only improves the efficiency of parsing, but also reduces the probability of parsing errors, because each part is clearly matched and verified.

[0247] (4) Flexible handling of nested structures: Regular expressions can effectively handle multi-layer nested structures, allowing efficiency and accuracy to be maintained when parsing Boolean search expressions containing multiple logical levels. By constructing corresponding regular patterns, multiple brackets and complex logical combinations can be quickly identified and processed.

[0248] (5) Easy to maintain and expand: The parsing method based on regular expressions is easy to maintain and expand. As requirements change, users can easily adjust regular expressions to adapt to new query requirements without significantly changing the entire parsing system. This flexibility helps to continuously improve parsing capabilities in future applications.

[0249] In summary, the embodiment of the present application provides a Boolean search formula parsing method based on regular expressions. The test result example proves that the DSL generated by the parsing is completely correct and the parsing process is very fast. The method can efficiently and accurately parse Boolean search formulas and construct a parsing tree structure that is easy to process and query, and accurately and quickly generate a query structure DSL for Elasticsearch. The method provided by the embodiment of the present application has broad application prospects and practical value.

[0250] In one embodiment, Figure 4 As shown, a Boolean search method is provided, which is applied to a server and includes the following steps:

[0251] Receive Boolean search expression input by user;

[0252] The input Boolean search expression is parsed using the Boolean search expression parsing method based on regular expressions provided in the above embodiment to obtain a corresponding query structure DSL of the Boolean search expression;

[0253] Execute retrieval based on the query structure DSL and return the retrieval results to the user.

[0254] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. The processor of the computer device is used to provide computing and control capabilities, and the network interface is used to communicate with an external terminal through a network connection. The computer device loads and runs a computer program to implement the above-mentioned Boolean retrieval parsing method based on regular expressions.

[0255] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0256] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which involves all or part of the processes in the above-mentioned embodiment method.

[0257] In one embodiment, a computer program product is also provided, including a computer program / instruction, which implements all or part of the process in the above-mentioned embodiment method when executed by a processor.

[0258] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.< / value> < / operator> < / bool> < / brace> < / slop> < / match> < / space> < / quote> < / phrase> < / value> < / operator> < / bool> < / brace> < / slop> < / match> < / space> < / quote> < / phrase> < / value> < / operator> < / bool> < / brace> < / slop> < / match> < / space> < / quote> < / phrase>

Claims

1. A Boolean search parsing method based on regular expressions, characterized in that: Applied to a server, the method comprises: S1, preprocessing the input Boolean search expression; S2, using predefined regular expression rules, parsing the preprocessed Boolean search expression, breaking the Boolean search expression into multiple sub-expressions, each of which can be directly identified and processed, to obtain the type and corresponding value of each matching item in the Boolean search expression; S3, constructing a parse tree of the Boolean search expression based on the parsing results, where each node in the parse tree represents a keyword or operator, and the connection relationship between the nodes reflects the logical relationship in the Boolean search expression; S4, converts the parse tree into the Elasticsearch-based query structure DSL.

2. The Boolean search formula parsing method based on regular expressions according to claim 1, characterized in that: Step S1 includes: Remove spaces from Boolean search terms; Convert all letters in the Boolean search query to uppercase / lowercase.

3. The Boolean search formula parsing method based on regular expressions according to claim 1, characterized in that: In the predefined regular expression rule, different aliases are used to identify different types of matching items.

4. The Boolean search formula parsing method based on regular expressions according to claim 3 is characterized in that: In the predefined regular expression rule, the alias of the matching item of phrase content type is phrase, the alias of the matching item of single isolated double quote type is quote, the alias of the matching item of blank character type is space, the alias of the matching item of single character symbol type is match, the alias of the matching item of slop configuration type is slop, the alias of the matching item of interval symbol type is brace, the alias of the matching item of Boolean operator type is bool, the alias of the matching item of positional operator type is operator, and the alias of the matching item of keyword content is value.

5. The Boolean search formula parsing method based on regular expressions according to claim 4, characterized in that: Predefined regular expression rules include: The regular expression used to match phrase content in Boolean search terms is:? <phrase> "[^"]*";< / phrase> The regular expression used to match a single isolated double quote in a Boolean search is:? <quote> ";< / quote> The regular expression used to match whitespace characters in Boolean search terms is:? <space> \s+;< / space> The regular expression used to match single-character symbols in Boolean search terms is: ? <match> (==)|[=:]);< / match> The regular expression used to match the slop configuration in the Boolean search formula is:? <slop> ([~](\d+)));< / slop> The regular expression used to match interval symbols in Boolean search expressions is:? <brace> [()\[\]]);< / brace> The regular expression used to match Boolean operators in Boolean search terms is:? <bool> ((\b(and|or|not)\b)|[&|+]|[\x21]));< / bool> The regular expression used to match positional operators in Boolean searches is:? <operator> \$\w+);< / operator> The regular expression used to match the keyword content in the Boolean search formula is:? <value> (\w|(-?\d)|[^\x00-\xff]|[%*\'·\?#,]|\.|\ / |(?<=\w)-(?=\w)|\b[(](\b|$))+).< / value> 6. The Boolean search formula parsing method based on regular expressions according to claim 4, characterized in that: Step S3 includes: According to the type and corresponding value of each matching item in the Boolean search formula, steps S31-S36 are respectively performed for each matching item in the Boolean search formula until all matching items in the Boolean search formula are traversed; wherein: S31, determine whether the type of the current matching item is match; if it is determined to be a match, determine the corresponding search field and add the corresponding parse tree node; if it is determined not to be a match, execute step S32; S32, determine whether the type of the current matching item is brace; if it is determined to be brace, determine whether the corresponding interval symbol is paired; if it is determined not to be brace, execute step S33; when it is determined that the corresponding interval symbol is paired, obtain the content in the paired interval symbol and add the corresponding parse tree node; when it is determined that the corresponding interval symbol is not paired, mark the current matching item as error information; S33, determine whether the type of the current matching item is bool; if it is determined to be bool, obtain the corresponding Boolean operator and add the corresponding parse tree node; if it is determined not to be bool, execute step S34; S34, determine whether the type of the current matching item is an operator; if it is determined to be an operator, obtain the corresponding position operator and add the corresponding parse tree node; if it is determined not to be an operator, execute step S35; S35, determine whether the type of the current matching item is value; if it is determined to be value, determine whether the corresponding keyword content has a nested search field; if it is determined not to be value, execute step S36; when it is determined that the corresponding keyword content has a nested search field, obtain the corresponding keyword content and add a corresponding parse tree node; when it is determined that the corresponding keyword content does not have a nested search field, mark the current matching item as an error message; S36, determining whether the type of the current matching item is a phrase; if it is determined to be a phrase, obtaining the corresponding phrase content and adding a corresponding parse tree node; if it is determined not to be a phrase, marking the current matching item as an error message.

7. The Boolean search formula parsing method based on regular expressions according to claim 1, characterized in that: Use RegExp.exec to parse the preprocessed Boolean search expression.

8. A Boolean search method, characterized in that: Applied to a server, the method comprises: Receive Boolean search expression input by user; Parsing the input Boolean search expression using the method described in any one of claims 1 to 7 to obtain a corresponding query structure DSL of the Boolean search expression; Execute retrieval based on the query structure DSL and return the retrieval results to the user.

9. A server, comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • A type of lactic acid cocci and its uses

    CN106957810B

  • Cross-platform logical operation expression method and system

    CN113918134A

  • Method and system for converting expression retrieval into Elasticsearch search statement

    CN114691825A

  • Query statement conversion method and device, electronic equipment and storage medium

    CN115827675A

  • Systems and methods for identifying content types for data loss prevention

    US20190180048A1