Query method and device, computer device and storage medium

By customizing the splitting and parsing of query strings to form subquery units, the scalability problem of query functions when the data scale increases is solved, realizing a flexible, convenient and efficient query method that can adapt to the query needs of different databases.

CN111459978BActive Publication Date: 2025-12-30SAI ANDY TECHNOLOGY (HONG KONG) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010199245.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-20
Publication Date
2025-12-30
Estimated Expiration
2040-03-20

AI Technical Summary

Technical Problem

The existing query function cannot flexibly and dynamically expand query conditions when faced with increasing data volume, resulting in limited query conditions and failing to meet the diverse needs of users.

Method used

By obtaining a custom query string, parsing and splitting it into basic query units, forming sub-query units based on configuration information, and obtaining sub-query results according to the target query method, it supports dynamically expanding query conditions, including error detection and repair, and adapts to different types of database queries.

Benefits of technology

It achieves greater flexibility and scalability in queries, improves the convenience and efficiency of queries, supports adaptive queries for different types of databases, and enhances the accuracy and fault tolerance of queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111459978B_ABST
    Figure CN111459978B_ABST
Patent Text Reader

Abstract

The application relates to big data, and provides a query method, a query device, equipment and a storage medium, which comprises the following steps: acquiring a query string, wherein the query string comprises a self-defined query expression; parsing the query expression, splitting the query expression according to a connection symbol to obtain corresponding basic query units comprising condition statements and field statements, acquiring corresponding configuration information, forming sub-query units by using the basic query units with the same configuration information according to the sequence of the basic query units, wherein the configuration information is used for determining a target query mode corresponding to the sub-query units, and obtaining corresponding sub-query results according to the target query mode; when the query result is a combined type, combining the sub-query results to obtain a target query result; when the query result is a quadratic type, a second query result corresponding to a second type of sub-query unit exists, a query database corresponding to the first type of sub-query unit is updated through the second query result, and the target query result is obtained by searching according to the updated query database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a query method, apparatus, computer device, and storage medium. Background Technology

[0002] Currently, the query function is widely used, enabling users to easily and quickly find the data they want, so most software has a query function.

[0003] As data volumes increase, query functions all share common limitations: they typically fix the query fields or global fields before using key-value pairs to retrieve the corresponding relational data. This approach lacks scalability and cannot dynamically expand the key values ​​of the query conditions, thus failing to fully accommodate user-defined combinations. If the query conditions are too limited, they cannot provide flexible and convenient querying for users. Therefore, providing a query method that supports dynamic expansion of query conditions and is user-friendly is crucial. Summary of the Invention

[0004] Therefore, it is necessary to provide a query method, apparatus, computer device, and storage medium to address the aforementioned technical problems. This supports the dynamic expansion of query data, allowing modification of the query structure simply by changing the configured data, thereby improving the scalability and convenience of the query.

[0005] A query method, the method comprising:

[0006] Obtain the query string, which includes a custom query expression;

[0007] The query expression is parsed, and the query expression is divided into corresponding basic query units according to the connectors in the query expression. The basic query unit includes conditional statements and field statements. The configuration information corresponding to the basic query unit is obtained. The basic query units with the same configuration information are formed into sub-query units according to the order of the basic query units. The configuration information is used to determine the target query method corresponding to the sub-query unit. The sub-query result corresponding to the sub-query unit is obtained according to the target query method corresponding to the sub-query unit.

[0008] When the subquery results corresponding to each subquery unit are combined query results, the subquery results are combined to obtain the target query result corresponding to the query string;

[0009] When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type subquery unit and a second type subquery unit. The second type subquery unit has a corresponding second query result. The query database corresponding to the first type subquery unit is updated through the second query result. The target query result corresponding to the query string is retrieved based on the updated query database.

[0010] In one embodiment, after obtaining the query string, the method further includes:

[0011] The query string is inspected, and if an error is found, it is repaired to obtain a repaired query string. The repair includes at least one of the following methods:

[0012] When the query string contains an error field, retrieve the current condition statement corresponding to the error field, and delete the error field statement and the current condition statement corresponding to the error field.

[0013] If the query string contains redundant fields, delete the field statements corresponding to the redundant fields;

[0014] When the query string contains a syntax error, the incorrect syntax connector will be corrected.

[0015] In one embodiment, obtaining the subquery result corresponding to the subquery unit based on the target query method corresponding to the subquery unit includes:

[0016] When the target query method corresponding to the first type of sub-query unit is an exact query, the target query database corresponding to the first type of sub-query unit is determined to be a relational database. When the target query method corresponding to the second type of sub-query unit is a fuzzy query, the target query database corresponding to the second type of sub-query unit is determined to be a retrieval database. The corresponding second query result is obtained by querying the retrieval database by the second type of sub-query unit.

[0017] When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type subquery unit and a second type subquery unit. The second type subquery unit has a corresponding second query result. The query database corresponding to the first type subquery unit is updated through the second query result. The target query result corresponding to the query string is retrieved based on the updated query database, including:

