CN115878661A - Query method, query device, electronic equipment and storage medium - Google Patents

Query method, query device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115878661A
CN115878661A CN202211461872.9A CN202211461872A CN115878661A CN 115878661 A CN115878661 A CN 115878661A CN 202211461872 A CN202211461872 A CN 202211461872A CN 115878661 A CN115878661 A CN 115878661A
Authority
CN
China
Prior art keywords
query
clause
json
target
clauses
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211461872.9A
Other languages
Chinese (zh)
Inventor
宛嵇祥
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Agricultural Bank of China
Original Assignee
Agricultural Bank of China
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Agricultural Bank of China filed Critical Agricultural Bank of China
Priority to CN202211461872.9A priority Critical patent/CN115878661A/en
Publication of CN115878661A publication Critical patent/CN115878661A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a query method, a query device, electronic equipment and a storage medium. The method comprises the following steps: acquiring a query sentence, wherein the query sentence comprises at least one key phrase clause and a relation clause, and the key phrase clauses are connected through the relation clause; inquiring in an inverted index of a JSON database by a JavaScript object representation method respectively according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through a relation clause, and the connection relation between the target mode lists is the same as that between the keyword group clauses; determining a target query plan according to the target mode list; and querying in a JSON database according to the target query plan to obtain a query result. The scheme provided by the invention can realize fuzzy query of the JSON database, can adapt to various different non-relational databases based on JSON documents, is suitable for various data modes, realizes automatic adaptation of the data modes and has high expandability.

Description

