Data query method, device, apparatus, and storage medium

By searching for the first and last characters of the query term in a pre-defined trie and combining prefix and suffix characters to output the query results, the problem of low indexing efficiency and insufficient accuracy is solved, thus improving the efficiency and accuracy of parcel information query in the logistics industry.

CN116610808BActive Publication Date: 2026-06-02SF TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SF TECH CO LTD
Filing Date
2022-02-09
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing indexing methods suffer from low indexing efficiency and limited accuracy of indexing results, especially in the logistics industry where the efficiency of querying parcel information and the accuracy of associated results have not yet reached an ideal level.

Method used

The system uses a pre-defined trie for querying. It finds the corresponding node in the trie by searching for the first and last characters of the query term, combines the prefix and suffix characters to output the query results, and optimizes the accuracy of the query results through statistical features and weights.

Benefits of technology

It improves query efficiency and matching accuracy, and enhances the information content of query terms and the richness of output results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116610808B_ABST
    Figure CN116610808B_ABST
Patent Text Reader

Abstract

The application discloses a data query method and device, equipment and a storage medium, wherein the method comprises the following steps: searching for a second target node corresponding to the tail character of a query word and a first target node corresponding to the character with the same first character of the query word in a preset dictionary tree; acquiring the first character corresponding to each node between the root node and the first target node in the preset dictionary tree and the second character corresponding to each node between the second target node and the corresponding leaf node; combining the first character to obtain the prefix character, combining the second character to obtain the suffix character, outputting the query result according to the prefix character and the suffix character; searching for the prefix character corresponding to the character with the same first character in the preset dictionary tree on the basis of searching for the suffix character of the query word in the preset dictionary tree, expanding the query word, increasing the information quantity of the query word; and outputting the query result through the prefix character and the suffix character, so that the accuracy of the matching result can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of retrieval technology, and more specifically to a data query method, apparatus, device, and storage medium. Background Technology

[0002] Many applications now feature search suggestions, intelligently suggesting information users might want based on their input and structure. In the logistics industry, when users enter shipping information, they want to quickly and accurately retrieve the desired shipment details. For a massive shipment dictionary, the indexing model must rapidly provide suggested results, and these results must be semantically relevant, meaning the suggested shipment details must include the user's input keywords. Currently, the query efficiency and accuracy of suggested suggestions still need improvement. Summary of the Invention

[0003] This invention provides a data query method, apparatus, device, and storage medium to solve the problems of low indexing efficiency and limited accuracy of indexing results in existing indexing methods.

[0004] On one hand, embodiments of the present invention provide a data query method, the method comprising:

[0005] Obtain the query term to be queried, and determine the first and last characters of the query term;

[0006] Search in the preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character;

[0007] Obtain the first character corresponding to each node between the root node and the first target node in the preset trie, and the second character corresponding to each node between the second target node and the corresponding leaf node;

[0008] The prefix character is obtained based on the first character combination, the suffix character is obtained based on the second character combination, and the query result is output based on the prefix character and the suffix character.

[0009] In some embodiments of the present invention, the step of outputting the query result based on the prefix character and the suffix character includes:

[0010] The prefix character is combined with the query term to obtain the target query term;

[0011] In the preset trie, starting from the root node, each character of the target query term is matched sequentially to obtain the third target node corresponding to the last character of the target query term;

[0012] Obtain the third character corresponding to each node between the third target node and the corresponding leaf node, and combine the third characters to obtain the target character;

[0013] The target character is combined with the target query term to obtain a first character combination, and the suffix character is combined with the query term to obtain a second character combination;

[0014] Output the query results based on the first character combination and the second character combination.

[0015] In some embodiments of the present invention, the step of outputting the query result based on the first character combination and the second character combination includes:

[0016] Obtain the popularity corresponding to the first character combination and the popularity corresponding to the second character combination;

[0017] Calculate the weight of the first character combination based on its popularity, and calculate the weight of the second character combination based on its popularity.

[0018] The query results are output based on the weights corresponding to the first character combination and the second character combination.

[0019] In some embodiments of the present invention, before the step of searching in a preset trie for the second target node corresponding to the last character and the first target node corresponding to the character identical to the first character, the method includes:

[0020] Obtain each sample character combination from the preset dictionary database and the initial popularity corresponding to each sample character combination;

[0021] Construct an initial trie, and determine the character branches and nodes in the initial trie according to the order of the characters in each of the sample character combinations;

[0022] For each sample character combination corresponding to each character branch, the initial popularity of the sample character combination is stored in the node corresponding to the last character of the sample character combination on that character branch to obtain a preset trie.

[0023] In some embodiments of the present invention, obtaining the initial popularity corresponding to each sample character combination in the preset dictionary database includes:

[0024] Count the occurrence frequency of each sample character combination in the pre-set dictionary database;

[0025] Based on the frequency of occurrence of the character combination, the statistical characteristics of the character combination are obtained, and the statistical characteristics are set as the initial popularity corresponding to the character combination; the statistical characteristics include one of the mean, variance, and expectation.

[0026] In some embodiments of the present invention, after storing the initial popularity of the sample character combination to the node corresponding to the last character of the sample character combination on the character branch to obtain a preset trie, the method includes:

[0027] According to a preset period, the occurrence count of each sample character combination in the preset dictionary database is counted.

[0028] New statistical features corresponding to each of the sample character combinations are obtained based on the frequency of occurrence of each of the sample character combinations.

[0029] If the new statistical feature is greater than or equal to the preset statistical feature threshold, then the initial popularity of the sample character combination in the preset trie is updated according to the new statistical feature;

[0030] If the new statistical feature is less than a preset statistical feature threshold, then the character branch corresponding to the sample character combination corresponding to the new statistical feature in the preset trie is removed.

[0031] In some embodiments of the present invention, after storing the initial popularity of the sample character combination to the node corresponding to the last character of the sample character combination on the character branch to obtain a preset trie, the method includes:

[0032] According to a preset period, count the newly added character combinations in the preset dictionary database;

[0033] Based on the order of the characters in the newly added character combination, starting from the root node in the preset trie, each character in the newly added character combination is matched sequentially to detect whether there is a matching sample character combination in the preset trie that matches the characters in the newly added character combination.

[0034] If the matching sample character combination exists, then the target sample character combination with the most matching characters is determined from the matching sample character combination. Based on the difference character between the target sample character combination and the newly added character combination, a target node corresponding to the difference character is added under the node corresponding to the last matching character of the target sample character combination and the newly added character combination, forming a new character branch.

[0035] If no matching sample character combination exists, then based on the order of the characters in the newly added character combination, determine the new character branch corresponding to the newly added character combination in the preset trie and each node in the newly added character branch.

[0036] In some embodiments of the present invention, the step of searching in a preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character includes:

[0037] The first character is matched with the characters of each node in the preset trie to obtain the characters in the preset trie that are the same as the first character. The node corresponding to the character that is the same as the first character is set as the first target node.

[0038] In the preset trie, starting from the root node, each character of the query term is matched sequentially to obtain the second target node corresponding to the last character of the query term.

[0039] On the other hand, this invention provides a data query device, the data query device comprising:

[0040] The query term acquisition module is used to acquire the query term to be queried and determine the first and last characters of the query term;

[0041] The node determination module is used to search in a preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character;

[0042] The character recording module is used to read the first character corresponding to each node from the root node to the first target node in the preset trie, and the second character corresponding to each node from the second target node to the corresponding leaf node.

[0043] The output module is used to obtain a prefix character based on the first character combination, obtain a suffix character based on the second character combination, and output the query result based on the prefix character and the suffix character.

[0044] On the other hand, embodiments of the present invention provide a data query device, including a memory and a processor; the memory stores an application program, and the processor is used to run the application program in the memory to perform the operations in the data query method.

[0045] On the other hand, embodiments of the present invention provide a storage medium storing a plurality of instructions adapted for loading by a processor to execute the steps in the data query method.