[0018] The second query result is written into the relational database corresponding to the first type of sub-query unit. The sub-query units are combined to form a complete query unit. The target query result is obtained by querying the relational database based on the complete query unit.

[0019] In one embodiment, the method further includes:

[0020] Obtain the newly added data table, compare the original candidate fields of the queried database with the fields in the newly added data table, and if the newly added data table contains a new field, use the new field as a new candidate field and match the corresponding configuration information for the new candidate field.

[0021] In one embodiment, comparing the original candidate fields of the queried database with the fields in the newly added data table includes:

[0022] When a new field exists in the newly added data table, the similarity between the new field and each original candidate field is calculated.

[0023] Obtain target original candidate fields whose similarity to the newly added field exceeds a preset threshold, establish the association between the newly added field and the target original candidate fields, and use the configuration information corresponding to the target original candidate fields as the configuration information corresponding to the newly added field.

[0024] A query device, the device comprising:

[0025] The acquisition module is used to acquire the query string, which includes a custom query expression;

[0026] The subquery result determination module is used to parse the query expression, divide the query expression into corresponding basic query units according to the connectors in the query expression, the basic query unit includes conditional statements and field statements, obtain the configuration information corresponding to the basic query unit, form subquery units with the same configuration information according to the order of the basic query units, the configuration information is used to determine the target query method corresponding to the subquery unit, and obtain the subquery result corresponding to the subquery unit according to the target query method corresponding to the subquery unit.

[0027] The first target query result determination module is used to combine the sub-query results to obtain the target query result corresponding to the query string when the sub-query results corresponding to each sub-query unit are combined query results.

[0028] The second target query result determination module is used when the subquery result corresponding to each subquery unit is a quadratic query result. The subquery unit includes a first type subquery unit and a second type subquery unit. The second type subquery unit has a corresponding second query result. The module updates the query database corresponding to the first type subquery unit through the second query result and retrieves the target query result corresponding to the query string based on the updated query database.

[0029] In one embodiment, the device further includes:

[0030] The processing module is used to detect errors in the query string. When errors are found in the query string, the module repairs them to obtain a repaired query string. The repair includes at least one of the following methods: when the query string contains erroneous fields, the module obtains the current condition statement corresponding to the erroneous field and deletes the erroneous field statement and the current condition statement; when the query string contains redundant fields, the module deletes the field statements corresponding to the redundant fields; when the query string contains syntax errors, the module corrects the incorrect syntax connectors.

[0031] In one embodiment, the subquery result determination module is further configured to determine that the target query database corresponding to the first type of subquery unit is a relational database when the target query method corresponding to the first type of subquery unit is an exact query, and to determine that the target query database corresponding to the second type of subquery unit is a retrieval database when the target query method corresponding to the second type of subquery unit is a fuzzy query, and to obtain the corresponding second query result based on the second type of subquery unit querying the retrieval database;

[0032] The second target query result determination module is further configured to write the second query result into the relational database corresponding to the first type of sub-query unit, combine the sub-query units into a complete query unit, and query the relational database according to the complete query unit to obtain the target query result.

[0033] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program performing the following steps:

[0034] Obtain the query string, which includes a custom query expression;

[0035] The query expression is parsed, and the query expression is divided into corresponding basic query units according to the connectors in the query expression. The basic query unit includes conditional statements and field statements. The configuration information corresponding to the basic query unit is obtained. The basic query units with the same configuration information are formed into sub-query units according to the order of the basic query units. The configuration information is used to determine the target query method corresponding to the sub-query unit. The sub-query result corresponding to the sub-query unit is obtained according to the target query method corresponding to the sub-query unit.

[0036] When the subquery results corresponding to each subquery unit are combined query results, the subquery results are combined to obtain the target query result corresponding to the query string;

[0037] When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type subquery unit and a second type subquery unit. The second type subquery unit has a corresponding second query result. The query database corresponding to the first type subquery unit is updated through the second query result. The target query result corresponding to the query string is retrieved based on the updated query database.

[0038] A computer-readable storage medium having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0039] Obtain the query string, which includes a custom query expression;

[0040] The query expression is parsed, and the query expression is divided into corresponding basic query units according to the connectors in the query expression. The basic query unit includes conditional statements and field statements. The configuration information corresponding to the basic query unit is obtained. The basic query units with the same configuration information are formed into sub-query units according to the order of the basic query units. The configuration information is used to determine the target query method corresponding to the sub-query unit. The sub-query result corresponding to the sub-query unit is obtained according to the target query method corresponding to the sub-query unit.

[0041] When the subquery results corresponding to each subquery unit are combined query results, the subquery results are combined to obtain the target query result corresponding to the query string;

[0042] When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type subquery unit and a second type subquery unit. The second type subquery unit has a corresponding second query result. The query database corresponding to the first type subquery unit is updated through the second query result. The target query result corresponding to the query string is retrieved based on the updated query database.

[0043] The aforementioned query method, apparatus, computer equipment, and storage medium obtain a query string, which includes a custom query expression; parse the query expression; segment the query expression according to the connectors in the query expression to obtain corresponding basic query units; each basic query unit includes conditional statements and field statements; obtain configuration information corresponding to the basic query units; form sub-query units with the same configuration information according to the order of the basic query units; the configuration information is used to determine the target query method corresponding to the sub-query unit; and query the sub-query result corresponding to the sub-query unit according to the target query method corresponding to the sub-query unit. When the sub-query results corresponding to each sub-query unit are combined query results, the sub-query results are combined to obtain the target query result corresponding to the query string. When the sub-query results corresponding to each sub-query unit are quadratic query results, the sub-query unit includes a first type of sub-query unit and a second type of sub-query unit. The second type of sub-query unit has a corresponding second query result. The query database corresponding to the first type of sub-query unit is updated through the second query result, and the target query result corresponding to the query string is retrieved according to the updated query database. The user controls and freely combines query conditions and fields through custom query expressions, supporting dynamic expansion of query data. Furthermore, configuration information allows each basic query unit to form corresponding sub-query units, each with different target query methods. The sub-query results are obtained through the target query method and then integrated to obtain the target query result. Modifying the query structure is achieved simply by changing the configuration data, thereby changing the configuration information corresponding to the basic query units. This flexibility and convenience improve the scalability and ease of use of queries. Attached Figure Description

[0044] Figure 1 This is a diagram illustrating the application environment of the query method in one embodiment;

[0045] Figure 2 This is a flowchart illustrating the query method in one embodiment;

[0046] Figure 3 This is a structural block diagram of the query device in one embodiment;

[0047] Figure 4 This is an internal structural diagram of a computer device in one embodiment;

[0048] Figure 5 This is a diagram of the internal structure of a computer device in another embodiment. Detailed Implementation

[0049] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0050] The query method provided in this application can be applied to, for example... Figure 1 The application environment shown. Figure 1 This is a diagram illustrating the application environment in which the query method operates in one embodiment. For example... Figure 1 As shown, the application environment includes terminal 110 and server 120. The terminal and server communicate with each other through a network, which can be a wireless or wired communication network, such as an IP network or a cellular mobile communication network. The number of terminals and servers is unlimited.

[0051] The terminal 110 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be a standalone server or a server cluster consisting of multiple servers. The query method can be applied to either the terminal or the server. When applied to the server, the terminal receives the input query string and sends a query request carrying the query string to the server, which then determines the corresponding target query result based on the query string. Multiple different types of query databases can exist on the terminal or server for basic query units with different configuration information to perform queries.

[0052] In one embodiment, such as Figure 2 As shown, a query method is provided, which can be applied to Figure 1 Taking terminal 110 or server 120 as an example, the following steps are included:

[0053] Step 210: Obtain the query string, which includes a custom query expression.

[0054] The query string is used to describe the query conditions and can be customized according to the content of the query.

[0055] Specifically, the query string includes custom query expressions, allowing users to flexibly combine query conditions. For example: "Male [Gender] AND Hunan [Address] OR Liver Cancer [Electronic Medical Record]", where spaces separate conditions and connectors. The data to the left of the square brackets is the query condition statement, and the data inside the square brackets is the field to be queried. AND and OR are the connectors between the conditions. Custom query expressions can be parsed using specialized parsing tools. All query conditions and fields are under the user's control and can be freely combined, greatly improving query flexibility.

[0056] The system can receive query strings through a unified input interface. The fields in the query string can be customized based on the query content. For example, for queries on medical data, fields could include disease names, drug names, etc. For queries on multimedia data, fields could include movie titles, song titles, etc. For queries on traffic information, fields could include road segment names, place names, etc. When the query method is applied to a terminal, the query string is received through a query interface. When the query method is applied to a server, it can receive query requests sent by the terminal, which include the query string.

[0057] In one embodiment, the query page includes field hints, which include candidate query fields. This allows users to select the target query field from the candidate fields, determine the corresponding query conditions based on the target query field, and thus form a custom query expression.

[0058] Step 220: Parse the query expression. Divide the query expression into basic query units based on the connectors in the query expression. The basic query unit includes conditional statements and field statements. Obtain the configuration information corresponding to the basic query unit. Form sub-query units with the same configuration information into sub-query units according to the order of the basic query units. The configuration information is used to determine the target query method corresponding to the sub-query unit. Query the sub-query result corresponding to the sub-query unit according to the target query method corresponding to the sub-query unit.

[0059] Specifically, when parsing query expressions, a custom parsing algorithm can be defined, such as parsing from left to right, identifying delimiters, and obtaining various basic query units. These basic query units include field statements, and different types of configuration information can be pre-configured for different types of field statements. This configuration information determines the target query method, which includes the query data source, query data table, and query database. For example, fields with accurate information like gender and name are configured with a first-type database, while disease types, which may have multiple similar names in different countries and regions, are configured with a second-type database. Different query data tables can also be configured for different fields, and the matching relationships between field names and query data table identifiers, query data source identifiers, and query database identifiers can be pre-stored.

[0060] Based on the matching relationship, basic query units can be combined. According to the configuration of the basic query units, basic query units with the same configuration can be combined. When combining the basic query units, pay attention to the order of each basic query unit. That is, basic query units that appear consecutively and have the same target query method are combined to form a sub-query unit. For example, if the first basic query unit and the second basic query unit are adjacent basic query units and have the same query database, then the first basic query unit and the second basic query unit form the first sub-query unit.

[0061] By forming sub-query units with the same configuration information from basic query units, and since the sub-query units have the same target query method, such as the same query database and the same query method, the query of multiple basic query units is converted into a single query through the sub-query unit, thereby improving query efficiency.

[0062] Step 230: When the subquery result corresponding to each subquery unit is a combined query result, combine the subquery results to obtain the target query result corresponding to the query string.

[0063] Specifically, when there are multiple subquery units, there are multiple subquery results. A custom algorithm can be used to process each subquery result to obtain the target query result corresponding to the query string. The processing method is not limited. When the subquery results corresponding to each subquery unit are combined query results, the subquery results are directly combined to obtain the target query result corresponding to the query string.

[0064] Step 240: When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type subquery unit and a second type subquery unit. The second type subquery unit has a corresponding second query result. The query database corresponding to the first type subquery unit is updated through the second query result. The target query result corresponding to the query string is retrieved based on the updated query database.

[0065] Specifically, the quadratic query result indicates that the target query result needs to be determined again based on the subquery result. The query database corresponding to the first type of subquery unit is updated through the second query result. The update operation can be customized, including modification, writing, etc. The query string is queried in the updated query database corresponding to the first type of subquery unit to obtain the target query result corresponding to the query string.

[0066] In this embodiment, a query string is obtained, which includes a custom query expression. The query expression is parsed, and it is segmented according to the connectors in the query expression to obtain corresponding basic query units. Each basic query unit includes conditional statements and field statements. Configuration information corresponding to the basic query units is obtained. Basic query units with the same configuration information are formed into sub-query units according to the order of the basic query units. The configuration information is used to determine the target query method corresponding to the sub-query unit. The sub-query result corresponding to the sub-query unit is obtained according to the target query method corresponding to the sub-query unit. When the sub-query results corresponding to each sub-query unit are combined query results, the sub-query results are combined to obtain the target query result corresponding to the query string. When the sub-query results corresponding to each sub-query unit are quadratic query results, the sub-query unit includes... It includes a first type of subquery unit and a second type of subquery unit. The second type of subquery unit has a corresponding second query result. The query database corresponding to the first type of subquery unit is updated by the second query result. The target query result corresponding to the query string is retrieved based on the updated query database. The query conditions and query fields are all controlled and freely combined by the user through custom query expressions, and the query data is dynamically expanded. Furthermore, the basic query units are formed into corresponding subquery units through configuration information. Different subquery units have different target query methods. The subquery results corresponding to each subquery unit are obtained through the target query method, and then integrated to obtain the target query result. Only by modifying the configuration data, thereby modifying the configuration information corresponding to the basic query units, the purpose of modifying the query structure can be achieved. It is flexible and convenient, and improves the scalability and convenience of the query.

[0067] In one embodiment, after obtaining the query string, the method further includes: detecting the query string; when the query string contains errors, repairing it to obtain a repaired query string; the repair includes at least one of the following methods: when the query string contains erroneous fields, obtaining the current condition statement corresponding to the erroneous field, and deleting the erroneous field statement and the current condition statement corresponding to the erroneous field; when the query string contains redundant fields, deleting the field statements corresponding to the redundant fields; when the query string contains syntax errors, correcting the incorrect syntax connectors.

[0068] Specifically, an erroneous field refers to a field that does not exist in the query database. In one embodiment, when the current field corresponding to a field statement does not exist in the query database, similar fields corresponding to the current field are obtained. If the similar field does not exist in the query database, the current field is determined to be an erroneous field. This corrects the user-inputted field by using similar fields, improving the flexibility of the retrieval. When an erroneous field exists, since no matching results can be found, the erroneous field statement and the current condition statement corresponding to the erroneous field need to be deleted. Unknown fields can be a type of erroneous field. Redundant fields refer to fields that are extra in the query string. For example, if a condition statement corresponds to multiple field statements, and it is unknown which field the condition statement specifically corresponds to, the extra fields need to be deleted. For example, in the query string "Male [Gender] 30 [Age] [Amount]", one of "[Age] [Amount]" needs to be deleted. When deleting, fields that are far from the condition statement can be deleted, or the redundant field can be matched with the context field. Successful matches are retained, and unsuccessful matches are deleted. If the context field is an entertainment field and the redundant field is a medical field, the match will obviously fail. Grammatical errors include omitting the conjunction AND or OR, such as "male [gender] 30 [age]", or using multiple AND or OR directly together, such as "male [gender] AND OR AND 30 [age]", etc.

[0069] In this embodiment, the fault tolerance of the query is improved by detecting and repairing the query string.

[0070] In one embodiment, step 220 includes: when the target query method corresponding to the first type of sub-query unit is an exact query, determining that the target query database corresponding to the first type of sub-query unit is a relational database; when the target query method corresponding to the second type of sub-query unit is a fuzzy query, determining that the target query database corresponding to the second type of sub-query unit is a retrieval database; and obtaining the corresponding second query result based on the query of the second type of sub-query unit in the retrieval database.

[0071] Specifically, relational database queries are relatively fixed and suitable for fixed queries such as names and phone numbers, like Oracle databases. Searchable databases are used for fuzzy queries, similar to Baidu search, like SOLR databases. When configured for exact queries, relational databases are suitable; when configured for fuzzy queries, searchable databases are suitable, yielding a second query result. For example, the query "Male [Gender] AND Hunan [Address] OR Liver Cancer [Electronic Medical Record]" can be configured to query the SOLR database for 'Liver Cancer [Electronic Medical Record]', and query Oracle databases for other conditions.

[0072] Step 240 includes: writing the second query result into the relational database corresponding to the first type of subquery unit, combining the subquery units into a complete query unit, and querying the relational database based on the complete query unit to obtain the target query result.

[0073] Specifically, the second query result is written to a relational database. For example, the second query result obtained from the SOLR database can be converted into data that can be recognized by the ORACLE database and written to the ORACLE database. Then, the target query result is obtained by querying the complete string "male[gender] AND Hunan[address] OR liver cancer[electronic medical record]" using ORACLE.

[0074] In this embodiment, the query expression can be parsed to break down the data into various sub-query units, then query the data in different types of databases according to the configuration, and finally integrate the queried data together. By configuring different fields in different databases, the accuracy of the query is improved, and the query can be performed adaptively.

[0075] In one embodiment, the method further includes: obtaining a new data table, comparing the original candidate fields of the query database with the fields in the new data table, and when a new field exists in the new data table, using the new field as a new candidate field, and matching the corresponding configuration information for the new candidate field.

[0076] Specifically, the initial candidate fields can be either the database's initial default candidate fields or historical candidate fields. Because different user data differs, the initial default candidate fields may not meet the field requirements of the user's data. Therefore, when a user's newly added data table contains fields that are not among the initial candidate fields for querying the database, these new fields need to be added as new candidate fields. Corresponding configuration information, including the query method and the query database, should be matched for each new candidate field. In subsequent queries, the new field will be queried using the target query method that matches the configuration information. Candidate fields can be displayed on the query page as field suggestions, making it easier for users to select the target query field from the candidate fields.

[0077] In this embodiment, when a new field is added, the corresponding configuration information is matched for the new candidate field, so that the query database is continuously expanded and the number of optional fields for querying is continuously increased.

[0078] In one embodiment, comparing the original candidate fields in the query database with the fields in the newly added data table includes: when there is a new field in the newly added data table, calculating the similarity between the new field and each original candidate field, obtaining the target original candidate field whose similarity to the new field exceeds a preset threshold, establishing the association between the new field and the target original candidate field, and using the configuration information corresponding to the target original candidate field as the configuration information corresponding to the new field.

[0079] Specifically, when the similarity between a newly added field and an original candidate field exceeds a preset threshold, it indicates that the newly added field and the original candidate field are synonyms. In this case, the original candidate field with the similarity exceeding the preset threshold is used as the target original candidate field. Only the association between the newly added field and the target original candidate field needs to be established. Subsequently, when querying a current field, similar fields can be obtained based on the association, thus determining the target query method for the current field based on the configuration information of similar fields, and ultimately obtaining the corresponding query results. By matching similar fields, meaningless additions of fields are reduced, improving the configuration efficiency of queries.

[0080] It should be understood that, although Figure 2 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0081] In one embodiment, such as Figure 3 As shown, a query device is provided, including: an acquisition module 310, a subquery result determination module 320, a first target query result determination module 330, and a second target query result determination module 340, wherein:

[0082] The acquisition module 310 is used to acquire the query string, which includes a custom query expression.

[0083] The subquery result determination module 320 is used to parse the query expression, divide the query expression into corresponding basic query units according to the connectors in the query expression, and obtain the configuration information corresponding to the basic query units. The basic query units include conditional statements and field statements. The module obtains the configuration information corresponding to the basic query units, and forms subquery units with the same configuration information according to the order of the basic query units. The configuration information is used to determine the target query method corresponding to the subquery unit. The module obtains the subquery result corresponding to the subquery unit according to the target query method corresponding to the subquery unit.

[0084] The first target query result determination module 330 is used to combine the subquery results to obtain the target query result corresponding to the query string when the subquery results corresponding to each subquery unit are combined query results.

[0085] The second target query result determination module 340 is used to update the query database corresponding to the first type of subquery unit when the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type of subquery unit and a second type of subquery unit, the second type of subquery unit has a corresponding second query result, the query database corresponding to the first type of subquery unit is updated through the second query result, and the target query result corresponding to the query string is retrieved according to the updated query database.

[0086] In one embodiment, the apparatus further includes:

[0087] The processing module 350 is used to detect errors in the query string. When errors are found in the query string, it repairs the query string to obtain a repaired query string. The repair includes at least one of the following methods: when there are erroneous fields in the query string, the current condition statement corresponding to the erroneous field is obtained, and the erroneous field statement and the current condition statement corresponding to the erroneous field are deleted; when there are redundant fields in the query string, the field statements corresponding to the redundant fields are deleted; when there are syntax errors in the query string, the incorrect syntax connectors are corrected.

[0088] In one embodiment, the subquery result determination module 320 is further configured to determine that the target query database corresponding to the first type of subquery unit is a relational database when the target query method corresponding to the first type of subquery unit is an exact query, and to determine that the target query database corresponding to the second type of subquery unit is a retrieval database when the target query method corresponding to the second type of subquery unit is a fuzzy query, and to obtain the corresponding second query result based on the query of the second type of subquery unit in the retrieval database.

[0089] The second target query result determination module 340 is also used to write the second query result into the relational database corresponding to the first type of sub-query unit, combine the sub-query units to form a complete query unit, and query the relational database based on the complete query unit to obtain the target query result.

[0090] In one embodiment, the apparatus further includes:

[0091] The 360 ​​New Fields module is used to obtain new data tables. It compares the original candidate fields in the database with the fields in the new data tables. When a new field exists in the new data tables, it is used as a candidate field for new data tables, and the corresponding configuration information is matched for the candidate field.

[0092] In one embodiment, the new field module 360 ​​is further configured to calculate the similarity between the new field and each original candidate field when there is a new field in the new data table, obtain the target original candidate field whose similarity to the new field exceeds a preset threshold, establish the association between the new field and the target original candidate field, and use the configuration information corresponding to the target original candidate field as the configuration information corresponding to the new field.

[0093] For specific limitations regarding the query device, please refer to the limitations on the query method above, which will not be repeated here. Each module in the aforementioned query device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0094] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, network interface, input device, and display screen connected via a system bus. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and may also store computer programs. When executed by the processor, these computer programs cause the processor to perform a polling method. The internal memory may also store computer programs, which, when executed by the processor, cause the processor to perform a data processing method. The display screen can be an LCD screen or an e-ink screen. The input device can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device's casing, or an external keyboard, touchpad, or mouse.

[0095] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and the database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data tables. The network interface communicates with external terminals via a network connection. When executed by the processor, the computer program implements a query method.

[0096] Those skilled in the art will understand that Figure 4 , Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0097] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: obtaining a query string, the query string including a custom query expression; parsing the query expression, dividing the query expression according to the connectors in the query expression to obtain corresponding basic query units, the basic query units including conditional statements and field statements; obtaining configuration information corresponding to the basic query units; forming sub-query units with the same configuration information according to the order of the basic query units, the configuration information being used to determine the target query method corresponding to the sub-query unit; querying the sub-query result corresponding to the sub-query unit according to the target query method corresponding to the sub-query unit; when the sub-query result corresponding to each sub-query unit is a combined query result, combining the sub-query results to obtain the target query result corresponding to the query string; when the sub-query result corresponding to each sub-query unit is a quadratic query result, the sub-query unit includes a first type sub-query unit and a second type sub-query unit, the second type sub-query unit having a corresponding second query result; updating the query database corresponding to the first type sub-query unit through the second query result; retrieving the target query result corresponding to the query string according to the updated query database.

[0098] In one embodiment, when the processor executes the computer program, it further performs the following steps: detecting the query string, and when the query string contains errors, repairing it to obtain a repaired query string. The repair includes at least one of the following methods: when the query string contains erroneous fields, obtaining the current condition statement corresponding to the erroneous field, and deleting the erroneous field statement and the current condition statement corresponding to the erroneous field; when the query string contains redundant fields, deleting the field statements corresponding to the redundant fields; and when the query string contains syntax errors, correcting the incorrect syntax connectors.

[0099] In one embodiment, obtaining the subquery result corresponding to the subquery unit based on the target query method of the subquery unit includes: when the target query method corresponding to the first type of subquery unit is an exact query, determining that the target query database corresponding to the first type of subquery unit is a relational database; when the target query method corresponding to the second type of subquery unit is a fuzzy query, determining that the target query database corresponding to the second type of subquery unit is a retrieval database; and obtaining the corresponding second query result based on the second type of subquery unit in the retrieval database. When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type of subquery unit and a second type of subquery unit, and the second type of subquery unit has a corresponding second query result. Updating the query database corresponding to the first type of subquery unit using the second query result, and retrieving the target query result corresponding to the query string based on the updated query database includes: writing the second query result into the relational database corresponding to the first type of subquery unit; combining the subquery units into a complete query unit; and obtaining the target query result based on the complete query unit in the relational database.