Query method, query device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of database management technologies, and in particular, to a query method, an apparatus, an electronic device, and a storage medium.
Background
In a big data analysis scenario, data from different data sources are required to be stored uniformly, and then a uniform query interface is used for querying and analyzing.
JavaScript Object Notation (JSON) is a commonly used data representation format, and has the characteristics of strong expressive force, flexible and changeable modes, and the like. JSON data from different data sources often have different modes, and when the data are analyzed in a unified mode, statements in a specific format are used for inquiring the content of the data, so that the analysis efficiency can be greatly improved.
However, the existing query methods, such as JSONPath and the like, are based on traditional XPath query syntax design, and when performing unified query on JSON data in multiple different modes, data query statements need to be written respectively and specifically, which is time-consuming and labor-consuming, and cannot be well adapted to new data modes. In addition, the existing JSON data query interface can only match field names based on a simple regular mechanism and does not have the characteristic of fuzzy query.
Disclosure of Invention
The invention provides a query method, a query device, electronic equipment and a storage medium, which can realize fuzzy query of a JSON database, can be adapted to various different non-relational databases based on JSON documents, is suitable for various data modes, realizes automatic adaptation of the data modes and has high expandability.
According to an aspect of the present invention, there is provided a query method, including:
acquiring a query sentence, wherein the query sentence comprises at least one key phrase clause and a relation clause, and the key phrase clauses are connected through the relation clause;
inquiring in an inverted index of a JavaScript object notation JSON database according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through a relation clause, and the connection relation between the target mode lists is the same as that between the keyword group clauses;
determining a target query plan according to the target mode list;
and querying in a JSON database according to the target query plan to obtain a query result.
Optionally, the JSON database comprises a plurality of JSON documents; before obtaining the query statement, the method further comprises:
respectively determining a data mode and a document corresponding relation list of each JSON document, wherein the document corresponding relation list comprises corresponding relations of each value contained in the JSON document and a query path thereof;
performing word segmentation processing on query paths in all document corresponding relation lists to obtain a keyword list, wherein the keyword list comprises a plurality of keywords;
and generating an inverted index according to the keyword list, the data modes of all JSON documents and the document corresponding relation list, wherein the inverted index comprises the corresponding relation between the keywords and the query path, and the JSON documents and the data modes to which the query path belongs.
Optionally, obtaining the query statement includes:
receiving an original sentence input by a user;
analyzing the original sentence to obtain a key phrase clause AND a relation clause, wherein each key phrase clause comprises at least two key words, a query operator AND a query operand, AND the relation clause comprises an AND clause AND/OR an OR clause;
and connecting the key phrase clauses through the relation clauses to generate a query sentence.
Optionally, for any keyword phrase clause; according to the key phrase clauses, inquiring in an inverted index of a JSON database to obtain a target mode list, wherein the method comprises the following steps:
matching at least two keywords included in the keyword group clause in the inverted index to obtain an original mode list;
and filtering the original mode list according to the constraint condition to obtain a target mode list.
Optionally, the constraint condition includes a first constraint sub-condition and a second constraint sub-condition; wherein, the first and the second end of the pipe are connected with each other,
the first constraint sub-condition is that each keyword matches a segment which is not overlapped with each other on the query path and the segment comprises all keywords in the keyword group clause;
the second constraint sub-condition is that the matched path segments among different keywords satisfy the sequence of the keywords in the keyword group clause.
Optionally, determining the target query plan according to the target mode list includes:
constructing an original query plan according to the target mode list, the query operational characters and the query operands;
and optimizing the original query plan to obtain a target query plan.
Optionally, the original query plan is optimized according to principles 1 and 2, or according to principles 1 and 3:
principle 1: for at least two target mode lists connected with the AND clause, taking the intersection of the data modes related to each target mode list, AND removing the data modes only existing in part of the target mode lists;
principle 2: grouping at least two target mode lists connected with the AND clauses according to the related data modes, AND constructing an AND query statement in each data mode;
principle 3: AND grouping at least two target mode lists connected by the AND clauses according to the incidence relation of the related data modes, AND disassembling the at least two target mode lists into a plurality of AND query statements without correlation.
According to another aspect of the present invention, there is provided a query apparatus, including: the system comprises a statement analysis module, a mode query module, a plan determination module and an execution module; wherein the content of the first and second substances,
the sentence analyzing module is used for acquiring a query sentence, wherein the query sentence comprises at least one keyword group clause and a relation clause, and the keyword group clauses are connected through the relation clause;
the mode query module is used for querying in an inverted index of a JavaScript object notation (JSON) database according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through the relation clauses, and the connection relation between the target mode lists is the same as that between the keyword group clauses;
the plan determining module is used for determining a target query plan according to the target mode list;
and the execution module is used for querying in the JSON database according to the target query plan to obtain a query result.
According to another aspect of the present invention, there is provided an electronic apparatus including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the query method of any of the embodiments of the invention.
According to another aspect of the present invention, there is provided a computer-readable storage medium storing computer instructions for causing a processor to implement a query method according to any one of the embodiments of the present invention when the computer instructions are executed.
According to the technical scheme of the embodiment of the invention, a query sentence comprising at least one key phrase clause and at least one relation clause is constructed, then according to each key phrase clause, at least one target mode list is obtained by querying in an inverted index of a JSON database, and a target query plan is further determined, so that query is carried out in the JSON database according to the target query plan, and a query result is obtained. Compared with the existing query method, the target query plan constructed based on the query of the phrase clauses can realize the fuzzy query of the JSON database; the query interface is irrelevant to the specific database implementation during query, and the method can be adapted to various different JSON document-based non-relational databases; meanwhile, the data mode is determined through the JSON document form, and the data query statement does not need to be written in a targeted manner, so that the method is suitable for various data modes, automatic adaptation of the data modes is realized, and the expandability is high.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present invention, nor do they necessarily limit the scope of the invention. Other features of the present invention will become apparent from the following description.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart of a query method according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a query method according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of an inquiry apparatus according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of another query device according to a third embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention.
Detailed Description
In order to make those skilled in the art better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," "original," "target," and the like in the description and claims of the invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Moreover, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example one
Fig. 1 is a schematic flowchart of a query method according to an embodiment of the present invention, where the present embodiment is applicable to a case of querying a JSON database, and the method may be executed by a query device, where the query device may be implemented in hardware and/or software, and the query device may be configured in an electronic device (such as a computer or a server). As shown in fig. 1, the method includes:
s110, obtaining a query sentence, wherein the query sentence comprises at least one keyword group clause and a relation clause, and the keyword group clauses are connected through the relation clause.
A query statement is any statement that is constructed based on the original statement input by the user. The query sentence comprises at least one key phrase clause and a relation clause, the key phrase clauses are connected through the relation clause, and the connected query sentence can be of a tree structure.
In one embodiment, each keyword group clause includes at least two keywords, a query operator, and a query operand; the relational clauses include AND clauses AND/OR clauses.
And S120, inquiring in the inverted index of the JSON database according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through the relation clauses, and the connection relation between the target mode lists is the same as that between the keyword group clauses.
JSON is a lightweight data exchange format, the content of which is composed of attributes and values and is easy to read and process. Some document-based non-relational databases, such as MongoDB, couchDB, etc., typically select JSON or its variants as the format for their data storage, transmission.
The inverted index is also called an inverted index, and is an indexing method for storing a mapping of a storage location of a word in a document or a group of documents in a full-text search, which is the most commonly used data structure in a document retrieval system.
The JSON database includes a plurality of JSON documents (which may also be understood as JSON data), and the inverted index of the JSON database is generated based on the JSON documents in the JSON database. Specifically, the step of generating the inverted index may be performed before the step S110 is performed, that is, before the user has a query requirement, the inverted index may be generated based on the JSON document in the JSON database, so that the pre-generated inverted index may be directly read in the step S120, so as to save the query time.
It can be understood that when the JSON database has updates, such as deleting, modifying, and adding JSON documents, the inverted index also needs to be updated accordingly to ensure the accuracy of the query result.
Since the query sentence includes at least one keyword group clause, and each keyword group clause has independence, in step S120, the query device needs to query in the inverted index for each keyword group clause to obtain the target mode list corresponding to the keyword group clause.
Specifically, the manner of obtaining the target mode list may refer to the description in the following second embodiment, and for brevity, will not be described herein again.
And S130, determining a target query plan according to the target mode list.
And S140, querying in a JSON database according to the target query plan to obtain a query result.
The query results may be presented to the user in the form of JSON documents.
Therefore, the target query plan constructed based on the keyword group clause query can realize the fuzzy query of the JSON database; the query interface is irrelevant to the specific database implementation during query, and the method can be adapted to various different JSON document-based non-relational databases.
Example two
Fig. 2 is a schematic flowchart of a query method according to a second embodiment of the present invention, and the present embodiment provides a detailed query method based on a JSON database on the basis of the first embodiment.
As shown in fig. 2, the method includes:
s201, respectively determining a data mode and a document corresponding relation list of each JSON document of the JSON database, wherein the document corresponding relation list comprises corresponding relations of each value contained in the JSON document and a query path of the value.
The JSON database comprises a plurality of JSON documents, and the data mode of the JSON documents can be determined by scanning each field in the JSON documents, namely the data mode of the JSON documents is determined by each field in the JSON documents. Illustratively, each field in a JSON document can be scanned using a recursive scan.
The data schema of a JSON document defines the structure and content form of the data. For JSON documents, its data schema determines what name fields are in the document and what type of contents of the fields are. The data schema is generally determined by the design of the application system, and different application systems often define and store different schemas of data.
For example, by scanning, it can be seen that: JSON document 1 includes field 1 and field 2, JSON document 2 includes field 1 and field 3, and JSON document 3 includes field 1 and field 2. It can be concluded that the data schemas of JSON document 1 and JSON document 2 are different, the data schemas of JSON document 1 and JSON document 3 are the same, and the data schemas of JSON document 2 and JSON document 3 are different.
Typically, a JSON document includes at least one field, each field corresponding to at least one value V, one value V corresponding to a query path P. The query path P is an ordered list of all field names that need to access the current value V, starting from the root of the JSON document. By scanning each field in the JSON document, the value V corresponding to each field of the JSON document and the query path P thereof can be obtained, and a document corresponding relation list is further established.
For example, suppose JSON document 1 includes field 1 and field 2, field 1 corresponds to values V11 and V12, the query path corresponding to value V11 is P11, and the query path corresponding to value V12 is P12; the field 2 corresponds to values V21, V22 and V23, the query path corresponding to the value V21 is P21, the query path corresponding to the value V22 is P22, and the query path corresponding to the value V23 is P23. Then, the document correspondence list of JSON document 1 can be as shown in table 1.
TABLE 1
Value of Query path
V11 P11
V12 P12
V21 P21
V22 P22
V23 P23
S202, performing word segmentation processing on the query paths in the corresponding relation list of all the documents to obtain a keyword list, wherein the keyword list comprises a plurality of keywords.
After the document corresponding relation lists of all JSON documents are obtained, word segmentation processing is carried out on query paths in all the document corresponding relation lists, long sentences representing the query paths are divided into independent keywords, and all the keywords are summarized to obtain a keyword list. If the partial keywords after word segmentation processing of different query paths are the same, the same keywords are combined in the keyword list. For example, the query path P11 is subjected to word segmentation to obtain the keyword 1 and the keyword 2, and the query path P12 is subjected to word segmentation to obtain the keyword 2 and the keyword 3, so that the keywords included in the keyword list are: keyword 1, keyword 2, and keyword 3.
Specifically, the word segmentation processing in the present invention may be implemented based on word segmentation, or based on some existing neural-Linguistic Programming (NLP) word segmentation engine.
S203, generating an inverted index according to the keyword list, the data modes of all JSON documents and the document corresponding relation list, wherein the inverted index comprises the corresponding relation between the keywords and the query path, the JSON documents to which the query path belongs and the data modes.
Based on the above steps S201-S202, an inverted index can be generated by combining the keyword list, the data patterns of all JSON documents, and the document correspondence list, where the inverted index includes the correspondence between the keywords and the query path, and the JSON document and data pattern to which the query path belongs.
In one embodiment, the querying device may also associate the data schema with a JSON document, and two JSON documents with the same data schema may be mapped to the same set. And querying the mode information corresponding to the set to obtain the set of all JSON documents with the data mode.
It should be noted that steps S201 to S203 need only be executed once in the whole process, that is, before the user has a query requirement, the reverse index may be generated based on the JSON document in the JSON database, so that the previously generated reverse index may be directly read each time the user has a query requirement, thereby saving the query time.
Of course, when the JSON database is updated, such as deleting, modifying, and adding JSON documents, the inverted index also needs to be updated accordingly to ensure the accuracy of the query result.
And S204, receiving an original sentence input by a user.
The original sentence is a query instruction input by a user, such as "name and time of entry of an employee", "house number or parking space number of an owner", and the like.
S205, analyzing the original sentence to obtain a keyword group clause AND a relation clause, wherein each keyword group clause comprises at least two keywords, a query operator AND a query operand, AND the relation clause comprises an AND clause AND/OR an OR clause.
In one embodiment, the types of query operators and query operands are determined according to the implementation details of the selected non-relational database. The query operator and the query operand at least support: the operations of equal, unequal, containing, not containing, prefix and suffix of the character string; numerical values are greater than, less than, equal to, greater than or equal to, less than or equal to operations.
Each AND clause can be connected with any number of key phrase clauses, AND the query result of the AND clause is the intersection of all clause results below the AND clause.
Each OR clause can be connected with any number of key phrase clauses, and the query result of the OR clause is the union of all clause results below the OR clause.
For example, the original sentence is "name and time of job of employee", and two key phrase clauses are obtained after parsing: the system comprises an employee name, an employee time of entry AND an AND clause, wherein each keyword clause comprises two keywords. For another example, the original sentence is "house number or parking space number of owner", and two keyword phrase clauses are obtained after parsing: the system comprises an owner house number, an owner parking space number and an OR clause, wherein each keyword clause comprises two keywords.
In addition, the steps of collecting, storing, using, processing and the like of the information (such as the identity information) in the invention all accord with the relevant regulations of national laws and regulations.
And S206, connecting the key phrase clauses through the relation clauses to generate a query sentence.
In general, the concatenated query statements may be in a tree structure.
Therefore, the original sentence is analyzed to obtain the keyword group clause and the relation clause, the query sentence is generated, the query instruction input by the user can be converted into the structured object representation which is easy to process by a program, and the fuzzy query of the JSON database is realized.
And S207, matching at least two keywords included in the keyword group clause in the inverted index to obtain an original mode list.
And S208, filtering the original mode list according to the constraint conditions to obtain a target mode list.
The constraint includes a first constraint sub-condition and a second constraint sub-condition.
Specifically, the first constraint sub-condition is that each keyword matches a segment which is not overlapped with each other on the query path and the segment includes all keywords in the keyword group clause; the second constraint sub-condition is that the path segments matched between different keywords meet the sequence of the keywords in the keyword group sub-sentence.
In combination with steps S207-S208, since the query statement includes N keyword group clauses, where N is an integer greater than or equal to 2, for each keyword group clause, it is necessary to perform a query in the inverted index to obtain a target mode list corresponding to the keyword group clause. I.e. steps S207-S208 need to be performed N times.
Firstly, matching at least two keywords included in a keyword group clause in an inverted index to obtain an original mode list, wherein the original mode list at least comprises the at least two keywords included in the keyword group clause; and then, sequentially filtering the original mode list according to the first constraint condition and the second constraint condition, and eliminating the modes which do not accord with the first constraint condition and the second constraint condition, thereby obtaining a target mode list.
S209, constructing an original query plan according to the target mode list, the query operator and the query operand.
After target mode lists corresponding to all the keyword group clauses are obtained, replacing the keyword group clauses with a list of query paths corresponding to the data mode, wherein the target mode lists are connected through relationship clauses, and the connection relationship between the target mode lists is the same as that between the keyword group clauses; and secondly, constructing an original query plan according to a query operator and a query operand based on the query syntax of the JSON database.
S210, optimizing the original query plan to obtain a target query plan.
In order to improve the query efficiency, the original query plan can be optimized to obtain a target query plan.
Specifically, the original query plan is optimized according to principles 1 and 2, or according to principles 1 and 3:
principle 1: AND for at least two target mode lists connected by the AND clauses, taking the intersection of the data modes related to each target mode list, AND removing the data modes only existing in partial target mode lists.
Because each JSON document only belongs to a certain specific data mode, AND the AND clause requires that the document meets the requirements of conditions under all the clauses, only the documents under the mode related to each query meet the requirements of the query conditions.
Principle 2: AND grouping at least two target mode lists connected by the AND clauses according to the data modes related to the target mode lists, AND constructing an AND query statement for each data mode.
Principle 3: AND grouping at least two target mode lists connected by the AND clauses according to the incidence relation of the related data modes, AND disassembling the at least two target mode lists into a plurality of AND query statements without correlation.
Wherein, the "association" means that the same query path exists between two data patterns; if the same query path does not exist between the two data patterns, it is said that no association exists between the two data patterns.
Multiple AND query statements in principles 2 AND 3 may be executed in parallel AND the results are then aggregated.
The above principles 2 and 3 are to take the concurrent query characteristics of the database into consideration, and break down one query into multiple concurrent queries to increase the execution speed of a single query. Since principles 2 AND 3 involve the same type of AND query statement parsing strategy, they cannot be performed simultaneously, AND only one of them can be selected.
And S211, inquiring in the JSON database according to the target inquiry plan to obtain an inquiry result.
For performance, the JSON database should support the "path-value" indexing method, the JSON documents to be queried should be pre-stored in the database as they are, and the "path-value" index is established, so that the program can execute several times of queries in the form of < path, operator, operand >. The query result is obtained by performing intersection AND union operation on the result set according to AND AND OR relations among the queries, AND the query result can be displayed to a user in a JSON document form.
The embodiment of the invention provides a query method, which comprises the following steps: acquiring a query sentence, wherein the query sentence comprises at least one key phrase clause and a relation clause, and the key phrase clauses are connected through the relation clause; inquiring in an inverted index of a JavaScript object notation JSON database according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through a relation clause, and the connection relation between the target mode lists is the same as that between the keyword group clauses; determining a target query plan according to the target mode list; and querying in a JSON database according to the target query plan to obtain a query result. The method comprises the steps of constructing a query sentence comprising at least one keyword group clause and a relation clause, querying in an inverted index of a JSON database according to each keyword group clause to obtain at least one target mode list, further determining a target query plan, and querying in the JSON database according to the target query plan to obtain a query result. Compared with the existing query method, the target query plan constructed based on the keyword group clause query can realize the fuzzy query of the JSON database; the query interface is irrelevant to the specific database implementation during query, and the method can be adapted to various different JSON document-based non-relational databases; meanwhile, the data mode is determined through the JSON document form, and the data query statement does not need to be written in a targeted manner, so that the method is suitable for various data modes, automatic adaptation of the data modes is realized, and the expandability is high.
EXAMPLE III
Fig. 3 is a schematic structural diagram of an inquiry apparatus according to a third embodiment of the present invention. As shown in fig. 3, the apparatus includes: a statement parsing module 301, a pattern query module 302, a plan determination module 303 and an execution module 304.
The sentence analyzing module 301 is configured to obtain a query sentence, where the query sentence includes at least one keyword group clause and a relationship clause, and the keyword group clauses are connected through the relationship clause;
the pattern query module 302 is configured to query the inverted index of the JSON database by using a JavaScript object notation (JavaScript object notation) according to each keyword group clause to obtain at least one target pattern list, where the target pattern lists are connected by using a relationship clause, and a connection relationship between the target pattern lists is the same as a connection relationship between the keyword group clauses;
a plan determining module 303, configured to determine a target query plan according to the target mode list;
and the execution module 304 is used for querying in the JSON database according to the target query plan to obtain a query result.
Optionally, the JSON database comprises a plurality of JSON documents. Referring to fig. 3, fig. 4 is a schematic structural diagram of another query device according to a third embodiment of the present invention. As shown in fig. 4, the method further includes: an index generation module 305.
An index generating module 305, configured to determine a data mode and a document correspondence list of each JSON document before the statement analyzing module 301 obtains the query statement, where the document correspondence list includes a correspondence between each value included in the JSON document and a query path thereof; performing word segmentation processing on query paths in all document corresponding relation lists to obtain a keyword list, wherein the keyword list comprises a plurality of keywords; and generating an inverted index according to the keyword list, the data modes of all JSON documents and the document corresponding relation list, wherein the inverted index comprises the corresponding relation between the keywords and the query path, and the JSON documents and the data modes to which the query path belongs.
Optionally, the sentence parsing module 301 is specifically configured to receive an original sentence input by a user; analyzing the original sentence to obtain a keyword group clause AND a relation clause, wherein each keyword group clause comprises at least two keywords, a query operator AND a query operand, AND the relation clause comprises an AND clause AND/OR an OR clause; and connecting the key phrase clauses through the relation clauses to generate a query sentence.
Optionally, for any keyword group clause;
a pattern query module 302, configured to match at least two keywords included in the keyword group clause in the inverted index, to obtain an original pattern list; and filtering the original mode list according to the constraint condition to obtain a target mode list.
Optionally, the constraint condition includes a first constraint sub-condition and a second constraint sub-condition; wherein, the first and the second end of the pipe are connected with each other,
the first constraint sub-condition is that each keyword matches a segment which is not overlapped with each other on the query path and the segment comprises all keywords in the keyword group clause;
the second constraint sub-condition is that the matched path segments among different keywords satisfy the sequence of the keywords in the keyword group clause.
Optionally, the plan determining module 303 is specifically configured to construct an original query plan according to the target pattern list, the query operator, and the query operand; and optimizing the original query plan to obtain a target query plan.
Optionally, the original query plan is optimized according to principle 1 and principle 2, or according to principle 1 and principle 3:
principle 1: for at least two target mode lists connected with the AND clause, taking the intersection of the data modes related to each target mode list, AND removing the data modes only existing in part of the target mode lists;
principle 2: grouping at least two target mode lists connected with the AND clauses according to the related data modes, AND constructing an AND query statement in each data mode;
principle 3: AND grouping at least two target mode lists connected by the AND clauses according to the incidence relation of the related data modes, AND disassembling the at least two target mode lists into a plurality of AND query statements without correlation.
The query device provided by the embodiment of the invention can execute the query method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Example four
FIG. 5 illustrates a block diagram of an electronic device 10 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 5, the electronic device 10 includes at least one processor 11, and a memory communicatively connected to the at least one processor 11, such as a Read Only Memory (ROM) 12, a Random Access Memory (RAM) 13, and the like, wherein the memory stores a computer program executable by the at least one processor, and the processor 11 may perform various suitable actions and processes according to the computer program stored in the Read Only Memory (ROM) 12 or the computer program loaded from the storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data necessary for the operation of the electronic apparatus 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
A number of components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, or the like; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The processor 11 performs the various methods and processes described above, such as the query method.
In some embodiments, the query method may be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the query method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the query method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be performed. A computer program can execute entirely on a machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user may provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the Internet.
The computing system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service are overcome.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present invention may be executed in parallel, sequentially, or in different orders, and are not limited herein as long as the desired results of the technical solution of the present invention can be achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of querying, comprising:
acquiring a query sentence, wherein the query sentence comprises at least one keyword group clause and a relation clause, and the keyword group clauses are connected through the relation clause;
inquiring in an inverted index of a JSON database by a JavaScript object notation respectively according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through the relation clause, and the connection relation between the target mode lists is the same as that between the keyword group clauses;
determining a target query plan according to the target mode list;
and querying in the JSON database according to the target query plan to obtain a query result.
2. The method of claim 1 wherein the JSON database comprises a plurality of JSON documents; before obtaining the query statement, the method further comprises:
respectively determining a data mode and a document corresponding relation list of each JSON document, wherein the document corresponding relation list comprises corresponding relations of each value contained in the JSON document and a query path thereof;
performing word segmentation processing on query paths in all the document corresponding relation lists to obtain a keyword list, wherein the keyword list comprises a plurality of keywords;
and generating the inverted index according to the keyword list, the data modes of all the JSON documents and the document corresponding relation list, wherein the inverted index comprises the corresponding relation between the keywords and the query path as well as the JSON documents and the data modes to which the query path belongs.
3. The method of claim 2, wherein obtaining the query statement comprises:
receiving an original sentence input by a user;
analyzing the original sentence to obtain the keyword group clauses AND the relation clauses, wherein each keyword group clause comprises at least two keywords, a query operator AND a query operand, AND the relation clauses comprise AND clauses AND/OR OR clauses;
and connecting the key phrase clauses through the relation clauses to generate the query sentence.
4. The method of claim 3, wherein for any of said keyword phrase clauses; and querying in an inverted index of a JSON database according to the keyword group clause to obtain a target mode list, wherein the method comprises the following steps:
matching at least two keywords included in the keyword group clause in the inverted index to obtain an original mode list;
and filtering the original mode list according to constraint conditions to obtain the target mode list.
5. The method of claim 4, wherein the constraint includes a first constraint sub-condition and a second constraint sub-condition; wherein the content of the first and second substances,
the first constraint sub-condition is that each keyword matches a segment which is not overlapped on the query path and comprises all keywords in the keyword group clause;
the second constraint sub-condition is that the matched path segments among different keywords meet the sequence of the keywords in the keyword group sub-sentence.
6. The method of claim 4, wherein determining a target query plan based on the target pattern list comprises:
constructing an original query plan according to the target mode list, the query operator and the query operand;
and optimizing the original query plan to obtain the target query plan.
7. The method of claim 6, wherein the original query plan is optimized according to principles 1 and 2, or according to principles 1 and 3:
principle 1: for at least two target mode lists connected by an AND clause, taking the intersection of the data modes related to each target mode list, AND removing the data modes only existing in part of the target mode lists;
principle 2: grouping at least two target mode lists connected with the AND clauses according to the related data modes, AND constructing an AND query statement in each data mode;
principle 3: AND grouping at least two target mode lists connected by the AND clauses according to the incidence relation of the related data modes, AND disassembling the at least two target mode lists into a plurality of AND query sentences without correlation.
8. An inquiry apparatus, comprising: the system comprises a statement analysis module, a mode query module, a plan determination module and an execution module; wherein, the first and the second end of the pipe are connected with each other,
the sentence analyzing module is used for acquiring a query sentence, wherein the query sentence comprises at least one keyword group clause and a relationship clause, and the keyword group clauses are connected through the relationship clause;
the mode query module is used for querying in an inverted index of a JSON database by a JavaScript object notation (JSON) respectively according to each keyword group clause to obtain at least one target mode list, wherein the target mode lists are connected through the relation clause, and the connection relation between the target mode lists is the same as that between the keyword group clauses;
the plan determining module is used for determining a target query plan according to the target mode list;
and the execution module is used for querying in the JSON database according to the target query plan to obtain a query result.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the query method of any one of claims 1-7.
10. A computer-readable storage medium having stored thereon computer instructions for causing a processor, when executed, to implement the query method of any one of claims 1-7.
CN202211461872.9A 2022-11-17 2022-11-17 Query method, query device, electronic equipment and storage medium Pending CN115878661A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211461872.9A CN115878661A (en) 2022-11-17 2022-11-17 Query method, query device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211461872.9A CN115878661A (en) 2022-11-17 2022-11-17 Query method, query device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115878661A true CN115878661A (en) 2023-03-31