[0046] In this embodiment of the invention, after obtaining the query term, the first and last characters of the query term are determined. The second target node corresponding to the last character and the first target node corresponding to the character with the same first character are searched in a preset trie. The first characters corresponding to each node from the root node to the first target node and the second characters corresponding to each node from the second target node to the leaf node are obtained from the preset trie. Prefix characters are obtained by combining the first characters, and suffix characters are obtained by combining the second characters. The query result is then output based on the prefix and suffix characters. Thus, by searching for the first target node corresponding to the character with the same first character in the preset trie and combining the first characters corresponding to each node from the root node to the first target node to obtain the prefix character, the query term is expanded, increasing its information content. Furthermore, by combining the prefix and suffix characters to output the query result, the accuracy of the matching result and the query efficiency can be improved. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0048] Figure 1 This is a schematic diagram of an embodiment of the data query system provided in this invention;

[0049] Figure 2 This is a schematic flowchart of an embodiment of the data query method provided by the present invention;

[0050] Figure 3 This is a schematic diagram of an embodiment of the preset trie provided by the present invention;

[0051] Figure 4 This is a schematic diagram of an embodiment of the data query method for constructing a trie provided in this invention.

[0052] Figure 5 This is a schematic diagram of another embodiment of the preset trie provided by the present invention;

[0053] Figure 6 This is a schematic diagram of a process for querying the name of consigned goods in a logistics application provided by an embodiment of the present invention;

[0054] Figure 7 This is a schematic diagram of an embodiment of the data query device provided in this invention;

[0055] Figure 8This is a schematic diagram of an embodiment of the data query device provided in this invention. Detailed Implementation

[0056] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0057] As described in the background section, there are currently two commonly used indexing structures: inverted indexes and trie indexes. Inverted indexes use the query term as an index and the associated information containing the query term as records. The inverted index is then matched against the user's input to obtain all associated content containing those terms. The drawback of this method is that it requires indexing every single user input term, and word segmentation must be done using N-grams. Otherwise, the user might not get any suggested results when inputting a particular word. Therefore, for massive associated dictionary databases, building such a dictionary would be extremely cumbersome, directly impacting search response speed and query efficiency. Trie indexes, on the other hand, construct an ordered tree structure based on a dictionary database, storing the common prefixes of all strings in the database. Users can query all associated results containing the prefix of their input term. Because this index only stores the common prefixes of strings, it saves storage space, significantly reduces comparisons of irrelevant strings, greatly reduces query time, and improves query efficiency. However, trie-based indexing methods cannot accurately perform associations when the user's input term does not conform to the prefix structure, thus affecting the accuracy of the query results.

[0058] Based on the above research, embodiments of the present invention provide a data query method, apparatus, device, and storage medium. By using a preset trie to improve response speed and query efficiency, and by searching for suffix characters of the query term in the preset trie, and further searching for prefix characters corresponding to characters with the same first character, the query term is expanded, increasing its information content. By outputting the query results using both prefix and suffix characters, the accuracy of the matching results can be improved.

[0059] According to the embodiments of the data query method provided by the present invention, it should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the flowchart shows a logical order, in some cases the steps described or shown can be executed in a different order than that shown here.

[0060] like Figure 1As shown, Figure 1 This is a schematic diagram of an embodiment of the data query system provided by the present invention. The data query system shown includes a server 101, a database 102, and at least one terminal 103.

[0061] Server 101 can be a standalone server 101, or a server network or server cluster composed of servers 101, such as a computer, a network host, a single network server, a set of multiple network servers, or a cloud server composed of multiple servers. Among them, the cloud server is composed of a large number of computers or network servers based on cloud computing.

[0062] Server 101 may be a server 101 that provides backend support for query-type applications. Server 101 may consist of one or more functional units.

[0063] In some embodiments of the present invention, such as Figure 1 As shown, server 101 may include an interface unit, a query unit, and a processing unit.

[0064] The interface unit is used to interact with the query application installed in the terminal 103 to obtain the query terms to be queried sent by the terminal 103 and to return the query results to the terminal 103.

[0065] The query unit is used to perform queries and retrievals in database 102 based on the query terms to be queried, and obtain query results. The query process performed by the query unit can be at least one of fuzzy query, inverted index query, trie query, and reverse query, that is, to retrieve query results containing the query terms to be queried from database 102, including but not limited to query results with the query terms as prefixes, query results with the query terms as suffixes, and query results with the query terms as intermediate fields.

[0066] The processing unit is used to process the string data in the database 102 so that the query unit can perform string queries efficiently while keeping memory usage relatively low.

[0067] The aforementioned database 102 can be a Redis database (Remote Dictionary Server), an SQL (Structured Query Language) database, or other types of databases. Database 102 is used to store various types of data, such as combinations of sample characters, associated data corresponding to each character in each sample character combination, and processing results from the processing unit.

[0068] In some embodiments of the present invention, the processing results of the above-mentioned processing unit include, but are not limited to, constructing a trie based on each sample character combination, and writing the associated data corresponding to each sample character combination into the trie. The associated data includes, but is not limited to, the word classification and weight corresponding to the sample character combination.

[0069] Terminal 103 may be a terminal device with network connectivity and a query application corresponding to the aforementioned server 101 installed. For example, terminal 103 may include, but is not limited to, smartphones, industrial computers, e-readers, smart glasses, smartwatches, MP3 (Moving Picture Experts Group Audio Layer III) players, MP4 (Moving Picture Experts Group 4) players, tablet computers, and PCs.

[0070] In some embodiments of the present invention, the above-mentioned query applications may include applications that provide query functions for any query term, such as, but not limited to, traditional video playback applications, live video applications, communication applications, social applications, game applications, browser applications, logistics applications, and so on.

[0071] In some embodiments of the present invention, the terminal 103 and the server 101 are connected through a communication network. In some embodiments of the present invention, the communication network may be a wired network or a wireless network.

[0072] In some embodiments of the present invention, the aforementioned wired or wireless networks use standard communication technologies and / or protocols. The network can be the Internet or any other network, including but not limited to wide area networks, metropolitan area networks, local area networks, 3rd Generation Partnership Project (3GPP), Long Term Evolution (LTE), Worldwide Interoperability for Microwave Access (WiMAX) mobile communications, or computer network communications based on the TCP / IP protocol suite (TCP / IP) and User Datagram Protocol (UDP), etc.

[0073] like Figure 2 As shown, Figure 2 This is a schematic flowchart of an embodiment of the data query method provided by the present invention. The obtained data query method includes steps 201 to 204:

[0074] 201. Obtain the query term to be queried, and determine the first character and the last character of the query term.

[0075] The query term is the input character. In some embodiments of the present invention, the query term can be a single character, or a string composed of two characters or more than two characters.

[0076] In some embodiments of the present invention, when the query term is a single character, the first character and the last character of the query term are the same. For example, when the input query term is "fruit", both the first character and the last character of the query term are "fruit".

[0077] In some embodiments of the present invention, when the query term is a string, the first character and the last character of the query term are the character at the first byte position of the string and the character at the last byte position of the string respectively. For example, when the input query term is "AED", the first character of the query term is "A", and the last character of the query term is "D".

[0078] In some embodiments of the present invention, the method of obtaining the query term to be queried can be to obtain the query term to be queried input by voice, obtain the query term to be queried input by clicking, or obtain the query term to be queried input by image. Among them, obtaining the query term to be queried input by voice can be to obtain the input voice, perform semantic understanding on the received voice to obtain the parsing result corresponding to the voice, and set the parsing result as the query term to be queried; obtaining the query term to be queried input by image can be to obtain the input image, perform image recognition on the image, extract the text information in the image, recognize the name of the target in the image, and set the extracted text information and / or the recognized target name as the query term to be queried.

[0079] 202. Search for the second target node corresponding to the last character and the first target node corresponding to the character same as the first character in the preset trie tree.

[0080] The preset trie tree is an ordered tree structure constructed by saving the common prefixes of the strings corresponding to all sample character combinations in the preset dictionary database, as Figure 3 shown. Figure 3This illustration shows a preset trie provided by an embodiment of the present invention. The preset trie includes a root node, character branches, and nodes on each character branch. The root node in the preset trie does not contain any characters, and each node except the root node contains only one character. A character branch refers to a path formed by characters from the root node to a certain node. Connecting the characters along the path in sequence forms the sample character combination corresponding to that character branch. In some embodiments of the present invention, when two or more sample character combinations have the same prefix character (i.e., two or more sample character combinations have a common prefix), starting from the root node, each character in the common prefix is ​​written into each node in sequence according to the order of the characters in the common prefix. The remaining characters in each sample character combination, excluding the common prefix, are then written into subsequent nodes in sequence. The node corresponding to the last character in the common prefix is ​​connected to the node corresponding to the first character of the remaining characters in each sample character combination, excluding the common prefix. Figure 3 As shown, the sample character combinations “BAEF” and “BAED” have a common prefix “BAE”. Starting from the root node, the common prefix “BAE” is written in sequence. Then, a new blank node is created, and the remaining character “F” in “BAEF” (excluding the common prefix) is written and connected to the node corresponding to “E”. The remaining character “D” in “BAED” (excluding the common prefix) is written and connected to the node corresponding to “E”.

[0081] The preset dictionary database is used to store sample character combinations that appear in the actual application scenarios of the data query method. These scenarios include, but are not limited to, logistics and freight, e-commerce, video playback, and gaming. For example, the preset dictionary database could be a database of goods transported in logistics, a database of products sold in e-commerce, a database of video names in video playback, a database of character names in a game scenario, or a database of guild names in a game scenario. It should be noted that the above-mentioned preset dictionary database is only an example; the preset dictionary database can be built by collecting character data appearing in the actual application scenario of the data query method.

[0082] In some embodiments of the present invention, for a pre-constructed trie, the branches corresponding to the characters of the query term can be found by combining the characters of each node in the pre-constructed trie. These branches are the target character branches, where the character combinations of each node in the pre-constructed trie match the character combinations of the query term. For example, if the query term is "AE", then the target character branch is the branch where the characters of the corresponding nodes are "A" and "E". Figure 3As shown in the diagram, the two nodes marked with thick lines form a branch, and the node corresponding to the character "A" in the target character branch has a lower level in the preset trie than the node corresponding to the character "E". Here, level refers to the distance from a node to the root node in the preset trie.

[0083] In some embodiments of the present invention, the last node in the target character branch is set as the second target node, and a query is performed in the preset trie to see if there is a node with the same character as the first node of the target character branch. If there is a node with the same character as the first node of the target character branch, then the node is set as the first target node.

[0084] 203. Obtain the first character of each node from the root node to the first target node in the preset trie, and the second character of each node from the second target node to the corresponding leaf node.

[0085] In some embodiments of the present invention, a leaf node refers to the node corresponding to the last character in the sample character combination in the preset dictionary data. The path from the second target node to the corresponding leaf node refers to the leaf node on the character branch where the second target node is located. In some embodiments of the present invention, when the second target node is a node corresponding to a character in a common prefix, that is, when the character branch where the second target node is located includes multiple branches, then the leaf nodes of these multiple character branches are set as the path from the second target node to the corresponding leaf node. Figure 3 For example, when the second target node is node 32, the corresponding leaf node from the second target node is the node corresponding to the character "E" on the character branch where node 32 is located; when the second target character is the node corresponding to the character "B", the corresponding leaf node from the second target node is the node corresponding to the character "D" and the node corresponding to the character "F".

[0086] In some embodiments of the present invention, after determining the first target node, the parent nodes of the preset trie are iteratively queried sequentially from the first target node to the root node of the preset trie to obtain all nodes between the root node and the first target node in the preset trie, and the first character of each node between the root node and the first target node in the preset trie is read. In some embodiments of the present invention, each node in the preset trie is provided with its own corresponding parent node pointer, which is used to indicate the parent node of the corresponding node. In some embodiments of the present invention, the parent node of the first target node is determined according to the parent node pointer of the first target node, and the grandparent node of the parent node of the first target node is determined according to the parent node pointer of the parent node, and the ancestor node of the first target node is iteratively searched according to the parent node pointer to obtain all nodes between the root node and the first target node in the preset trie. An ancestor node refers to a node whose parent node pointer points to the root node in the preset trie.

[0087] like Figure 3 As shown, when the query term is "AE", the system searches for node 32 in the preset trie where the character "A" is present. This node 32 is then set as the first target node. The system then queries the ancestor nodes of the first target node. To facilitate the query of ancestor nodes, after determining the first target node... Figure 3 By iterating towards the root node (node ​​32), the first character of each node between the root node and the first target node in the preset trie can be obtained. That is, the first character is the character "D" corresponding to node 21 under the root node.

[0088] In some embodiments of the present invention, when constructing a preset trie, a node identifier can be set for each node in the preset trie. The node identifier is used to indicate whether the corresponding node is a leaf node, and the node identifier can be a number or a letter. For example, the node identifier can be 0 and 1. In some embodiments of the present invention, when the node identifier of a node is 0, it indicates that the node is not the node corresponding to the last character in any sample character combination in the preset dictionary database; when the node identifier of a node is 1, it indicates that the node is the node corresponding to the last character in any sample character combination in the preset dictionary database.

[0089] In some embodiments of the present invention, after determining the second target node, the character branch in which the second target node is located is determined, the node identifiers of each node in the character branch in which the second target node is located after the second target node are obtained, and each node is determined to be a leaf node based on the node identifiers of each node, thereby determining the leaf node in the character branch in which the second target node is located after the second target node, obtaining each node between the second target node and the leaf node, and reading the second character corresponding to each node between the second target node and the corresponding leaf node.

[0090] For example, such as Figure 3 As shown, when the query term to be queried is "AE", after determining the target character branch corresponding to "AE" in the preset trie, the second target node corresponding to the last character "E" in the target character branch is determined. Based on the character branch where the second target node is located, the leaf node after the second target node in the character branch where the second target node is located is determined by the node identifier, and the characters "D" and "F" corresponding to each second target node are read as the second characters corresponding to each node between the second target node and the corresponding leaf node.

[0091] In some embodiments of the present invention, when constructing a preset dictionary tree, information bits can be set for each data tail node in the preset dictionary tree. The data tail node is the node corresponding to the last character in any sample character combination in the preset dictionary database. The information bits are used to place the sample word corresponding to any sample character combination in the preset dictionary database, the category corresponding to the sample word, etc.

[0092] In some embodiments of the present invention, after determining the second target node, nodes with information bits in each node located after the second target node in the preset trie are obtained, and the nodes with information bits in each node are set as data tail nodes to obtain each node between the second target node and the data tail node, and the second character corresponding to each node between the second target node and the data tail node is read.

[0093] 204. The first character combination yields the prefix character, the second character combination yields the suffix character, and the query result is output based on the prefix and suffix characters.

[0094] In some embodiments of the present invention, step 204 may involve combining the prefix character, query term, and suffix character to obtain the query result and outputting the query result.

[0095] In some embodiments of this invention, query results can be obtained and output based on the combination of prefix character, query term, and suffix character. For example... Figure 3 As shown, when the input query term is "AE", the first character "A" and the last character "E" of the query term "AE" can be compared with the characters of each node after the root node, starting from the root node in the preset trie, to determine the target character branch corresponding to the query term "AE" in the preset trie. Figure 3 As shown in the diagram (branch 31d), by performing prefix matching on this target character branch, we can find all branches with the prefix "AE" and whose last node is a leaf node (i.e., the combination of the target character branch and the branch corresponding to the suffix character). Figure 3 The branches "AED" and "AEF" of the target character branch 31d are shown in bold, indicating that the suffix characters of the query term "AE" are "D" and "F" respectively; then, the first target node in the preset trie with the same first character "A" as the target character branch is queried. Figure 3 (See node 32 shown in the image) to obtain all nodes between the root node and the first target node in the preset trie. Figure 3In node 21), read the first character “D” corresponding to node 21, and obtain the prefix character “D” based on the combination of the first character; according to the combination method of prefix character-query term-suffix character, combine the prefix character “D” and the query term “AE”, and then combine them with the suffix characters “D” and “F” respectively to obtain the query results “DAED” and “DAEF”, and output the query results so that the user can make a selection based on the output query results.

[0096] In some embodiments of the present invention, in order to improve the richness of the output query results, query results can be obtained and output based on combinations of prefix character-query term, query term-suffix character, and prefix character-query term-suffix character. For example... Figure 3 As shown, when the input query term is "AE", the first character "A" and the last character "E" of the query term "AE" can be compared with the characters of each node after the root node, starting from the root node in the preset trie, to determine the target character branch corresponding to the query term "AE" in the preset trie. Figure 3 As shown in the diagram (branch 31d), by performing prefix matching on this target character branch, we can find all branches with the prefix "AE" and whose last node is a leaf node (i.e., the combination of the target character branch and the branch corresponding to the suffix character). Figure 3 The branches "AED" and "AEF" of the target character branch 31d are shown in bold, indicating that the suffix characters of the query term "AE" are "D" and "F" respectively; then, the first target node in the preset trie with the same first character "A" as the target character branch is queried. Figure 3 (See node 32 shown in the image) to obtain all nodes between the root node and the first target node in the preset trie. Figure 3 In node 21, the first character "D" corresponding to node 21 is read, and the prefix character "D" is obtained by combining the first character. According to the combination method of prefix character-query term-suffix character, the prefix character "D" and the query term "AE" are combined, and then combined with the suffix characters "D" and "F" respectively to obtain the query results "DAED" and "DAEF". According to the combination method of prefix character-query term, the prefix character "D" and the query term "AE" are combined to obtain the query result "DAE". According to the combination method of query term-suffix character, the query term "AE" is combined with the suffix characters "D" and "F" respectively to obtain the query results "AED" and "AEF". The query results "DAED", "DAEF", "DAE", "AED" and "AEF" are output so that the user can make a selection based on the output query results.

[0097] In this embodiment of the invention, based on finding the suffix characters of the query term in a preset trie, the first target node corresponding to the character with the same first character is found in the preset trie. The prefix characters are obtained by combining the first characters corresponding to each node from the root node to the first target node, thereby expanding the query term and increasing its information content. The query results are output through the prefix characters and suffix characters, which can improve the accuracy of the matching results.

[0098] like Figure 4 As shown, Figure 4 This is a schematic diagram of an embodiment of the data query method for constructing a trie provided in this invention.

[0099] In some embodiments of the present invention, to improve query response speed and query efficiency, a preset trie is constructed based on a preset dictionary database. Furthermore, to increase the accuracy of the output query results, the popularity of each sample character combination in the preset trie can be written into the character branch corresponding to each sample character combination in the preset trie during construction. Before outputting the query results, the weight of each character combination in the query results is determined, and a preset number of character combinations are output in descending order of weight. Popularity refers to the number of times a character combination appears. Specifically, the method for constructing the trie includes steps 401-403:

[0100] 401. Obtain each sample character combination in the preset dictionary database and the initial popularity corresponding to each sample character combination.

[0101] In some embodiments of the present invention, the character combination can be a single character, or it can be a string composed of two or more characters.

[0102] In some embodiments of the present invention, the initial popularity of each sample character combination can be determined by statistically analyzing the frequency of occurrence of each sample character combination in a preset dictionary database within a preset time period. Specifically, the frequency of occurrence of each sample character combination in the preset dictionary database is counted; based on the frequency of occurrence of the character combinations, statistical characteristics of the character combinations are obtained, and these statistical characteristics are set as the initial popularity of the character combinations. The statistical characteristics include one of the following: mean, variance, and expected value.

[0103] 402. Construct the initial trie and determine the character branches and nodes in the initial trie according to the order of characters in each sample character combination.

[0104] In some embodiments of the present invention, in order to reduce the memory usage of the initial trie, when writing the sample character combination to be written into the initial trie, the system queries the initial trie starting from the root node to see if there exists a character branch corresponding to a sample character combination that has a common prefix with the sample character combination to be written. If such a branch exists, a new node is constructed under the last node of the common prefix, and the remaining characters of the sample character combination to be written, excluding the common prefix, are written sequentially into the new node according to the order of each character, forming a character branch corresponding to the sample character combination to be written. If such a branch does not exist, a new node with the same number of characters as the sample character combination to be written is constructed under the root node of the initial trie, and each character is written sequentially into the new node according to the order of each character in the sample character combination to be written, forming a character branch corresponding to the sample character combination to be written.

[0105] 403. For each character branch corresponding to a sample character combination, the initial heat of the sample character combination is stored in the node corresponding to the last character of the sample character combination on that character branch, so as to obtain the preset trie.

[0106] In some embodiments of the present invention, the initial popularity of a sample character combination can be set to the information bit corresponding to the sample character combination, and the information bit can be written to the node corresponding to the tail character of the sample character combination on the character branch.

[0107] In some embodiments of the present invention, the initial popularity of the sample character combination can be stored in the leaf node of the character branch, and the leaf node can be connected to the node corresponding to the last character of the sample character combination on the character branch.

[0108] In some embodiments of the present invention, to facilitate the output of query results, character combinations are categorized according to their corresponding categories when outputting the query results. When constructing a preset trie, the category corresponding to a sample character combination and its initial popularity are stored in the node corresponding to the last character of that sample character combination on that character branch. For example, as... Figure 5 As shown, Figure 5This is a schematic diagram of a preset trie provided in an embodiment of the present invention. The preset trie includes four character branches: 33a, 32b, 21b, 31c, and 33d. The sample character combination corresponding to character branch 33a is "apple", the sample character combination corresponding to character branch 32b is "apple juice", the sample character combination corresponding to character branch 21b is "jelly", the sample character combination corresponding to character branch 31c is "rice", and the sample character combination corresponding to character branch 33d is "hairy crab". The popularity and category of the sample characters corresponding to each of character branches 33a, 32b, 21b, 31c, and 33d are written into the leaf nodes corresponding to character branches 33a, 32b, 21b, 31c, and 33d. For example, [apple, 5, fruit] is stored in leaf node 13 of 33a, and leaf node 13 is connected to node 12. Here, "5" refers to the initial popularity of the sample character combination "apple".

[0109] In this embodiment of the invention, when constructing a preset trie, the popularity of each sample character combination in the preset trie is written into the character branch corresponding to each sample character combination in the preset trie, so as to provide data support for the order and number of character combinations in the output of subsequent query results.

[0110] In some embodiments of the present invention, in order to improve the reliability of the output query results, after establishing a preset trie, the occurrence frequency of each sample character combination in the preset dictionary database is counted according to a preset period, and the initial popularity of each sample character combination in the preset trie is updated based on the occurrence frequency. Specifically, this includes steps a1 to a4:

[0111] Step a1: According to the preset period, count the occurrence times of each sample character combination in the preset dictionary database.

[0112] The preset period can be a week, a month, three months, six months, a year, etc. That is, every week, month, three months, six months or a year, the occurrence frequency of each sample character combination in the preset dictionary database is counted and steps a3 to a4 are executed.

[0113] Step a2: Obtain new statistical features corresponding to each sample character combination based on the frequency of occurrence of each sample character combination.

[0114] Step a3: If the new statistical feature is greater than or equal to the preset statistical feature threshold, then update the initial popularity of the sample character combination in the preset dictionary tree according to the new statistical feature.

[0115] Step a4: If the new statistical feature is less than the preset statistical feature threshold, then remove the character branch corresponding to the sample character combination in the preset dictionary tree.

[0116] In some embodiments of the present invention, if the new statistical feature is less than the preset statistical feature threshold, the leaf node, node identifier, or information bit of the character branch corresponding to the sample character combination can be deleted, so that there is no leaf node or data tail node in the character branch corresponding to the sample character combination in the preset trie, thereby removing the character branch corresponding to the sample character combination in the preset trie from the preset trie.

[0117] In some embodiments of the present invention, if the new statistical feature is less than the preset statistical feature threshold, it is also possible to determine whether there is a common prefix between the sample character combination and other sample character combinations in the preset trie by iteratively querying the parent node from the node of the last character of the character branch corresponding to the sample character combination to the root node; if there is no common prefix between the sample character combination and other sample character combinations in the preset trie, then all nodes of the character branch corresponding to the sample character combination are removed from the preset trie. As Figure 5 shown, when the sample character combination is "jelly", since there is no common prefix between the sample character combination "jelly" and the remaining sample character combinations in the preset trie, the character branch 21a corresponding to the sample character combination is removed from the preset trie; if there is a common prefix between the sample character combination and other sample character combinations in the preset trie, then the node corresponding to the tail character of the common prefix is determined, and the remaining nodes after this node in the character branch corresponding to the sample character combination are removed from the preset trie. As Figure 5 shown, when the sample character combination is "apple juice", since the sample character combination "apple juice" has a common prefix "apple" with the sample character combination "apple", the nodes 14 and 15 after the node 12 corresponding to the tail character "le" of the prefix character "apple" in the character branch 32b are removed from the preset trie.

[0118] In some embodiments of the present invention, after the preset trie is constructed, it is monitored whether there are new character combinations in the actual application scenario, and when a new character combination appears, the new character combination is added to the preset trie to update the preset trie. Specifically, it includes steps b1 to b5:

[0119] Step b1, count the new character combinations in the preset dictionary database at a preset period.

[0120] The new character combination can be a sample word that appears in scenarios such as logistics freight, e-commerce, video playback, or games, and there is no sample character combination in the preset dictionary database whose character combination is the same as that of the sample word.

[0121] Step b2: Starting from the root node in the preset trie, match each character of the newly added character combination in sequence according to the order of the characters in the newly added character combination, and detect whether there is a matching sample character combination in the preset trie that matches the characters in the newly added character combination.

[0122] In some embodiments of the present invention, step b2 includes: Starting from the root node in the preset trie, match each character of the newly added character combination in sequence according to the order of the characters in the newly added character combination, query the candidate sample character combinations in each sample character combination that have a common prefix with the newly added character combination, and select the matching sample character combination that has the largest string match with the newly added character combination from the candidate sample character combinations according to the character length of the common prefix corresponding to each candidate sample character combination.

[0123] As Figure 5 shown, when the newly added character combination is "big switchblade", starting from the root node in the preset trie, match each character of the newly added character combination in sequence with the characters in each sample character combination in the preset trie, and query the candidate sample character combinations "big rice" and "hairy crab" in each sample character combination that have a common prefix with the newly added character combination. Since the character length of the common prefix of the candidate sample character combination "hairy crab" and the newly added character combination "big switchblade" is larger, "hairy crab" is set as the target sample character combination that has the largest string match with the newly added character combination.

[0124] Step b3: If there is a matching sample character combination, determine the target sample character combination with the most matching characters from the matching sample character combinations, and add a target node corresponding to the different character under the node corresponding to the last matching character of the target sample character combination and the newly added character combination according to the different characters between the target sample character combination and the newly added character combination, to form a newly added character branch.

[0125] The different character refers to the character that the target sample character combination and the newly added character combination do not match. For example, when the newly added character combination is "big switchblade" and the target sample character combination is "hairy crab", the different character between the target sample character combination and the newly added character combination is "knife".

[0126] The target node refers to the node corresponding to the written different character. In some embodiments of the present invention, the parent node of the target node corresponding to the different character in the target character branch corresponding to the target sample character combination can be determined according to the different characters between the target sample character combination and the newly added character combination, where the parent node of the target node is the node corresponding to the last matching character of the target sample character combination and the newly added character combination. As Figure 5As shown, when the different character between the target sample character combination and the newly added character combination is "knife", the parent node of the target node is the node corresponding to the character "brake".

[0127] Step b4, if there is no matching sample character combination, then according to the order of each character in the newly added character combination, determine the newly added character branch corresponding to the newly added character combination in the preset trie tree and each node in the newly added character branch.

[0128] In some embodiments of the present invention, if there is no target sample character combination that maximally matches the string of the newly added character combination in the preset trie tree, then according to the order of each character in the newly added character combination, determine the newly added character branch corresponding to the newly added character combination in the preset trie tree and each node in the newly added character branch. In some embodiments of the present invention, the newly added character branch corresponding to the newly added character combination in the preset trie tree and each node in the newly added character branch can be determined according to the order of each character in the newly added character combination in accordance with step 402, and the initial heat corresponding to the newly added character combination can be determined according to step 401 based on the number of occurrences of the newly added character combination within a preset period, and the initial heat corresponding to the newly added character combination is stored in the newly added character branch. For example, as Figure 5 shown, when the newly added character combination is "rice wine", according to the order of each character in the newly added character combination, starting from the root node in the preset trie tree, it is determined that there is no target sample character combination that maximally matches the string of the newly added character combination in the preset trie tree, then the newly added character branch corresponding to the newly added character combination in the preset trie tree is constructed in accordance with step 402, and each node in the newly added character branch is constructed, and "rice" and "wine" are written into each node in sequence.

[0129] In some embodiments of the present invention, after the preset trie tree is completed, when a query word is received, obtain the query word to be queried, query the prefix character and suffix character corresponding to the preset trie tree through steps 201 to step 204, combine the query word, the prefix character and the suffix character, obtain the query result, and output it. Optionally, in some embodiments of the present invention, after the preset trie tree is completed, when a query word is received, obtain the query word to be queried, determine the first character and the last character of the query word through step 201, and match the first character with the characters of each node in the preset trie tree to obtain the character in the preset trie tree that is the same as the first character, and set the node corresponding to the character that is the same as the first character as the first target node; in the preset trie tree, starting from the root node, match each character of the query word in sequence to obtain the second target node corresponding to the last character of the query word.

[0130] Considering that there may be no character with the same first character in the preset trie, in order to increase the flexibility and applicability of the data query method, in some embodiments of the present invention, when there is no character with the same first character in the preset trie, the prefix character and the suffix character corresponding to the query term in the preset trie are obtained, the prefix character, the query term, and the suffix character are concatenated to obtain the query result, and the query result is output.

[0131] Specifically, the query term is obtained, starting from the root node of the preset trie, and the characters corresponding to each node in the preset trie are matched with each character in the character combination of the query term to determine the target character combination corresponding to the character combination of the query term in the preset trie. The starting node corresponding to the target character combination is taken as the target starting node. Starting from the target starting node, prefix matching is performed on the character combination of the query term in the preset trie to obtain the target character branch of the query term. The first node of the target character branch is set as the fourth target node corresponding to the first character, and the last node of the target character branch is set as the second target node corresponding to the last character. Starting from the fourth target node, the parent node corresponding to the third target node in the preset trie is obtained by searching for each node between the root node and the first target node in step 203. The characters of each node between the root node and the fourth target node in the preset trie are combined into prefix characters according to the order of the corresponding node in the preset trie from smallest to largest level. In the predefined trie, obtain the node identifiers of each node following the second target node. Based on the node identifiers, determine the leaf nodes among the nodes following the second target node. Combine the characters corresponding to each node from the second target node to the leaf nodes into suffix characters according to the ascending order of the corresponding node's level in the predefined trie. Concatenate the prefix character, query term, and suffix character to obtain the query result, and output the query result. Figure 3 As shown, when the input query term is "AE", the prefix character is "B" and the suffix character is "D", the output query result is unique, i.e., "BAED"; when the suffix characters are "D" and "F", there are two query results, namely "BAED" and "BAEF".

[0132] The prefix and suffix characters mentioned above can be empty, meaning that the query term does not have a corresponding prefix and / or suffix character.

[0133] Optionally, in some embodiments of the present invention, when querying according to the query term, in order to output relatively accurate query results as much as possible, the query term to be input needs to have more characters, so as to perform accurate retrieval according to the output query term. However, entering a query term with more characters will take more input time, which will affect the output efficiency of the query results. And considering that directly combining the prefix character, query term, and suffix character to obtain the query result may reduce the richness of the query result. Therefore, in some embodiments of the present invention, the prefix character and the query term can also be combined to obtain a new query term, which no longer limits the number of characters of the input query term and improves the query efficiency. Starting from the root node of the preset trie, sequentially match the characters of the new query term with the characters of each node in the preset trie to obtain a new target character combination branch corresponding to the new query term. Perform prefix matching on the new target character branch to find all branches with the new query term as the prefix and the last node being a leaf node. Read the characters of each node on this branch to obtain a new suffix character, and combine the new suffix character with the new query term to obtain a new character combination. Combine the query term and the suffix character to obtain a character combination. Set the new character combination and the character combination as the query result and output the query result.

[0134] In some embodiments of the present invention, when there is a character in the preset trie that is the same as the first character, according to step 203, obtain the first characters corresponding to each node between the root node and the first target node in the preset trie, and the second characters corresponding to each node between the second target node and the leaf node. Combine the characters of each node between the root node and the first target node in the preset trie in ascending order of their levels in the preset trie to form a prefix character. Combine the characters of each node corresponding between the second target node and the leaf node in ascending order of their levels in the preset trie to form a suffix character. Combine the prefix character with the query term to obtain a target query term. Search for the target character corresponding to the target query term in the preset trie. Combine the target character with the target query term to obtain a first character combination. Combine the suffix character with the target query term to obtain a second character combination. Set the first character combination and the second character combination as the query result and output the query result. Specifically, it includes steps c1 to c5:

[0135] Step c1, combine the prefix character with the query term to obtain a target query term.

[0136] Exemplarily, as Figure 5 shown, when the input query term to be queried is "fruit", obtain the node 12 in the preset trie that has the same character as the query term "fruit", set this node 12 as the first target node, start querying from this first target node towards the root node in the preset trie, and obtain the prefix character "apple" of this first target node. Combine the characters "apple" and "fruit" to obtain the target query term "apple".

[0137] Step c2: Starting from the root node in the preset trie, match each character of the target query term in sequence to obtain the third target node corresponding to the last character of the target query term.

[0138] Step c3: Obtain the third characters corresponding to the nodes between the third target node and the leaf nodes, and combine the third characters to obtain the target character.

[0139] In the preset trie, obtain the node identifiers corresponding to the nodes after the third target node, and determine the leaf nodes among the nodes after the third target node according to the node identifiers; combine the third characters corresponding to the nodes between the third target node and the leaf nodes in ascending order of the levels of the corresponding nodes in the preset trie to form the target character.

[0140] Take Figure 5 as an example. When the input query term to be queried is "fruit", the target query term "apple" is obtained. The target character "juice" corresponding to the target query term "apple" is queried from the preset trie.

[0141] Step c4: Combine the target character with the target query term to obtain the first character combination, and combine the suffix character with the query term to obtain the second character combination.

[0142] Take Figure 5 as an example. When the input query term to be queried is "fruit", the target query term "apple" is obtained. The target character "juice" corresponding to the target query term "apple" is queried from the preset trie. Combine the target query term "apple" and the target character "juice" to obtain "apple juice". Since "apple" is a sample character combination in the preset trie, the first character combination is obtained: "apple, " "apple juice". The suffix character of the query term "fruit" is "jelly". Combine the query term "fruit" with the suffix character "jelly" to obtain the second character combination "jelly fruit".

[0143] Step c5: Output the query result according to the first character combination and the second character combination.

[0144] In some embodiments of the present invention, the terminal 103 receives the input query term to be queried through the query interface, sends the query term to the server 101 for querying. The server 101 queries according to the received query term to be queried to obtain the query result, and feeds back the query result to the terminal 103. The terminal 103 displays the query result on the query interface.

[0145] In some embodiments of the present invention, in order to improve the adaptation degree of the query result to the query term and enhance the accuracy of the query result, when determining the first character combination and the second character combination, the popularity corresponding to each of the first character combination and the second character combination is obtained, and based on the popularity corresponding to each of the first character combination and the second character combination, the weight corresponding to each of the first character combination and the second character combination is determined, and the query result is retrieved according to the weight. Specifically, it includes steps d1 to d3:

[0146] Step d1, obtain the popularity corresponding to the first character combination and the popularity corresponding to the second character combination.

[0147] Step d2, calculate the weight corresponding to the first character combination according to the popularity corresponding to the first character combination, and calculate the weight corresponding to the second character combination according to the popularity corresponding to the second character combination.

[0148] Step d3, output the query result according to the weight corresponding to the first character combination and the weight corresponding to the second character combination.

[0149] In some embodiments of the present invention, when obtaining the third characters corresponding to each node between the third target node and the leaf nodes and obtaining the target characters according to the third character combination, the popularity in each leaf node is read, and the popularity of each leaf node is associated with the target character corresponding to that leaf node; the target character is combined with the target query term to obtain the first character combination, and the popularity corresponding to the target character is set as the popularity corresponding to the first character combination. The method for obtaining the popularity corresponding to the second character combination is similar to the method for obtaining the popularity corresponding to the first character combination, which will not be elaborated here.

[0150] As Figure 5 shown, when the input query term to be queried is "fruit", the popularities corresponding to the first character combinations "apple" and "apple juice" are 5 and 4 respectively, and the popularity of the second character combination "jelly" is 6.

[0151] In some embodiments of the present invention, the sum of the popularities corresponding to the first character combination and the second character combination can be calculated, and the ratio between the popularity corresponding to the first character combination and the sum of the popularities is set as the weight corresponding to the first character combination, and the ratio between the popularity corresponding to the second character combination and the sum of the popularities is set as the weight corresponding to the second character combination.

[0152] In some embodiments of the present invention, a preset weight coefficient can be obtained, and by calculating the product of the popularity corresponding to each of the first character combination and the second character combination and the preset weight coefficient, the weight corresponding to each of the first character combination and the second character combination is obtained. In some embodiments of the present invention, the preset weight coefficient can be set according to the actual application scenario.

[0153] In some embodiments of the present invention, in order to further improve the adaptability of the query result to the query term, different weight coefficients can be set for the first character combination and the second character combination. Specifically, obtain the first weight coefficient corresponding to the first character combination and the second weight coefficient corresponding to the second character combination, set the product of the first character combination and the first weight coefficient as the weight corresponding to the first character combination, and set the product between the second character combination and the second weight coefficient as the weight corresponding to the second character combination.

[0154] In some embodiments of the present invention, in order to ensure the accuracy of obtaining the weight coefficients, the weight coefficients corresponding to the first character combination and the second character combination can be determined by locating the positions of the query terms in the first character combination and the second character combination. For example, when the first character of the query term is in the first byte position of the character combination, then this character combination is the second character combination, and the second weight coefficient is used as the weight coefficient corresponding to this character combination; when the first character of the query term is not in the first byte position of the character combination, then this character combination is the first character combination, and the first weight coefficient is set as the weight coefficient corresponding to this character combination.

[0155] In some embodiments of the present invention, since the acquisition time of the first character combination is greater than the acquisition time of the second character combination, the weight coefficient corresponding to this character combination can also be determined according to the acquisition time of the character combination.

[0156] In some embodiments of the present invention, the suffix characters of the query term can be obtained first to get the second character combination, and the second weight coefficient is set as the weight of this second character combination; then the target query term of this query term is obtained, and the target characters corresponding to the target query term are obtained to get the first character combination, and the first weight coefficient is set as the weight coefficient corresponding to this first character combination.

[0157] In some embodiments of the present invention, the first weight coefficient is set to 0.4 and the second weight coefficient is set to 0.6. As Figure 5 shown, when the input query term to be queried is "fruit", the respective heat degrees of the first character combinations "apple" and "apple juice" are 5 and 4, the heat degree of the second character combination "jelly" is 6, the weight of "jelly" is 6 * 0.6 = 3.6, the weight of "apple" is 5 * 0.4 = 2.0, and the weight of "apple juice" is 4 * 0.4 = 1.6.

[0158] In some embodiments of the present invention, a preset number of query results can be output in descending order of weights.

[0159] For Figure 5For example, when the query term to be queried is "fruit", the weights corresponding to the first character combinations "apple" and "apple juice" are 2.0 and 1.6 respectively, and the weight of the second character combination "jelly" is 3.6. When the preset quantity is 2, the query results output are [jelly, apple], and when the preset quantity is 3, the query results output are [jelly, apple, apple juice].

[0160] In some embodiments of the present invention, when there is no character in the preset trie that is the same as the first character, the prefix character, the query term, and the suffix character are concatenated to obtain the second character combination, and the popularity corresponding to each second character combination is set as the weight corresponding to each second character combination, and the preset quantity of query results is output in the order from high to low according to the weights.

[0161] In the embodiments of the present invention, before outputting the query results, the weights corresponding to the first character combination and the second character combination are determined according to the popularity of the first character combination and the second character combination, and the preset quantity of query results is output in the order from high to low according to the weights, so as to improve the accuracy of the query results output through the weights, and different weight coefficients are set for the first character combination and the second character combination to improve the adaptability of the query results to the query term; and when there is no character in the preset trie that is the same as the first character, prefix matching and suffix matching are performed on the query term to obtain the second character combination, so as to improve the flexibility and applicability of the data query method.

[0162] To better illustrate the data query method provided by the embodiments of the present invention, take the application of the data query method in the logistics application as an example. Figure 6 It is a schematic flowchart of querying the name of the consignment in a logistics application shown according to an exemplary embodiment. As Figure 6 shown, the process includes:

[0163] S61, the terminal running the logistics application sends a query term to the server of the logistics application.

[0164] In the embodiments of the present invention, taking the input of the name of the consignment as an example, the server of the logistics application pre-determines the sample character combinations and initial popularity corresponding to the names of the consignments that have appeared, constructs a preset trie according to each sample character combination, and stores the initial popularity of each sample character combination into the preset trie. Each node in the preset trie has a pointer pointing to its parent node.

[0165] For the last character in each sample character combination, the server of the logistics application also sets the node identifier of the corresponding node in the preset trie to 1 to indicate that the node is the leaf node corresponding to the name of one or more consignments. Correspondingly, for other nodes in the preset trie, the node identifier is set to 0.

[0166] Users enter a query term consisting of one or more characters in the search bar of the mailing page of the logistics application on the terminal. The query term can contain any characters, such as Chinese and English. The terminal then sends the query term to the logistics application's server.

[0167] S62, after receiving the query term, the server of the logistics application determines the first and last characters of the query term.

[0168] S63, the logistics application server queries the target character branch corresponding to the query term in the preset trie, determines the second target node corresponding to the tail character, and obtains the suffix characters corresponding to each node between the second target node and the corresponding leaf node.

[0169] S64, the logistics application server queries the first target node corresponding to characters with the same first character in the preset trie, and obtains the prefix characters corresponding to each node from the root node to the first target node in the preset trie.

[0170] S65, the logistics application server combines the prefix character with the query term to obtain the target query term, and then searches for the target character corresponding to the target query term in the preset trie.

[0171] S66, the logistics application server concatenates the query term and suffix characters in order to obtain the name of the second consignment item; the logistics application server concatenates the target query term and target characters in order to obtain the name of the first consignment item.

[0172] In some embodiments of the present invention, the server of the logistics application determines the weight of the second consignment and the weight of the first consignment.

[0173] S67, the logistics application server returns the first and second entrusted items to the terminal for display.

[0174] In some embodiments of the present invention, the server of the logistics application returns a preset number of second and first entrusted items to the terminal in order of weight from low to high.

[0175] In some embodiments of the present invention, the server of the logistics application returns the first and second entrusted items, as well as the weights corresponding to the first and second entrusted items, to the terminal. The terminal displays a preset number of the second and first entrusted items in ascending order of weight according to the weights corresponding to the first and second entrusted items.

[0176] This invention expands the query terms based on a pre-defined trie index and assigns weights to the two query results. The pre-defined trie saves storage space for the item lookup dictionary and improves query speed. It also supports returning query patterns that include the query term as a suffix, adds prefix matching, and enriches the associated results. Furthermore, the final query results can be sorted and output according to the weight of the item, improving the accuracy of the associated results. For parcel sending scenarios, this can shorten the time for filling in sending information and improve the user's sending experience.

[0177] To better illustrate the data query method provided in the embodiments of the present invention, based on the data query method, the embodiments of the present invention also provide a data query device, such as... Figure 7 As shown, Figure 7 This is a schematic diagram of an embodiment of the data query device provided in this invention. The data query device shown includes:

[0178] The query term acquisition module 701 is used to acquire the query term to be queried and determine the first and last characters of the query term;

[0179] The node determination module 702 is used to find the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character in the preset trie;

[0180] The character recording module 703 is used to read the first character corresponding to each node from the root node to the first target node in the preset trie, and the second character corresponding to each node from the second target node to the corresponding leaf node.

[0181] Output module 704 is used to obtain the prefix character based on the first character combination, obtain the suffix character based on the second character combination, and output the query result based on the prefix character and the suffix character.

[0182] In some embodiments of the present invention, the output module 704 includes:

[0183] The prefix character is combined with the query term to obtain the target query term;

[0184] In the predefined trie, starting from the root node, each character of the target query term is matched sequentially to obtain the third target node corresponding to the last character of the target query term;

[0185] Obtain the third character of each node between the third target node and the corresponding leaf node, and combine the third characters to obtain the target character.

[0186] The target character is combined with the target query term to obtain the first character combination, and the suffix character is combined with the query term to obtain the second character combination;

[0187] Output the query results based on the first character combination and the second character combination.

[0188] In some embodiments of the present invention, the output module 704 further includes:

[0189] Get the popularity corresponding to the first character combination and the popularity corresponding to the second character combination;

[0190] Calculate the weight corresponding to the first character combination based on its popularity, and calculate the weight corresponding to the second character combination based on its popularity.

[0191] Output the query results based on the weights corresponding to the first character combination and the second character combination.

[0192] In some embodiments of the present invention, the data query device further includes:

[0193] The construction module 705 is used to obtain each sample character combination in the preset dictionary database and the initial popularity of each sample character combination; construct an initial trie, and determine the character branches and nodes in the initial trie according to the order of each character in each sample character combination; for each sample character combination corresponding to a character branch, store the initial popularity of the sample character combination in the node corresponding to the last character of the sample character combination on the character branch to obtain the preset trie.

[0194] In some embodiments of the present invention, the construction module 705 includes:

[0195] Count the occurrence frequency of each sample character combination in the pre-set dictionary database;

[0196] Based on the frequency of occurrence of character combinations, statistical characteristics of the character combinations are obtained, and these statistical characteristics are set as the initial popularity of the character combinations. The statistical characteristics include one of the following: mean, variance, and expectation.

[0197] In some embodiments of the present invention, the construction module 705 further includes:

[0198] According to a preset period, count the number of occurrences of each sample character combination in the preset dictionary database.

[0199] New statistical features corresponding to each sample character combination are obtained based on the frequency of occurrence of each sample character combination.

[0200] If the new statistical feature is greater than or equal to the preset statistical feature threshold, then the initial popularity of the sample character combination in the preset dictionary tree is updated according to the new statistical feature.

[0201] If the new statistical feature is less than the preset statistical feature threshold, then the character branch corresponding to the sample character combination corresponding to the new statistical feature in the preset dictionary tree will be removed.

[0202] In some embodiments of the present invention, the construction module 705 further includes:

[0203] According to a preset period, count the newly added character combinations in the preset dictionary database;

[0204] Based on the order of the characters in the newly added character combination, starting from the root node in the preset trie, each character in the newly added character combination is matched sequentially to detect whether there is a matching sample character combination in the preset trie that matches the characters in the newly added character combination.

[0205] If a matching sample character combination exists, the target sample character combination with the most matching characters is determined from the matching sample character combinations. Based on the difference between the target sample character combination and the new character combination, a target node corresponding to the difference character is added under the node corresponding to the last matching character of the target sample character combination and the new character combination, forming a new character branch.

[0206] If no matching sample character combination exists, the new character branch corresponding to the new character combination in the preset trie and each node in the new character branch are determined according to the order of the characters in the new character combination.

[0207] In some embodiments of the present invention, the node determination module 702 further includes:

[0208] Match the first character with the characters in each node of the preset trie to obtain the character that is the same as the first character in the preset trie, and set the node corresponding to the character that is the same as the first character as the first target node;

[0209] In the predefined trie, starting from the root node, each character of the query term is matched sequentially to obtain the second target node corresponding to the last character of the query term.

[0210] In this embodiment of the invention, based on finding the suffix characters of the query term in a preset trie, the prefix characters corresponding to characters with the same first character are found in the preset trie to expand the query term and increase its information content; and by outputting the query results through the prefix characters and suffix characters, the accuracy of the matching results can be improved.

[0211] This invention also provides a data query device, such as... Figure 8 As shown, it illustrates the structural diagram of the data query device involved in the embodiment of the present invention, specifically:

[0212] The data query device may include components such as a processor 801 with one or more processing cores, a memory 802 with one or more computer-readable storage media, a power supply 803, and an input unit 804. Those skilled in the art will understand that... Figure 8 The data query device structure shown does not constitute a limitation on the data query device. It may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0213] The processor 801 is the control center of the data query device. It connects various parts of the data query device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 802, and by calling data stored in the memory 802, it performs various functions and processes data, thereby providing overall monitoring of the data query device. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 801.

[0214] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created based on the use of the data query device, etc. In addition, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.

[0215] The data query device also includes a power supply 803 that supplies power to the various components. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 803 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0216] The data query device may also include an input unit 804, which can be used to receive input numerical or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0217] Although not shown, the data query device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 801 in the data query device loads the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 runs the application programs stored in the memory 802 to realize various functions, as follows:

[0218] Obtain the query term to be queried, and determine the first and last characters of the query term;

[0219] In the predefined trie, find the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character;

[0220] Get the first character of each node from the root node to the first target node in the preset trie, and the second character of each node from the second target node to the corresponding leaf node.

[0221] The first character combination yields the prefix character, the second character combination yields the suffix character, and the query result is output based on the prefix and suffix characters.

[0222] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0223] To this end, embodiments of the present invention provide a storage medium storing a plurality of instructions that can be loaded by a processor to execute steps in any of the data query methods provided in the embodiments of the present invention. For example, the instructions can execute the following steps:

[0224] Obtain the query term to be queried, and determine the first and last characters of the query term;

[0225] In the predefined trie, find the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character;

[0226] Get the first character of each node from the root node to the first target node in the preset trie, and the second character of each node from the second target node to the corresponding leaf node.

[0227] The first character combination yields the prefix character, the second character combination yields the suffix character, and the query result is output based on the prefix and suffix characters.

[0228] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0229] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0230] Since the instructions stored in the storage medium can execute the steps of any data query method provided in the embodiments of the present invention, the beneficial effects that any data query method provided in the embodiments of the present invention can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.

[0231] The above provides a detailed description of a data query method, apparatus, device, and storage medium provided by embodiments of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A data query method, characterized in that, The method includes: Obtain the query term to be queried, and determine the first and last characters of the query term; Search in the preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character; Obtain the first character corresponding to each node between the root node and the first target node in the preset trie, and the second character corresponding to each node between the second target node and the corresponding leaf node; The prefix character is obtained based on the first character combination, the suffix character is obtained based on the second character combination, and the query result is output based on the prefix character and the suffix character. The step of searching in the preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character includes: Set the last node in the target character branch as the second target node, and query the preset trie to see if there is a node with the same character as the first node of the target character branch. If there is a node with the same character as the first node of the target character branch, set that node as the first target node. Here, the target character branch refers to the branch in the preset trie where the character combination of each node is consistent with the character combination of the query term.

2. The data query method as described in claim 1, characterized in that, The output of the query results based on the prefix character and the suffix character includes: The prefix character is combined with the query term to obtain the target query term; In the preset trie, starting from the root node, each character of the target query term is matched sequentially to obtain the third target node corresponding to the last character of the target query term; Obtain the third character corresponding to each node between the third target node and the corresponding leaf node, and according to... The third character combination yields the target character; The target character is combined with the target query term to obtain a first character combination, and the suffix character is combined with the query term to obtain a second character combination; Output the query results based on the first character combination and the second character combination.

3. The data query method as described in claim 2, characterized in that, The step of outputting the query result based on the first character combination and the second character combination includes: Obtain the popularity corresponding to the first character combination and the popularity corresponding to the second character combination; Calculate the weight of the first character combination based on its popularity, and calculate the weight of the second character combination based on its popularity. The query results are output based on the weights corresponding to the first character combination and the second character combination.

4. The data query method according to any one of claims 1 to 3, characterized in that, Before the step of searching in the preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character, the method includes: Obtain each sample character combination from the preset dictionary database and the initial popularity corresponding to each sample character combination; Construct an initial trie, and determine the character branches and nodes in the initial trie according to the order of the characters in each of the sample character combinations; the nodes in each of the character branches constitute a sample character combination. For each sample character combination corresponding to each character branch, the initial popularity of the sample character combination is stored in the node corresponding to the last character of the sample character combination on that character branch to obtain a preset trie.

5. The data query method as described in claim 4, characterized in that, The process of obtaining the initial popularity corresponding to each sample character combination in the preset dictionary database includes: Count the occurrence frequency of each sample character combination in the pre-set dictionary database; Based on the frequency of occurrence of the character combination, the statistical characteristics of the character combination are obtained, and the statistical characteristics are set as the initial popularity corresponding to the character combination; the statistical characteristics include at least one of mean, variance, and expectation.

6. The data query method as described in claim 4, characterized in that, After storing the initial popularity of the sample character combination in the node corresponding to the last character of the sample character combination on the character branch to obtain the preset trie, the method includes: According to a preset period, the occurrence count of each sample character combination in the preset dictionary database is counted. New statistical features corresponding to each of the sample character combinations are obtained based on the frequency of occurrence of each of the sample character combinations. If the new statistical feature is greater than or equal to the preset statistical feature threshold, then the initial popularity of the sample character combination in the preset trie is updated according to the new statistical feature; If the new statistical feature is less than a preset statistical feature threshold, then the character branch corresponding to the sample character combination corresponding to the new statistical feature in the preset trie is removed.

7. The data query method as described in claim 4, characterized in that, After storing the initial popularity of the sample character combination in the node corresponding to the last character of the sample character combination on the character branch to obtain the preset trie, the method includes: According to a preset period, count the newly added character combinations in the preset dictionary database; Based on the order of the characters in the newly added character combination, starting from the root node in the preset trie, each character in the newly added character combination is matched sequentially to detect whether there is a matching sample character combination in the preset trie that matches the characters in the newly added character combination. If the matching sample character combination exists, then the target sample character combination with the most matching characters is determined from the matching sample character combination. Based on the difference character between the target sample character combination and the newly added character combination, a target node corresponding to the difference character is added under the node corresponding to the last matching character of the target sample character combination and the newly added character combination, forming a new character branch. If no matching sample character combination exists, then based on the order of the characters in the newly added character combination, determine the new character branch corresponding to the newly added character combination in the preset trie and each node in the newly added character branch.

8. The data query method as described in claim 1, characterized in that, The step of searching in the preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character includes: The first character is matched with the characters of each node in the preset trie to obtain the characters in the preset trie that are the same as the first character. The node corresponding to the character that is the same as the first character is set as the first target node. In the preset trie, starting from the root node, each character of the query term is matched sequentially to obtain the second target node corresponding to the last character of the query term.

9. A data query device, characterized in that, The data query device includes: The query term acquisition module is used to acquire the query term to be queried and determine the first and last characters of the query term; The node determination module is used to search in a preset trie for the second target node corresponding to the last character and the first target node corresponding to the character that is the same as the first character; The character recording module is used to read the first character corresponding to each node from the root node to the first target node in the preset trie, and the second character corresponding to each node from the second target node to the corresponding leaf node. The output module is used to obtain a prefix character based on the first character combination, obtain a suffix character based on the second character combination, and output the query result based on the prefix character and the suffix character; The node determination module is further configured to set the last node in the target character branch as the second target node, and query in the preset dictionary tree whether there is a node with the same character as the first node of the target character branch. If there is a node with the same character as the first node of the target character branch, then set that node as the first target node. Here, the target character branch refers to the branch in the preset dictionary tree where the character combination of each node is consistent with the character combination of the query term.

10. A data query device, characterized in that, It includes a memory and a processor; the memory stores an application program, and the processor runs the application program within the memory to perform the operations in the data query method according to any one of claims 1 to 8.

11. A storage medium, characterized in that, The storage medium stores a plurality of instructions adapted for loading by a processor to execute the steps of the data query method according to any one of claims 1 to 8.