[0100] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining a new data table, comparing the original candidate fields of the query database with the fields in the new data table, and when a new field exists in the new data table, using the new field as a new candidate field, and matching the corresponding configuration information for the new candidate field.

[0101] In one embodiment, comparing the original candidate fields in the query database with the fields in the newly added data table includes: when there is a new field in the newly added data table, calculating the similarity between the new field and each original candidate field; obtaining the target original candidate field whose similarity to the new field exceeds a preset threshold, establishing the association between the new field and the target original candidate field, and using the configuration information corresponding to the target original candidate field as the configuration information corresponding to the new field.

[0102] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps: obtaining a query string, the query string including a custom query expression; parsing the query expression, dividing the query expression according to the connectors in the query expression to obtain corresponding basic query units, the basic query units including conditional statements and field statements; obtaining configuration information corresponding to the basic query units; forming sub-query units with the same configuration information according to the order of the basic query units, the configuration information being used to determine the target query method corresponding to the sub-query unit; querying the sub-query result corresponding to the sub-query unit according to the target query method corresponding to the sub-query unit; when the sub-query results corresponding to each sub-query unit are combined query results, combining the sub-query results to obtain the target query result corresponding to the query string; when the sub-query results corresponding to each sub-query unit are quadratic query results, the sub-query unit includes a first type sub-query unit and a second type sub-query unit, the second type sub-query unit having a corresponding second query result; updating the query database corresponding to the first type sub-query unit through the second query result; retrieving the target query result corresponding to the query string according to the updated query database.

[0103] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: detecting the query string, and when the query string contains errors, repairing it to obtain a repaired query string. The repair includes at least one of the following methods: when the query string contains erroneous fields, obtaining the current condition statement corresponding to the erroneous field, and deleting the erroneous field statement and the current condition statement corresponding to the erroneous field; when the query string contains redundant fields, deleting the field statements corresponding to the redundant fields; and when the query string contains syntax errors, correcting the incorrect syntax connectors.

[0104] In one embodiment, obtaining the subquery result corresponding to the subquery unit based on the target query method of the subquery unit includes: when the target query method corresponding to the first type of subquery unit is an exact query, determining that the target query database corresponding to the first type of subquery unit is a relational database; when the target query method corresponding to the second type of subquery unit is a fuzzy query, determining that the target query database corresponding to the second type of subquery unit is a retrieval database; and obtaining the corresponding second query result based on the second type of subquery unit in the retrieval database. When the subquery result corresponding to each subquery unit is a quadratic query result, the subquery unit includes a first type of subquery unit and a second type of subquery unit, and the second type of subquery unit has a corresponding second query result. Updating the query database corresponding to the first type of subquery unit using the second query result, and retrieving the target query result corresponding to the query string based on the updated query database includes: writing the second query result into the relational database corresponding to the first type of subquery unit; combining the subquery units into a complete query unit; and obtaining the target query result based on the complete query unit in the relational database.

[0105] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining a new data table, comparing the original candidate fields of the query database with the fields in the new data table, and when a new field exists in the new data table, using the new field as a new candidate field, and matching the corresponding configuration information for the new candidate field.

[0106] In one embodiment, comparing the original candidate fields in the query database with the fields in the newly added data table includes: when there is a new field in the newly added data table, calculating the similarity between the new field and each original candidate field; obtaining the target original candidate field whose similarity to the new field exceeds a preset threshold, establishing the association between the new field and the target original candidate field, and using the configuration information corresponding to the target original candidate field as the configuration information corresponding to the new field.

[0107] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0108] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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.

[0109] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A query method, the method comprising: obtaining a query string, the query string comprising a self-defined query expression; parsing the query expression, splitting the query expression according to a connector in the query expression to obtain corresponding basic query units, the basic query units comprising condition statements and field statements; obtaining configuration information corresponding to the basic query units, forming sub-query units from basic query units with the same configuration information according to the order of the basic query units, the configuration information being used to determine a target query mode corresponding to the sub-query units, the target query mode comprising a query data source, a query data table, a query database, different query data tables and different types of query databases being configured for different fields, the basic query units comprising field statements, different types of configuration information being configured in advance for different types of field statements; querying sub-query results corresponding to the sub-query units according to the target query mode corresponding to the sub-query units, comprising: when a target query mode corresponding to a first type of sub-query unit is a precise query, determining that a target query database corresponding to the first type of sub-query unit is a relational database, when a target query mode corresponding to a second type of sub-query unit is a fuzzy query, determining that a target query database corresponding to the second type of sub-query unit is a retrieval database, and querying a corresponding second query result in the retrieval database according to the second type of sub-query unit; when the sub-query results corresponding to each sub-query unit are combined query results, combining the sub-query results to obtain a target query result corresponding to the query string; when the sub-query results corresponding to each sub-query unit are quadratic query results, the sub-query units comprising the first type of sub-query unit and the second type of sub-query unit, the second type of sub-query unit having a corresponding second query result, updating a query database corresponding to the first type of sub-query unit through the second query result, retrieving the target query result corresponding to the query string according to the updated query database, comprising: writing the second query result into a relational database corresponding to the first type of sub-query unit, combining each sub-query unit to form a complete query unit, and querying the target query result in the relational database according to the complete query unit; obtaining a new data table, when there is a new field in the new data table, taking the new field as a new candidate field, matching configuration information corresponding to the new candidate field, comprising: calculating the similarity between the new field and each original candidate field; obtaining a target original candidate field with a similarity to the new field exceeding a preset threshold, establishing an association between the new field and the target original candidate field, and taking configuration information corresponding to the target original candidate field as configuration information corresponding to the new field.

2. The method of claim 1, wherein, After obtaining the query string, the method further comprises: detecting the query string, when the query string has errors, repairing to obtain a repaired query string, the repairing comprising at least one of the following methods: When the query string has an error field, a current condition statement corresponding to the error field is obtained, and the error field statement and the current condition statement corresponding to the error field are deleted; When the query string has a redundant field, the field statement corresponding to the redundant field is deleted; When the query string has a syntax error, the error syntax connector is corrected.

3. The method of claim 1, wherein, The writing of the second query result into the relational database corresponding to the first type of subquery unit includes: The second query result obtained by querying the SOLR database is converted into data recognizable by the ORACLE database and written into the ORACLE database.

4. The method of claim 1, wherein, The original candidate field is an initial default candidate field of the database or a historical candidate field.

5. The method of claim 4, wherein, The method further includes: Fields with accurate information are configured in the first type of database, and fields with multiple similar names in different countries and regions are configured in the second type of database.

6. A query device, characterized in that The device includes: An acquisition module is configured to acquire a query string, the query string including a self-defined query expression; A subquery result determination module is configured to parse the query expression, split the query expression according to a connector in the query expression to obtain corresponding basic query units, the basic query units including condition statements and field statements, acquire configuration information corresponding to the basic query units, form subquery units from the basic query units with the same configuration information according to an order of the basic query units, the configuration information being used to determine a target query mode of the subquery units, the target query mode including a query data source, a query data table, and a query database, different query data tables and different types of query databases being configured for different fields, different types of configuration information being configured for different types of field statements in advance, and a subquery result corresponding to each subquery unit being obtained according to a target query mode of the subquery unit, including: when a target query mode of a first type of subquery unit is a precise query, determining that a target query database corresponding to the first type of subquery unit is a relational database, when a target query mode of a second type of subquery unit is a fuzzy query, determining that a target query database corresponding to the second type of subquery unit is a retrieval database, and a second query result corresponding to the second type of subquery unit being obtained by querying the retrieval database; A first target query result determination module is configured to combine each subquery result to obtain a target query result corresponding to the query string when the subquery result corresponding to each subquery unit is a combined query result. The second target query result determination module is configured to, when the subquery result corresponding to each subquery unit is a quadratic form query result, the subquery unit includes a first type subquery unit and a second type subquery unit, the second type subquery unit has a corresponding second query result, the query database corresponding to the first type subquery unit is updated through the second query result, the target query result corresponding to the query string is obtained through retrieval according to the updated query database, and the target query result is obtained through the following steps: the second query result is written into the relational database corresponding to the first type subquery unit, each subquery unit is combined to form a complete query unit, and the target query result is obtained through query in the relational database according to the complete query unit; the newly added data table is obtained, when the newly added field exists in the newly added data table, the newly added field is taken as a newly added candidate field, corresponding configuration information of the newly added candidate field is matched, the similarity between the newly added field and each original candidate field is calculated, the target original candidate field whose similarity with the newly added field exceeds a preset threshold is obtained, the association relationship between the newly added field and the target original candidate field is established, and the configuration information corresponding to the target original candidate field is taken as the configuration information corresponding to the newly added field.

7. The apparatus of claim 6, wherein, The apparatus further includes: The processing module is configured to detect the query string, and when the query string has an error, a repaired query string is obtained through repair, the repair including at least one of the following modes: when the query string has an error field, a current condition statement corresponding to the error field is obtained, and an error field statement and the current condition statement corresponding to the error field are deleted; when the query string has a redundant field, a field statement corresponding to the redundant field is deleted; and when the query string has a syntax error, an incorrect syntax connector is corrected.

8. The apparatus of claim 6, wherein The second target query result determination module is further configured to convert the second query result obtained through query in the SOLR database into data recognizable by the ORACLE database and write the data into the ORACLE database. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the method in any one of claims 1 to 6.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • An interactive natural language query conversion method

    CN109947794A