Family

ID=85760444

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211461872.9A Pending CN115878661A (en) 2022-11-17 2022-11-17 Query method, query device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115878661A (en)

Similar Documents

Publication Publication Date Title
CN114357276A (en) Data query method and device, electronic equipment and storage medium
CN111708805A (en) Data query method and device, electronic equipment and storage medium
CN113836314B (en) Knowledge graph construction method, device, equipment and storage medium
CN111435406A (en) Method and device for correcting database statement spelling errors
CN114579104A (en) Data analysis scene generation method, device, equipment and storage medium
CN109815240A (en) For managing method, apparatus, equipment and the storage medium of index
CN112989235A (en) Knowledge base-based internal link construction method, device, equipment and storage medium
CN110362593B (en) Data query method, device, equipment and storage medium
CN113312539B (en) Method, device, equipment and medium for providing search service
CN113609100B (en) Data storage method, data query device and electronic equipment
CN113722600B (en) Data query method, device, equipment and product applied to big data
CN113220710B (en) Data query method, device, electronic equipment and storage medium
CN116955856A (en) Information display method, device, electronic equipment and storage medium
CN111797115A (en) Employee information searching method and device
CN115328917A (en) Query method, device, equipment and storage medium
CN115878661A (en) Query method, query device, electronic equipment and storage medium
CN115203428B (en) Knowledge graph construction method and device, electronic equipment and storage medium
CN113971216B (en) Data processing method and device, electronic equipment and memory
CN116414856A (en) Data query method and device, electronic equipment and storage medium
CN116069830A (en) Information query method, device, electronic equipment and storage medium
CN116226039A (en) File name index generation method and device and file searching method and device
CN112817990A (en) Data processing method and device, electronic equipment and readable storage medium
CN117033402A (en) Data access method, device, equipment and storage medium
CN118132550A (en) Structured large field data query method and device and electronic equipment
CN115525659A (en) Data query method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination