Keyword searching method and device, computer equipment, medium and program product
By merging sparse nodes in the prefix tree and constructing a heap structure, the storage space and efficiency issues of the prefix tree are solved, and efficient word association matching in a large-scale term library is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING SOGOU TECHNOLOGY DEVELOPMENT CO LTD
- Filing Date
- 2024-10-30
- Publication Date
- 2026-05-01
AI Technical Summary
In existing technologies, prefix trees consume a lot of storage space and are inefficient when constructing and matching associated words, making it difficult to support the matching of associated words for ultra-large-scale entries.
By merging sparse nodes in the prefix tree and building a heap structure for non-leaf nodes, the target number of terms can be filtered out, reducing the number of nodes and improving indexing efficiency.
It improves indexing efficiency and reduces storage space usage in a massive thesaurus, while ensuring the speed and accuracy of word matching.
Smart Images

Figure CN121958322A_ABST
Abstract
Description
Keyword search methods, devices, computer equipment, media and program products Technical Field
[0001] This application relates to the field of computer technology, and in particular to a keyword search method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Technology
[0002] Search, as the entry point for users to access information, is one of the most frequently used functions. Currently, search systems offer a suggested search term feature, also known as a search suggestion feature. When users search for information, the search system recommends a series of related or semantically similar terms based on the keywords entered. Users can quickly select the corresponding term to access the relevant search results. The suggested search term feature reduces the number of times users need to type, helps users quickly find search results, and improves search efficiency, significantly enhancing the search experience and enabling the search system to more effectively meet users' needs.
[0003] A trie is a data structure that indexes the prefixes of words. By using a trie, nodes can be quickly matched to obtain words that are prefixed with the keywords entered by the user, and these words can be displayed as suggested words for the user to choose from.
[0004] In related technologies, building a prefix tree requires storing all child nodes for each node, which consumes a lot of storage space and makes it difficult to support word association matching based on ultra-large-scale terms. Moreover, due to the large size of the prefix tree, the indexing efficiency of word association is also relatively low. Summary of the Invention
[0005] Based on this, it is necessary to provide a keyword search method, apparatus, computer device, computer-readable storage medium, and computer program product to address the aforementioned technical problems. Based on the prefix tree and heap structure, the sparser nodes at the tail of the prefix tree are merged, which can significantly reduce the number of nodes, thereby improving indexing efficiency while reducing storage space usage.
[0006] Firstly, this application provides a keyword search method, including:
[0007] An initial prefix tree is constructed based on the term. Each node of the initial prefix tree corresponds to a prefix. The prefix is composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0008] For each non-leaf node, from the nodes on the path from the non-leaf node to the leaf node, select up to a target number of terms according to the term weight score, and construct a heap structure corresponding to the non-leaf node based on the target number of terms. The target number is the number of associated terms required in the search scenario.
[0009] When the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain a target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the associated words of the keyword.
[0010] Secondly, this application also provides a search device, comprising:
[0011] An initial construction module is used to construct an initial prefix tree based on the term. Each node of the initial prefix tree corresponds to a prefix. The prefix is composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0012] The heap structure construction module is used to, for each non-leaf node, filter out at most a target number of terms from the nodes recorded on the path from the non-leaf node to the leaf node according to the term weight score, and construct the heap structure corresponding to the non-leaf node based on the target number of terms, where the target number is the number of associated words required in the search scenario;
[0013] The node merging module is used to merge the non-leaf node with its child nodes when the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, to obtain a target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the associated words of the keyword.
[0014] In some embodiments, the initial construction module is used to obtain a term library for matching keywords; for each term in the term library, a corresponding encoding string is generated according to a preset encoding format, and a key-value pair is constructed between the encoding string and the term; the preset encoding format includes at least one of Chinese character conversion, Pinyin conversion, abbreviated Pinyin conversion, similar character conversion, and case conversion; an initial prefix tree is constructed based on each key-value pair.
[0015] In some embodiments, the initial construction module is used to determine at least one encoding string corresponding to each term; for each encoding string, starting from the first character of the encoding string, traversing from the root node to the child nodes; when there is a child node representing the currently traversed character, the child node is used as the new current node; when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node; the next character of the encoding string is obtained as the new current traversed character, and traversing to the child nodes of the new current node continues, returning the step of "when there is a child node representing the currently traversed character, the child node is used as the new current node; when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node", until the new current traversed character is the last character of the encoding string, the traversal ends, the child node representing the currently traversed character is marked as a leaf node, and the term corresponding to the encoding string is recorded on the leaf node.
[0016] In some embodiments, the initial construction module is used to determine the number of child nodes of a parent node in the initial prefix tree; when the number of child nodes is 1, the parent node and child node are merged.
[0017] In some embodiments, nodes record the terms and term weight scores corresponding to the corresponding prefixes; a heap structure construction module is used to determine, for each non-leaf node in the initial prefix tree, at least one leaf node that the non-leaf node leads to; obtain the terms recorded on each of the at least one leaf node; filter out at most a target number of terms from the terms according to the term weight scores; construct a min-heap corresponding to the non-leaf nodes according to the target number of terms, where each node of the min-heap represents one of the terms in the target number, and the term weight score of the term represented by the root node of the min-heap is the smallest among the corresponding terms in the target number of terms.
[0018] In some embodiments, the initial construction module is used to obtain the term search features of the term, which include at least one of the term's historical search frequency and the term's historical click rate; and to determine the term weight score of the term based on the term search features of the term.
[0019] The node merging module is used to merge the min-heaps corresponding to the non-leaf nodes with the min-heaps corresponding to the child nodes of the non-leaf nodes when the number of terms in the heap structure corresponding to the non-leaf nodes is less than the target number. This results in a merged min-heap, which is then recorded on the non-leaf nodes. Finally, the child nodes of the non-leaf nodes are deleted to obtain the target prefix tree.
[0020] In some embodiments, the keyword search device further includes:
[0021] The offline index file generation module is used to traverse the nodes of the target prefix tree, obtain the node information of each node, including the prefix and heap structure of each node; and generate an offline index file based on the node information of each node.
[0022] In some embodiments, the node information also includes the number of child nodes for each node, and the keyword search device further includes: an online construction module, used to read the number of child nodes for each node in the offline index file when constructing an online prefix tree based on the offline index file, and to apply for storage space based on the number of child nodes to construct the online prefix tree.
[0023] In some embodiments, the online construction module is further configured to read the offline index file, extract the node information of each node, and construct an online prefix tree based on the node information of each node. The node information of each node in the online prefix tree includes the child node information corresponding to each node and a list of terms composed of ordered terms in the prefix and heap structure.
[0024] In some embodiments, the keyword search device further includes:
[0025] The online matching module is used to obtain keywords, traverse the online prefix tree based on the strings included in the keywords, determine the target node that matches the keywords from the online prefix tree, and filter the associated words that match the keywords from the word list corresponding to the target node.
[0026] In some embodiments, the online matching module is configured to start from the first character of the keyword, take the root node of the online prefix tree as the current node, and traverse from the current node; when there is a child node representing the currently traversed character among the child nodes of the current node, then take the child node as the new current node, obtain the next character of the keyword as the new current traversed character, traverse to the child nodes of the new current node, and return to the previous step. When there is a child node representing the currently traversed character among the child nodes of the current node, then take the child node as the new current node, and continue to execute until there is no child node representing the currently traversed character among the child nodes of the current node, and then end the execution; when there is no child node representing the currently traversed character among the child nodes of the current node, then take the current node as the target node that matches the keyword.
[0027] In some embodiments, the online matching module is used to perform prefix matching between the terms in the term list corresponding to the target node and the keyword, and to use the terms that successfully match the prefix as the associated words that match the keyword; after sorting the terms that successfully match the prefix in the term list, it returns a list of associated words that match the keyword.
[0028] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0029] An initial prefix tree is constructed based on the term. Each node of the initial prefix tree corresponds to a prefix. The prefix is composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0030] For each non-leaf node, from the terms recorded on the leaf nodes that the non-leaf node leads to, at most a target number of terms are selected according to the term weight score. Based on the target number of terms, a heap structure corresponding to the non-leaf node is constructed. The target number is the number of associated terms required in the search scenario.
[0031] When the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain a target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the associated words of the keyword.
[0032] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0033] An initial prefix tree is constructed based on the term. Each node of the initial prefix tree corresponds to a prefix. The prefix is composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0034] For each non-leaf node, from the nodes on the path from the non-leaf node to the leaf node, select up to a target number of terms according to the term weight score, and construct a heap structure corresponding to the non-leaf node based on the target number of terms. The target number is the number of associated terms required in the search scenario.
[0035] When the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain a target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the associated words of the keyword.
[0036] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0037] An initial prefix tree is constructed based on the term. Each node of the initial prefix tree corresponds to a prefix. The prefix is composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0038] For each non-leaf node, from the nodes on the path from the non-leaf node to the leaf node, select up to a target number of terms according to the term weight score, and construct a heap structure corresponding to the non-leaf node based on the target number of terms. The target number is the number of associated terms required in the search scenario.
[0039] When the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain a target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the associated words of the keyword.
[0040] The aforementioned keyword search methods, devices, computer equipment, computer-readable storage media, and computer program products construct an initial prefix tree based on the term. Each node in the initial prefix tree corresponds to a prefix, which consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term. When the number of all terms reaches a massive scale, such as hundreds of millions, when an object inputs a few characters, the child nodes under the matched nodes in the initial prefix tree may have hundreds of thousands of terms. Traversing all child nodes to their leaf nodes requires a large number of accesses, and sorting hundreds of thousands of child terms is time-consuming, resulting in low indexing efficiency. Therefore, for each non-leaf node, from the terms recorded by the nodes on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to the term weight score. A heap structure is constructed for the non-leaf node based on the target number of terms, where the target number is the number of associated words required in the search scenario. In this way, by introducing a heap structure for each non-leaf node, the heap structure itself remains ordered, eliminating the need to sort the child nodes. Moreover, the heap structure directly stores at most the target number of terms, allowing for the retrieval of terms without further traversal, thus improving indexing efficiency. Furthermore, when the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, the non-leaf node is merged with its child nodes to obtain the target prefix tree. That is, when the number of terms in the heap structure corresponding to a non-leaf node (which is the parent node) is less than the target number to be displayed to the object, it means that the terms in the parent node's heap structure fully include the terms in the heap structures of its child nodes. Therefore, merging the non-leaf node with its child nodes reduces the storage space occupied by a large number of nodes and the storage heap structure, thus simplifying the prefix tree. The target prefix tree is used to traverse the target node matching the keyword in a search scenario and determine the terms from the heap structure corresponding to the target node as related terms for the keyword. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 is a schematic diagram of the search function interface in one embodiment;
[0043] Figure 2 is a schematic diagram of a prefix tree in one embodiment;
[0044] Figure 3 is a schematic diagram of a min-heap constructed for non-leaf nodes in one embodiment;
[0045] Figure 4 is a statistical diagram of the number of child nodes of a node in some embodiments;
[0046] Figure 5 is a schematic diagram of merging child nodes based on a heap structure in one embodiment;
[0047] Figure 6 is a schematic diagram of a radix tree in one embodiment;
[0048] Figure 7 shows the application environment of the keyword search method in one embodiment;
[0049] Figure 8 is a detailed flowchart of a keyword search method in one embodiment;
[0050] Figure 9 is a flowchart illustrating the steps of a keyword search method in one embodiment;
[0051] Figure 10 shows the search performance in one embodiment;
[0052] Figure 11 is a structural block diagram of a keyword search device in one embodiment;
[0053] Figure 12 is an internal structure diagram of a computer device in one embodiment. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0055] Before describing the embodiments of this application, the application scenarios and concepts and terms that may be used in the embodiments are first explained. The technical solution of this application can be applied to search scenarios in the field of Internet technology, such as search systems for e-commerce platforms, encyclopedia information search systems, content platform search systems, video platform search systems, etc. In some embodiments, after an object with search needs enters keywords in the search box of the application, the application can display related words matching the keywords to the object. When the object selects a target related word from at least one related word, the application displays search results for that target related word to the object. Thus, by displaying a series of related words that are related to or semantically similar to the keywords, the application provides an entry point for the object to quickly obtain search results from massive amounts of information. The object can quickly select the corresponding word to enter the corresponding search results, which can help the object improve the accuracy and efficiency of the search and enhance the search experience. As shown in Figure 1, it is a schematic diagram of the search function interface in one embodiment. The keywords entered by the object may be in the form of letters, Chinese characters, pinyin, etc. The search system needs to ensure that different forms of input can correctly match related words. Referring to part (a) of Figure 1, which is a schematic diagram of word association matching after Chinese characters are entered into the object, and referring to part (b) of Figure 1, which is a schematic diagram of word association matching after pinyin is entered into the object.
[0056] A trie, also known as a dictionary tree or key tree, is an efficient and space-saving data structure for string retrieval. It stores common prefixes of a large number of strings in shared nodes, thus avoiding the duplication of storing the same prefixes. Strings can be easily retrieved, inserted, or deleted by traversing the paths in the trie. In a trie, strings with common prefixes share the same parent node path. By utilizing these common prefixes, the overhead of query time is reduced, thus improving efficiency. It exhibits good performance and can be applied to scenarios involving predictive text search.
[0057] Figure 2 shows a schematic diagram of a prefix tree in one embodiment. Referring to Figure 2, using a dictionary consisting of five terms: apple, app, api, banana, and bus, the prefix tree is constructed as shown in Figure 2. It is understood that the basic units constituting the prefix tree are not necessarily all characters; they can also be composed of at least one of the following: Chinese characters, pinyin, numbers, letters, or characters. For example, at least one of the following processes can be performed on the terms: Chinese character conversion, pinyin conversion, abbreviated pinyin conversion, similar character conversion, and case conversion, to obtain the corresponding encoded strings. The prefix tree is then constructed based on all the encoded strings. This helps the user to match associated words in the prefix tree even when inputting similar words, synonyms, or even misspelled words. Continuing with the example above, in this dictionary, the first character of the terms apple, app, and api is 'a', so 'a' is the prefix. The first character of the terms banana and bus is 'b', so 'b' is the prefix. Therefore, referring to Figure 2, the root node has two child nodes, corresponding to the prefix 'a' and the prefix 'b', respectively. Referring to Figure 2, the second character of the terms "apple," "app," and "api" is "p," so the node corresponding to the prefix "a" has only one child node, representing the character "p," and its prefix is "ap." The second characters of the terms "banana" and "bus" are "a" and "u," respectively, so the node corresponding to the prefix "b" has two child nodes, representing the characters "a" and "u," corresponding to the prefixes "ba" and "bu," respectively. This pattern continues, with all the characters from all the terms forming all the nodes in this prefix tree. Referring to Figure 2 again, the nodes marked in gray represent prefixes formed by the characters (or strings) represented by each node on the path from the root node to that node, combined with the characters (or strings) represented by the node itself. If a prefix matches a given term, that term can be recorded at that node, and the node can be marked as a term node. For example, in Figure 2, the dashed circle corresponds to node 1 (prefix for "app"), which records the term "app," and node 2 (prefix for "api"), which records the term "api."
[0058] Following the above method, new entries can be continuously inserted. For example, when inserting a new entry "buy", first, based on the first character "b", check if the root node has a child node corresponding to the prefix "b"; this child node exists. Next, based on the second character "u", check if the node corresponding to the prefix "b" has a child node representing the character "u"; this child node exists. Then, based on the third character "y", check if the node corresponding to the prefix "bu" has a child node representing the character "y"; this child node does not exist. Therefore, a new child node representing the character "y" is created for the node representing the character "u". At this point, since the character "y" is the last character in the entry "buy", this newly created node can be marked as an entry node, and the entry recorded on this node is "buy".
[0059] When the input keyword "ap" is given, the computer device checks if the root node has a child node corresponding to the prefix "a" based on the first character "a". If it finds one, it checks if the node corresponding to the prefix "a" has a child node representing the character "p" based on the second character "p" (or checks if the node corresponding to the prefix "a" has a child node corresponding to the prefix "ap"). If both are found, it can be determined that a term with "ap" as a prefix exists in the current prefix tree. Furthermore, this process continues until a term node is found, at which the term recorded is used as a suggested word for matching the keyword.
[0060] Referring to Figure 2, the prefix tree consists of a root node, leaf nodes, and non-leaf nodes. The root node is the ancestor of all nodes in the prefix tree except itself, and it is the starting point of the prefix tree. The root node has no parent node. Leaf nodes are nodes without children, while non-leaf nodes are nodes with children. A parent node is a node in a structure that has at least one direct child node; this node is called the parent node of the child node.
[0061] Based on the above process, it can be seen that the time for inserting and searching nodes in the prefix tree is directly proportional to the number of levels in the prefix tree, which in turn is determined by the length of the terms. Furthermore, the prefix tree is very memory-intensive because it needs to store all child nodes for each node. When the number of terms reaches millions, a single machine cannot handle the massive prefix tree structure. While the prefix tree structure can retrieve all terms prefixed by the input keyword, when the dictionary is on the order of hundreds of millions, using the input keyword as a prefix may match a large number of terms, such as hundreds of thousands. The matching process requires traversing all child nodes to their corresponding leaf nodes, which involves a large number of accesses. Sorting these hundreds of thousands of terms is also very time-consuming. The word association function only needs to display the best k terms to the user. Therefore, the computer can construct a min-heap of size k for each non-leaf node according to the term weight score. The min-heap directly stores the terms, allowing retrieval of terms from non-leaf nodes without traversal, and without sorting the child nodes of non-leaf nodes, as the heap structure itself remains ordered.
[0062] Heap structure: It is an array object that can be viewed as a complete binary tree.
[0063] Min-heap: A complete binary tree data structure that satisfies the heap property: the value of each node is less than or equal to the values of its child nodes. In a min-heap, the root node always stores the minimum value in the entire heap. In the embodiments of this application, the term weight score corresponding to the root node in the heap structure corresponding to non-leaf nodes is the smallest.
[0064] Figure 3 illustrates a min-heap constructed for non-leaf nodes in one embodiment. Referring to Figure 3, the root node includes non-leaf nodes representing the strings "pingguo," "shouji," "yifu," and "10." For each non-leaf node, the computer device filters out a target number of terms from the nodes along the path from the non-leaf node to the leaf node, based on the term weight scores. A heap structure corresponding to the non-leaf node is then constructed based on this target number of terms. This avoids the significant time consumption required to traverse all child nodes to their corresponding leaf nodes. Furthermore, the ordered heap structure itself avoids the high time consumption required to sort hundreds of thousands of child terms, thus greatly improving the matching efficiency of the associated terms. For example, a min-heap of size k can be constructed, where k is the number of associated terms needed in the search scenario. For example, if k is 10, for the non-leaf node "yifu", it leads to 7 different leaf nodes. The terms recorded on the leaf nodes are "new clothes", "spring clothes", "women's clothes", "wholesale clothes", "thin clothes", "clothes shops", and "new women's clothes", with corresponding term weight scores of 5, 14, 33, 28, 48, 58, and 99, respectively. Referring to Figure 3, after sorting according to the corresponding term weight scores, a min-heap 301 is constructed.
[0065] Referring to Figure 3, after introducing the heap structure, each node needs to additionally store a heap structure consisting of up to k terms, and the node also needs to store the term weight scores for sorting, increasing memory usage. Figure 4 shows a statistical diagram of the number of child nodes of a node in some embodiments. Statistically, the horizontal axis x represents the number of child nodes x, and the vertical axis y represents the number of nodes i with x child nodes y. Based on the statistical data in Figure 4, it can be seen that in the prefix tree used for associative search, more than 95% of the nodes have fewer than 15 child nodes, while the number of associative words required in the search scenario is approximately 5-15 terms. Therefore, the prefix tree is still relatively sparse and can be further compressed. When the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, the computer device can merge the non-leaf node with its child nodes to obtain the target prefix tree. This can merge sparse nodes at the tail, significantly reducing the number of nodes and the storage space occupied by the heap structure. Thus, by combining prefix trees and heap structures, and merging heap structures of sparse nodes, it is possible to balance the indexing efficiency and memory usage of matching related words in ultra-large-scale word search scenarios, that is, to improve indexing efficiency while reducing storage space usage.
[0066] Figure 5 illustrates a schematic diagram of merging child nodes based on a heap structure in one embodiment. When the number of terms corresponding to the heap structure stored by the parent node is less than k, which is the optimal k terms to be displayed to the object, it means that the terms in the heap structure stored by the parent node include the terms in the heap structure stored by the child nodes. For example, when the target number k is 10, and the number of terms in the heap structure stored on the non-leaf node representing "clothes" is less than 10, then the terms in the heap structures of all child nodes of "clothes" must be included in the heap structure stored by "clothes". By merging the child nodes of nodes with fewer than k terms in the heap structure, the number of nodes can be significantly reduced, thus reducing the storage space occupied.
[0067] A radix tree is a special type of prefix tree, also known as a compressed prefix tree. It reduces the number of nodes by merging the unique child nodes of a parent node with its parent node. Since the tails of the prefix tree's associated words are relatively sparse, easily forming many single-node subtrees, a radix tree effectively avoids a large number of single-node subtrees, significantly reducing memory usage. Figure 6 shows a schematic diagram of a radix tree in one embodiment. Referring to Figure 6, the computer device can also traverse the prefix tree by counting the number of child nodes of a parent node. If the number of child nodes is 1, the parent node and child node are merged. It can be seen that the original large number of nodes, after compression, only a small number of nodes need to be stored.
[0068] Index files: By organizing the elements in a data set according to a certain order and rules, search and access operations can be performed more efficiently. They are used to quickly locate and access information in databases, file systems, or other data sets.
[0069] A byte is one of the most fundamental units of data storage in computer science. It typically consists of 8 binary bits and can represent 256 different states or values. Bytes are an important standard unit for measuring computer storage capacity; kilobytes (KB), megabytes (MB), and gigabytes (GB) are all multiples of bytes.
[0070] The keyword search method provided in this application embodiment can be applied to the application environment shown in Figure 7. In this environment, terminal 702 communicates with server 704 via a network. A data storage system can store the data that server 704 needs to process. The data storage system can be integrated onto server 704, or it can be located in the cloud or on another network server. In one embodiment, the keyword search method provided in this application embodiment can be executed by a server. The server 704 can construct an initial prefix tree based on the terms. Each node of the initial prefix tree corresponds to a prefix. The prefix consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The nodes with the same prefix as the terms record the terms. For each non-leaf node, the terms recorded by the nodes on the path from the non-leaf node to the leaf node are selected according to the term weight score, up to a target number of terms. The heap structure corresponding to the non-leaf node is constructed according to the target number of terms. The target number is the number of associated words required in the search scenario. When the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain a target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms as associated words of the keyword from the heap structure corresponding to the target node.
[0071] Among them, terminal 702 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Head-mounted devices can include virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. Server 704 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0072] Figure 8 shows a detailed flowchart of a keyword search method in one embodiment. Referring to Figure 8, the detailed flowchart can be divided into two parts: online side and offline side. Offline side: The server can obtain a thesaurus, perform text preprocessing on the entries in the thesaurus, generate corresponding encoded strings, construct a target prefix tree based on the encoded strings, and generate an offline index file based on the target prefix tree. Online side: The terminal side of the search system can provide a search box for users to input keywords. The server side of the search system performs keyword retrieval and sorting based on the keywords input by the users and the offline index file, outputs a list of related keywords, and the terminal side of the search system can receive and display the list of related keywords returned by the server side of the search system.
[0073] In an exemplary embodiment, as shown in FIG9, a keyword search method is provided. Taking the application of this method to the computer device (e.g., server 704) in FIG7 as an example, the method includes the following steps 902 to 906. Wherein:
[0074] Step 902: Construct an initial prefix tree based on the term. Each node in the initial prefix tree corresponds to a prefix. The prefix consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0075] A prefix tree is an efficient and space-saving data structure for string lookup. Computer devices can construct prefix trees based on a large number of terms in a terminology database, which can be on the order of hundreds of millions. Each node in a prefix tree represents a string (which can be a single character), and each node corresponds to a prefix. The prefix is composed of the strings represented by the nodes along the path from the root node to the node, and the string represented by the node itself. In a prefix tree, strings with a common prefix share the same parent node path. By utilizing the common prefixes of strings, the query time overhead is reduced, thus improving efficiency. It has good performance and can be applied to scenarios involving associative word retrieval. Referring to Figure 2, the two nodes representing 'a' and 'u' share a common prefix 'b'. For the node representing 'a', the strings represented by 'b' along the path from the root node to that node, together with the string 'a', form the prefix 'ba', meaning that the node corresponds to the prefix 'ba'. For the node representing 'u', the strings represented by 'b' along the path from the root node to that node, together with the string 'u', form the prefix 'bu', meaning that the node corresponds to the prefix 'bu'.
[0076] In some embodiments, constructing an initial prefix tree based on terms includes: obtaining a term library for matching keywords; for each term in the term library, generating a corresponding encoding string according to a preset processing method, and constructing a key-value pair between the encoding string and the term; the preset encoding format includes at least one of Chinese character conversion, Pinyin conversion, abbreviated Pinyin conversion, similar character conversion, and case conversion; and constructing an initial prefix tree based on each key-value pair.
[0077] Alternatively, computer devices can acquire a large number of terms for associative matching in different ways. For example, they can obtain a large number of terms based on the historical terms of the object input, or they can segment or extract the titles or summaries of content on the Internet to obtain a large number of terms, or they can generate a large number of terms based on models, etc. These terms constitute a large-scale term library.
[0078] Optionally, for each term, the computer device can also generate a corresponding term weight score, which can represent the weight of the term during recall. Among the large number of terms matched by the keyword, the higher the term weight score, the more likely the term will be recalled as a related term for that keyword.
[0079] Optionally, for each term, the computer device can determine the corresponding term weight score using a deep learning model. For example, it can determine the term weight score based on features such as the term's historical search frequency and historical click-through rate. Specifically, the computer device can acquire the term's search features, which include at least one of the term's historical search frequency and historical click-through rate; and determine the term's weight score based on the term's search features.
[0080] The data format for the constructed terms can be as follows:
[0081] {"word":"dried tofu","weight":"0.4287312"},
[0082] {"word":"pure milk","weight":"0.39012843"},
[0083] {"word":"What causes bones to crack?","weight":"0.9411842"},
[0084] {"word":"fitness equipment","weight":"0.2974023"},
[0085] {"word":"seafood","weight":"0.83941203"},
[0086] {"word":"When will the Olympics start?","weight":"0.0736123"}
[0087] ...
[0088] {"word":"air conditioner","weight":"0.5283123"}.
[0089] Here, "word" represents a term, and "weight" represents the term's weight score.
[0090] Optionally, the computer device can also perform text cleaning on the entries, including but not limited to removing punctuation marks, spaces, special characters, etc. from the entries, such as converting "fresh milk 500ml" to "fresh milk 500ml".
[0091] Optionally, the computer device can also generate a corresponding encoded string according to a preset encoding format. The encoded string is used to match the keywords input by the object, and the entry is used to display the associated words to the object. In this way, by generating a corresponding encoded string for each entry according to the preset encoding format, it is convenient to support various forms of words input by the object, including but not limited to Chinese characters, pinyin, abbreviated pinyin, similar characters, homophonic characters, case-insensitive matching, and so on. Therefore, the preset encoding format includes at least one of, but is not limited to, Chinese character conversion, pinyin conversion, abbreviated pinyin conversion, similar character conversion, and case conversion. For example, the full pinyin of the original entry "牛奶" is "niunai", the initials abbreviated pinyin is "nn", and the error-prone word "niulai". When the object inputs "牛", "niuna", or "nn", it may match "牛奶". The corresponding entry data format after conversion is as follows:
[0092] {"word": "牛奶500ML", "code": "牛奶500ml ", "weight": "0.4287312"},
[0093] {"word": "牛奶500ML", "code": "niunai500ml ", "weight": "0.4287312"},
[0094] {"word": "牛奶500ML", "code": "nn500ml ", "weight": "0.4287312"},
[0095] {"word": "牛奶低脂", "code": "nn500ml ", "weight": "0.4653283"},
[0096] ……
[0097] {"word": "空调", "code": "空调", "weight": "0.5283123"}。
[0098] Among them, "word" represents the entry, "code" represents the encoded string, and "weight" represents the entry weight score corresponding to the entry. Optionally, the computer device can first perform text cleaning on the entry and then generate the corresponding encoded string according to the preset encoding format.
[0099] In some embodiments, for each entry, after obtaining the corresponding encoded string in the above manner, a key-value pair is constructed with the encoded string and the entry. The computer device can construct an initial prefix tree based on a large number of key-value pairs.
[0100] In some embodiments, constructing an initial prefix tree based on terms includes: determining at least one encoding string corresponding to each term; for each encoding string, starting from the first character of the encoding string, traversing from the root node to the child nodes; when there is a child node representing the currently traversed character, the child node is used as the new current node; when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node; obtaining the next character of the encoding string as the new current traversed character, traversing to the child nodes of the new current node, and returning the previous character; continuing to execute the steps of "when there is a child node representing the currently traversed character, the child node is used as the new current node; when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node" until the new current traversed character is the last character of the encoding string, ending the traversal; marking the child node representing the currently traversed character as a leaf node, and recording the term corresponding to the encoding string on the leaf node.
[0101] Specifically, the construction process of the initial prefix tree includes the following steps:
[0102] 1. Initialize the root node. The initial prefix tree is constructed starting from the root node, which is usually an empty node representing an empty string.
[0103] 2. For each inserted key-value pair (encoded string-word), starting from the root node, traverse downwards in the tree according to each character of the encoded string.
[0104] 3. When a node is encountered, its child node list should contain the node corresponding to the currently traversed character. If the child node list does not contain a node corresponding to the currently traversed character, a new node is created based on the currently traversed character and added to the child node list of the current node.
[0105] 4. If the currently traversed character is the last character of the key (encoded string), and the node is not yet a leaf node, then mark it as a leaf node and store the corresponding value (word) in that leaf node. Such leaf nodes can also be marked as word nodes. It can be seen that each node corresponds to a prefix, and the prefix corresponding to a leaf node is the same as the word recorded on that leaf node. It is understandable that as key-value pairs are continuously updated, nodes marked as leaf nodes may continue to have child nodes, but the marking of these nodes is preserved. For example, referring to Figure 2, the node recording the word "app" also has child nodes.
[0106] 5. Repeat the above steps: For each key-value pair that is inserted, insert it into the prefix tree according to the above steps until all key-value pairs are inserted into the prefix tree.
[0107] In some embodiments, the method further includes: determining the number of child nodes of a parent node in the initial prefix tree; and merging the parent node with the child node if the number of child nodes is 1.
[0108] Specifically, because the prefix tree has a sparse ending of associated words, it easily forms many single-node subtrees, and each pinyin entry requires an average of 14 tree nodes. Compared to the standard prefix tree, the radix tree (compressed prefix tree) can effectively avoid a large number of single-node subtrees, reducing memory usage. The computer device traverses the prefix tree by counting the number of child nodes of the parent node. If the number of child nodes is 1, the parent node and child node are merged. After compression, only a small number of nodes need to be stored.
[0109] Step 904: For each non-leaf node, select up to a target number of terms from the nodes recorded on the path from the non-leaf node to the leaf node according to the term weight score, and construct a heap structure corresponding to the non-leaf node based on the target number of terms. The target number is the number of associated words required in the search scenario.
[0110] The target number refers to the number of related terms needed in the search scenario. For example, if the search scenario requires recommending k terms to an object, the target number is k, which can be between 10 and 15. When an object inputs a keyword, the computer device can obtain all terms prefixed with the input keyword based on the initial prefix tree. However, when the vocabulary is on the order of hundreds of millions, using the input keyword as a prefix may match a large number of terms, such as hundreds of thousands. Finding these hundreds of thousands of terms requires traversing all child nodes of the node prefixed with that keyword to its corresponding leaf node. This process requires a large number of accesses and obviously consumes a lot of computing resources. In addition, after obtaining hundreds of thousands of child terms, sorting them according to their weight scores to select k terms is obviously very time-consuming, also consuming a lot of computing resources, and will also slow down the matching process of related terms, thus affecting the search experience. Considering that the word association function only needs to display k words to the object, the computer device can build a min-heap of size k for each non-leaf node in the initial prefix tree according to the weight score of the word. The min-heap directly stores the words, and words can be obtained through non-leaf nodes without traversal. Moreover, there is no need to sort the child nodes of non-leaf nodes because the heap structure itself is ordered.
[0111] Specifically, for each non-leaf node, among the terms recorded by nodes on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to their weight scores. A heap structure corresponding to the non-leaf node is then constructed based on this target number of terms. Nodes that record terms on the path from the non-leaf node to the leaf node are nodes that have been marked as leaf nodes, i.e., the term nodes mentioned earlier, i.e., nodes whose prefixes are the same as the terms. These nodes record terms.
[0112] In some embodiments, nodes record the terms and their weight scores corresponding to the prefixes. For each non-leaf node, from the terms recorded by nodes on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to their weight scores. A heap structure corresponding to the non-leaf node is constructed based on the target number of terms, including: for each non-leaf node in the initial prefix tree, determining at least one leaf node that the non-leaf node leads to; obtaining the terms recorded on each of the at least one leaf node; selecting at most a target number of terms from the terms according to their weight scores; and constructing a min-heap corresponding to the non-leaf node based on the target number of terms. Each node in the min-heap represents one of the terms in the target number of terms, and the term weight score of the term represented by the root node of the min-heap is the smallest among the terms in the target number of terms.
[0113] For example, as shown in Figure 2, for a non-leaf node corresponding to the prefix ap, the paths from this non-leaf node to the leaf node are ap→p, ap→i, and ap→p→l→e. These paths record the terms app, api, and apple, with a target quantity of 10. Therefore, a heap structure containing 3 terms can be built for this non-leaf node. If, in some cases, the paths from this non-leaf node to the leaf node record more than 10 terms, only the top 10 terms with the highest weight scores are selected to construct a min-heap for this non-leaf node.
[0114] In some embodiments, when the term weight score of the term in the min-heap corresponding to a non-leaf node is updated, or when a new term is inserted with a prefix corresponding to the non-leaf node, then, based on the ordered structure of the min-heap, it is only necessary to compare the term weight score of the new term with the term weight score of the term represented by the root node in the min-heap. If the term weight score of the new term is smaller than the term weight score of the term represented by the root node, then there is no need to update the min-heap. If the term weight score of the new term is larger than the term weight score of the term represented by the root node, then the child nodes of the root node in the min-heap are traversed and compared with the term weight scores of the terms represented by the child nodes to see whether to replace the root node or replace the child nodes. In this way, efficient updating of the min-heap is achieved.
[0115] Thus, for example, the data structure of each node in the initial prefix tree can be:
[0116] Node {
[0117] / / Child node information
[0118] map[string]*Node children
[0119] / / Store the min-heap constructed from the k terms under the current node
[0120] Heap wordHeap
[0121] / / Prefix corresponding to the node
[0122] String prefix
[0123] }
[0124] Step 906: When the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, merge the non-leaf node with its child nodes to obtain the target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the keyword's associated words.
[0125] When the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, it means that the terms in the heap structure corresponding to the parent non-leaf node include the terms in the heap structures corresponding to its child nodes. As shown in Figure 5, for example, when the target number k is 10, and the number of terms in the heap structure stored on the non-leaf node representing "clothes" is less than 10, then the terms in the heap structures of all child nodes of "clothes" must be included in the heap structure stored for "clothes". By merging the child nodes of nodes with less than k terms in the heap structure, the number of nodes can be significantly reduced, thus reducing the storage space occupied.
[0126] In some embodiments, when the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain the target prefix tree. This includes: when the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, merging the min-heap corresponding to the non-leaf node and the min-heap corresponding to the child nodes of the non-leaf node to obtain a merged min-heap, recording the merged min-heap on the non-leaf node, and deleting the child nodes of the non-leaf node to obtain the target prefix tree.
[0127] In the keyword search method described above, an initial prefix tree is constructed based on the term. Each node in the initial prefix tree corresponds to a prefix. The prefix consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term. When the number of all terms reaches a massive scale, such as hundreds of millions, when an object inputs a few characters, the child nodes under the matched nodes in the initial prefix tree may have hundreds of thousands of terms. Traversing all child nodes to their leaf nodes requires a large number of accesses, and sorting hundreds of thousands of child terms is time-consuming, resulting in low indexing efficiency. Therefore, for each non-leaf node, from the terms recorded by the nodes on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to the term weight score. A heap structure is constructed for the non-leaf node based on the target number of terms, where the target number is the number of associated words required in the search scenario. In this way, by introducing a heap structure for each non-leaf node, the heap structure itself remains ordered, eliminating the need to sort the child nodes. Moreover, the heap structure directly stores at most the target number of terms, allowing for the retrieval of terms without further traversal, thus improving indexing efficiency. Furthermore, when the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, the non-leaf node is merged with its child nodes to obtain the target prefix tree. That is, when the number of terms in the heap structure corresponding to a non-leaf node (which is the parent node) is less than the target number to be displayed to the object, it means that the terms in the parent node's heap structure fully include the terms in the heap structures of its child nodes. Therefore, merging the non-leaf node with its child nodes reduces the storage space occupied by a large number of nodes and the storage heap structure, thus simplifying the prefix tree. The target prefix tree is used to traverse the target node matching the keyword in a search scenario and determine the terms from the heap structure corresponding to the target node as related terms for the keyword.
[0128] In some embodiments, the method further includes: traversing the nodes of the target prefix tree, obtaining node information for each node, the node information including the prefix and heap structure corresponding to each node; and generating an offline index file based on the node information for each node.
[0129] The target prefix tree obtained based on the aforementioned steps contains a small number of nodes and has high indexing efficiency. After obtaining the target prefix tree, the computer device can generate a corresponding offline index file based on it. Specifically, by traversing the nodes of the target prefix tree, the node information of each node is obtained, and an offline index file is generated based on the node information. For example, the data structure of each node in the offline index file can be:
[0130] Index {
[0131] / / Prefix corresponding to the current node
[0132] [ ]string Prefix
[0133] / / Store the min-heap corresponding to the current node, containing k terms.
[0134] Heap wordHeap
[0135] }
[0136] In computers, relationships between nodes in a tree structure are typically stored using arrays or hash tables. When building a target prefix tree, as nodes are continuously added, the storage capacity for child nodes eventually reaches its limit, triggering resizing. To avoid frequent storage requests and data migrations, each resizing increments by a certain coefficient. For example, in Go, when a slice has less than 256 elements, adding elements will double the capacity by a factor of 2. When the capacity is between 256 and 1024 elements, a slightly smaller coefficient is used. Once the capacity exceeds 1024 elements, the coefficient decreases, but the actual storage space required for resizing increases. See the table below for details.
[0137] Current capacity expansion factor: 2562.05121.6310241.4420481.3540961.30 surface
[0138] This means that if the relationships between nodes are stored using slices in the prefix tree, and the current number is 1025, which is greater than 1024, then 2048 slots of capacity will be requested, leaving approximately 1023 slots without storing valid data, resulting in a significant waste of storage space. Therefore, on the offline side, the computer device can recursively count the number of child nodes for each node by recursively processing the entire target prefix tree and outputting this count to an offline index file. This way, when constructing the online prefix tree on the online side based on the offline index file, storage space can be requested according to the number of child nodes indicated in the offline index file, improving storage space utilization.
[0139] In some embodiments, the node information also includes the number of child nodes for each node, and the method further includes: when constructing an online prefix tree based on an offline index file, reading the number of child nodes for each node in the offline index file, and allocating storage space based on the number of child nodes to construct the online prefix tree.
[0140] For example, the data structure of each node in the offline index file can be designed as follows:
[0141] Index {
[0142] / / Prefix corresponding to the current node
[0143] [ ]string Prefix
[0144] / / Number of child nodes, used to specify the required storage space.
[0145] uint32 ChildCount
[0146] / / Store the min-heap corresponding to the current node, containing k terms.
[0147] Heap wordHeap
[0148] }
[0149] In some embodiments, the method further includes: reading an offline index file and extracting node information for each node; constructing an online prefix tree based on the node information for each node, wherein the node information for each node in the online prefix tree includes the child node information, prefix, and heap structure. In this embodiment, the node information of the online prefix tree includes a heap structure, which needs to additionally store the term weight score corresponding to each term so that after a successful match, the terms are sorted to form an ordered term list presented to the object.
[0150] In some embodiments, the method further includes: reading an offline index file and extracting node information for each node; constructing an online prefix tree based on the node information for each node, wherein the node information for each node in the online prefix tree includes the child node information corresponding to each node and a list of terms composed of ordered terms in the prefix and heap structure.
[0151] In this embodiment, by reading the offline index file, an online prefix tree for online word association can be constructed using a different data structure than the nodes in the offline target prefix tree. For example, the node information can directly store a list of words composed of sorted terms in a heap structure. In this way, when constructing the online prefix tree, only the ordered list of words needs to be saved, without needing to save the corresponding term weight score for each term, which can also reduce the storage space occupied significantly.
[0152] For example, the data structure of each node in the online prefix tree can be designed as follows:
[0153] Node {
[0154] / / Information on the child nodes of the current node, the size of which is the number of child nodes in the offline index file, ChildCount.
[0155] map[string]*Node children
[0156] / / Directly save the k entries from the min-heap corresponding to the current node
[0157] [ ]string TopWords
[0158] / / Prefix corresponding to the node
[0159] string prefix
[0160] }
[0161] In some embodiments, the computer device can generate the time-consuming task of building the target prefix tree offline, such as building the heap structure corresponding to non-leaf nodes and counting the number of child nodes of nodes. In this way, the loading time of the index can be greatly reduced on the online side, and the online side only needs to build the online prefix tree based on the offline index file and then perform word association matching.
[0162] In some embodiments, the method further includes: obtaining keywords; traversing an online prefix tree based on the strings included in the keywords; determining a target node matching the keywords from the online prefix tree; and filtering associated words matching the keywords from the list of terms corresponding to the target node.
[0163] In a specific application scenario, when an object enters a keyword into a search engine or text editor, a computer device with search functionality can use a constructed online prefix tree to index related terms and identify matching related terms. The terminal can then display these related terms, providing the object with an entry point to quickly retrieve search results from a vast amount of information. The object can quickly select the corresponding term to access the relevant search results, improving search accuracy and efficiency, and enhancing the search experience.
[0164] In some embodiments, determining the target node matching the keyword from the online prefix tree includes: starting from the first character of the keyword, taking the root node of the online prefix tree as the current node, and traversing from the current node; if there is a child node representing the currently traversed character among the child nodes of the current node, then taking the child node as the new current node, obtaining the next character of the keyword as the new current traversed character, traversing to the child nodes of the new current node, and returning to the previous step. If there is a child node representing the currently traversed character among the child nodes of the current node, then taking the child node as the new current node continues to execute until there is no child node representing the currently traversed character among the child nodes of the current node, and then ending the execution; if there is no child node representing the currently traversed character among the child nodes of the current node, then taking the current node as the target node matching the keyword.
[0165] In some embodiments, when the constructed online prefix tree includes a heap structure corresponding to a node, filtering associated words matching the keyword from the word list corresponding to the target node includes: reading the words and their corresponding weight scores from the heap structure corresponding to the target node; arranging the read words in order according to their weight scores to obtain a word list; performing prefix matching on each word in the word list with the keyword; and using the words with successful prefix matching as associated words matching the keyword. That is, if the node information includes words and their corresponding weight scores, the words are first sorted according to their weight scores in the heap structure to obtain an ordered word list, and then prefix matching is performed, returning the associated word list in the same order. Alternatively, if the node information includes words and their corresponding weight scores, prefix matching is first performed to filter associated words from the heap structure, and then the words are sorted according to their weight scores to obtain an ordered associated word list, which is then returned.
[0166] In some embodiments, when the constructed online prefix tree directly includes an ordered list of terms from the heap structure corresponding to the node, and no corresponding term weight scores are stored, the process of filtering associated words matching the keyword from the term list corresponding to the target node includes: performing prefix matching on each term in the term list corresponding to the target node with the keyword, and using the terms that successfully match the prefix as associated words matching the keyword; and returning the list of associated words matching the keyword after sorting the terms that successfully match the prefix according to their order in the term list. That is, if the node information directly includes an ordered list of terms, the associated word list is returned in that order after prefix matching, without needing to sort according to term weight scores.
[0167] It should be noted that because the heap structure corresponding to the node is merged when constructing the target prefix tree, the heap structure corresponding to the node may include entries that do not match the input keyword. Therefore, on the online side, it is necessary to perform prefix matching between the keyword and the entry list, including but not limited to text prefix, pinyin prefix, and abbreviation prefix matching, in order to find accurate associated words from the limited entry list. For example, referring to Figure 5, for a non-leaf node representing "clothes", after merging the heap structure corresponding to its child nodes, the heap structure corresponding to this non-leaf node includes the entries "new clothes", "spring clothes", "women's clothing", "wholesale clothes", "clothes mini-program", "clothes shop", and "new women's clothing". So, when the input keyword is "women's clothing", after matching the target node "clothes", it is still necessary to match the keyword with the entries in the entry list corresponding to the target node "clothes" to filter out the associated words that match the keyword "women's clothing", namely "women's clothing" and "new women's clothing".
[0168] Based on test data, merging a single child node with its parent node can effectively avoid a large number of single nodes, reducing memory usage by 63%. Further merging sparse nodes at the tail based on the number of terms contained in the heap structure reduces the number of nodes and the space occupied by the heap structure by more than 50%. Storing the number of child nodes in the node information and allocating designated storage space according to the number of child nodes can further reduce storage space usage by more than 30%. When constructing the online prefix tree, only the ordered list of terms formed by the heap structure corresponding to the node is saved, without storing term weight scores, which can also reduce memory usage by more than 10%. In one embodiment, a compressed prefix tree is used, introducing a min-heap and merging sparse nodes at the tail, combined with a simplified online prefix tree structure that does not store term weight scores, which can improve storage space utilization. Figure 10 shows the search performance effect in one embodiment. It can effectively support 100 million Chinese and English entries, requiring only 15GB of memory. It meets the requirements of association matching for ultra-large-scale word databases on a single machine. Under a stress test of 1000 QPS (1000 keyword search requests per second) with 8 cores and 16G, the latency of P95 (responding to 95% of keyword search requests) is controlled within 2ms. It does not require caching design and can support hundreds of millions of entries on a single machine. It can be applied to various search scenarios.
[0169] In one specific embodiment, a keyword search method is provided, executed by a server, which may include the following steps:
[0170] 1. A thesaurus used for matching keywords;
[0171] 2. For each entry in the dictionary, generate a corresponding encoding string according to a preset encoding format, and construct a key-value pair between the encoding string and the entry; the preset encoding format includes at least one of the following: Chinese character conversion, Pinyin conversion, abbreviated Pinyin conversion, similar character conversion, and case conversion;
[0172] 3. Construct an initial prefix tree based on each key-value pair. Each node in the initial prefix tree corresponds to a prefix. The prefix consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The node with the same prefix as the term records the term.
[0173] 4. Determine the number of child nodes of the parent node in the initial prefix tree;
[0174] 5. If the number of child nodes is 1, merge the parent node with the child node;
[0175] 6. For each non-leaf node in the initial prefix tree, determine the at least one leaf node that the non-leaf node leads to, and obtain the terms recorded on each of the at least one leaf node.
[0176] 7. Select the target number of terms from the terms based on their weight scores;
[0177] 8. Construct a min-heap corresponding to the non-leaf nodes based on the target number of terms. Each node in the min-heap represents one of the terms in the target number of terms. The term weight score of the term represented by the root node of the min-heap is the smallest among the terms in the target number of terms. The target number is the number of associated terms required in the search scenario.
[0178] 9. When the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, merge the min-heap corresponding to the non-leaf node with the min-heap corresponding to the child nodes under the non-leaf node to obtain a merged min-heap. Record the merged min-heap on the non-leaf node and delete the child nodes under the non-leaf node to obtain the target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the keyword's associated words.
[0179] 10. Traverse the nodes of the target prefix tree and obtain the node information of each node. The node information includes the prefix and heap structure corresponding to each node, as well as the number of child nodes of each node.
[0180] 11. Generate an offline index file based on the node information of each node.
[0181] 12. Read the offline index file and extract the node information for each node;
[0182] 13. Based on the node information of each node, construct an online prefix tree. The node information of each node in the online prefix tree includes the child node information corresponding to each node, the word list composed of ordered words in the prefix and heap structure, and the number of child nodes.
[0183] 14. Obtain keywords and traverse the online prefix tree based on the strings included in the keywords;
[0184] 15. Determine the target node that matches the keyword from the online prefix tree;
[0185] 16. Perform prefix matching between the terms in the term list corresponding to the target node and the keyword, and use the terms that successfully match the prefix as the associated terms that match the keyword;
[0186] 17. After sorting the successfully matched prefixes in the word list, return the list of related words that match the keywords.
[0187] The keyword search method described above constructs an initial prefix tree based on the term. Each node in the initial prefix tree corresponds to a prefix. The prefix consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term. When the number of all terms reaches a massive scale, such as hundreds of millions, when an object inputs a few characters, the child nodes under the matched nodes in the initial prefix tree may have hundreds of thousands of terms. Traversing all child nodes to their leaf nodes requires a large number of accesses, and sorting hundreds of thousands of child terms is time-consuming, resulting in low indexing efficiency. Therefore, for each non-leaf node, from the terms recorded by the nodes on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to the term weight score. A heap structure is constructed for the non-leaf node based on the target number of terms, where the target number is the number of associated words required in the search scenario. In this way, by introducing a heap structure for each non-leaf node, the heap structure itself remains ordered, eliminating the need to sort the child nodes. Moreover, the heap structure directly stores at most the target number of terms, allowing for the retrieval of terms without further traversal, thus improving indexing efficiency. Furthermore, when the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, the non-leaf node is merged with its child nodes to obtain the target prefix tree. That is, when the number of terms in the heap structure corresponding to a non-leaf node (which is the parent node) is less than the target number to be displayed to the object, it means that the terms in the parent node's heap structure fully include the terms in the heap structures of its child nodes. Therefore, merging the non-leaf node with its child nodes reduces the storage space occupied by a large number of nodes and the storage heap structure, thus simplifying the prefix tree. The target prefix tree is used to traverse the target node matching the keyword in a search scenario and determine the terms from the heap structure corresponding to the target node as related terms for the keyword.
[0188] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0189] Based on the same inventive concept, this application also provides a keyword search device for implementing the keyword search method described above. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations in one or more keyword search device embodiments provided below can be found in the limitations of the keyword search method described above, and will not be repeated here.
[0190] In an exemplary embodiment, as shown in FIG11, a keyword search device 1100 is provided, including: an initial construction module 1102, a heap structure construction module 1104, and a node merging module 1106, wherein:
[0191] The initial construction module 1102 is used to construct an initial prefix tree based on the term. Each node of the initial prefix tree corresponds to a prefix. The prefix is composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term.
[0192] The heap structure construction module 1104 is used to, for each non-leaf node, filter out at most a target number of terms from the nodes recorded on the path from the non-leaf node to the leaf node according to the term weight score, and construct the heap structure corresponding to the non-leaf node based on the target number of terms. The target number is the number of associated words required in the search scenario.
[0193] The node merging module 1106 is used to merge the non-leaf nodes with their child nodes when the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, to obtain the target prefix tree. The target prefix tree is used to traverse the target node that matches the keyword in the search scenario and determine the terms from the heap structure corresponding to the target node as the keyword's associated words.
[0194] In some embodiments, the initial construction module 1102 is used to obtain a term library for matching keywords; for each term in the term library, a corresponding encoding string is generated according to a preset encoding format, and a key-value pair is constructed between the encoding string and the term; the preset encoding format includes at least one of Chinese character conversion, Pinyin conversion, abbreviated Pinyin conversion, similar character conversion, and case conversion; and an initial prefix tree is constructed based on each key-value pair.
[0195] In some embodiments, the initial construction module 1102 is used to determine at least one encoding string corresponding to each term; for each encoding string, starting from the first character of the encoding string, traversing from the root node to the child nodes; when there is a child node representing the currently traversed character, the child node is used as the new current node; when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node; the next character of the encoding string is obtained as the new current traversed character, and traversing to the child nodes of the new current node continues, returning the step of when there is a child node representing the currently traversed character, the child node is used as the new current node, and when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node, until the new current traversed character is the last character of the encoding string, the traversal ends, the child node representing the currently traversed character is marked as a leaf node, and the term corresponding to the encoding string is recorded on the leaf node.
[0196] In some embodiments, the initial construction module 1102 is used to determine the number of child nodes of a parent node in the initial prefix tree; when the number of child nodes is 1, the parent node and child node are merged.
[0197] In some embodiments, nodes record the terms and term weight scores corresponding to the corresponding prefixes; the heap structure construction module 1104 is used to determine, for each non-leaf node in the initial prefix tree, at least one leaf node that the non-leaf node leads to; obtain the terms recorded on each of the at least one leaf node; filter out at most a target number of terms from the terms according to the term weight scores; construct a min-heap corresponding to the non-leaf nodes according to the target number of terms, where each node of the min-heap represents one of the terms in the target number of terms, and the term weight score of the term represented by the root node of the min-heap is the smallest among the corresponding terms in the target number of terms.
[0198] In some embodiments, the initial construction module 1102 is used to obtain the term search features of the term, which include at least one of the term's historical search frequency and the term's historical click rate; and to determine the term weight score of the term based on the term search features of the term.
[0199] The node merging module, used by node merging module 1106, is used to merge the min-rooted heap corresponding to the non-leaf node with the min-rooted heap corresponding to the child node under the non-leaf node when the number of terms in the heap structure corresponding to the non-leaf node is less than the target number. This results in a merged min-rooted heap, which is recorded on the non-leaf node. The child nodes under the non-leaf node are then deleted to obtain the target prefix tree.
[0200] In some embodiments, the keyword search device 1100 further includes:
[0201] The offline index file generation module is used to traverse the nodes of the target prefix tree, obtain the node information of each node, including the prefix and heap structure of each node; and generate an offline index file based on the node information of each node.
[0202] In some embodiments, the node information also includes the number of child nodes of each node. The keyword search device 1100 further includes an online construction module, which is used to read the number of child nodes of each node in the offline index file when constructing an online prefix tree based on the offline index file, and to apply for storage space based on the number of child nodes to construct the online prefix tree.
[0203] In some embodiments, the online construction module is further configured to read the offline index file, extract the node information of each node, and construct an online prefix tree based on the node information of each node. The node information of each node in the online prefix tree includes the child node information corresponding to each node and a list of terms composed of ordered terms in the prefix and heap structure.
[0204] In some embodiments, the keyword search device 1100 further includes:
[0205] The online matching module is used to obtain keywords, traverse the online prefix tree based on the strings included in the keywords, determine the target node that matches the keywords from the online prefix tree, and filter the associated words that match the keywords from the word list corresponding to the target node.
[0206] In some embodiments, the online matching module is configured to start from the first character of the keyword, take the root node of the online prefix tree as the current node, and traverse from the current node; when there is a child node representing the currently traversed character among the child nodes of the current node, then take the child node as the new current node, obtain the next character of the keyword as the new current traversed character, traverse to the child nodes of the new current node, and return to the previous step. When there is a child node representing the currently traversed character among the child nodes of the current node, then take the child node as the new current node, and continue to execute until there is no child node representing the currently traversed character among the child nodes of the current node, and then end the execution; when there is no child node representing the currently traversed character among the child nodes of the current node, then take the current node as the target node that matches the keyword.
[0207] In some embodiments, the online matching module is used to perform prefix matching between the terms in the term list corresponding to the target node and the keyword, and to use the terms that successfully match the prefix as the associated words that match the keyword; after sorting the terms that successfully match the prefix in the term list, it returns a list of associated words that match the keyword.
[0208] The keyword search device 1100 described above constructs an initial prefix tree based on the term. Each node in the initial prefix tree corresponds to a prefix. The prefix consists of the strings represented by each node on the path from the root node to the node and the string represented by the node itself. The term is recorded on the node whose prefix is the same as the term. When the number of all terms reaches a massive scale, such as hundreds of millions, when an object inputs a few characters, the child nodes under the matched nodes in the initial prefix tree may have hundreds of thousands of terms. Traversing all child nodes to their leaf nodes requires a large number of accesses, and sorting hundreds of thousands of child terms is time-consuming, resulting in low indexing efficiency. Therefore, for each non-leaf node, from the terms recorded by the nodes on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to the term weight score. A heap structure is constructed for the non-leaf node based on the target number of terms, where the target number is the number of associated words required in the search scenario. In this way, by introducing a heap structure for each non-leaf node, the heap structure itself remains ordered, eliminating the need to sort the child nodes. Moreover, the heap structure directly stores at most the target number of terms, allowing for the retrieval of terms without further traversal, thus improving indexing efficiency. Furthermore, when the number of terms in the heap structure corresponding to a non-leaf node is less than the target number, the non-leaf node is merged with its child nodes to obtain the target prefix tree. That is, when the number of terms in the heap structure corresponding to a non-leaf node (which is the parent node) is less than the target number to be displayed to the object, it means that the terms in the parent node's heap structure fully include the terms in the heap structures of its child nodes. Therefore, merging the non-leaf node with its child nodes reduces the storage space occupied by a large number of nodes and the storage heap structure, thus simplifying the prefix tree. The target prefix tree is used to traverse the target node matching the keyword in a search scenario and determine the terms from the heap structure corresponding to the target node as related terms for the keyword.
[0209] Each module in the aforementioned keyword search device 1100 can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0210] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram is shown in Figure 12. The computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is connected to the system bus via the I / O interfaces. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes non-volatile storage media and internal memory. The non-volatile storage media stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The I / O interfaces of the computer device are used for exchanging information between the processor and external devices. The communication interface of the computer device is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a keyword search method.
[0211] Those skilled in the art will understand that the structure shown in Figure 12 is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0212] In one exemplary embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of the keyword search method provided in the embodiments of this application.
[0213] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the keyword search method provided in the embodiments of this application.
[0214] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the keyword search method provided in the embodiments of this application.
[0215] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0216] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0217] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0218] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A keyword search method, characterized in that, The method includes: constructing an initial prefix tree based on terms, where each node of the initial prefix tree corresponds to a prefix, the prefix consisting of the strings represented by each node on the path from the root node to the node and the string represented by the node itself, and the nodes with the same prefix as the terms recording the terms; for each non-leaf node, selecting at most a target number of terms from the terms recorded by the nodes on the path from the non-leaf node to the leaf node according to the term weight score, constructing a heap structure corresponding to the non-leaf node based on the target number of terms, the target number being the number of associated words required in the search scenario; when the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, merging the non-leaf node with its child nodes to obtain a target prefix tree, the target prefix tree being used to traverse the target node matching the keyword in the search scenario, and determining the terms from the heap structure corresponding to the target node as associated words of the keyword.
2. The method according to claim 1, characterized in that, The step of constructing an initial prefix tree based on terms includes: obtaining a term library for matching keywords; for each term in the term library, generating a corresponding encoding string according to a preset encoding format, wherein the encoding string and the term form a key-value pair; the preset encoding format includes at least one of Chinese character conversion, Pinyin conversion, abbreviated Pinyin conversion, similar character conversion, and case conversion; and constructing an initial prefix tree based on each key-value pair.
3. The method according to claim 1, characterized in that, The method of constructing an initial prefix tree based on terms includes: determining at least one encoding string corresponding to each term; for each encoding string, starting from the first character of the encoding string, traversing from the root node to the child nodes; when there is a child node representing the currently traversed character, the child node is used as the new current node; when there is no child node representing the currently traversed character, a new child node is created based on the currently traversed character as the new current node; obtaining the next character of the encoding string as the new current traversed character, traversing to the child nodes of the new current node, and returning to the step of using the child node representing the currently traversed character as the new current node when there is one, and creating a new child node based on the currently traversed character as the new current node when there is no child node representing the currently traversed character, until the new current traversed character is the last character of the encoding string, and ending the traversal; marking the child node representing the currently traversed character as a leaf node, and recording the term corresponding to the encoding string on the leaf node.
4. The method according to claim 3, characterized in that, The method further includes: determining the number of child nodes of a parent node in the initial prefix tree; and merging the parent node with the child node when the number of child nodes is 1.
5. The method according to claim 1, characterized in that, The nodes record the terms and their weight scores corresponding to the prefixes. For each non-leaf node, from the terms recorded on the path from the non-leaf node to the leaf node, at most a target number of terms are selected according to their weight scores. A heap structure corresponding to the non-leaf node is constructed based on the target number of terms. This includes: for each non-leaf node in the initial prefix tree, determining at least one leaf node that the non-leaf node leads to; obtaining the terms recorded on each of the at least one leaf node; selecting at most a target number of terms from the terms according to their weight scores; constructing a min-heap corresponding to the non-leaf node based on the target number of terms, where each node in the min-heap represents one of the terms in the target number, and the term weight score of the term represented by the root node of the min-heap is the smallest among the terms in the target number.
6. The method according to claim 1, characterized in that, The term weight score of the term is determined according to the following steps: obtaining the term search features of the term, the term search features including at least one of the term's historical search frequency and the term's historical click rate; determining the term weight score of the term based on the term search features of the term.
7. The method according to claim 1, characterized in that, When the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, the non-leaf node and its child nodes are merged to obtain the target prefix tree. This includes: when the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, merging the min-heap corresponding to the non-leaf node and the min-heap corresponding to the child nodes of the non-leaf node to obtain a merged min-heap, recording the merged min-heap on the non-leaf node, and deleting the child nodes of the non-leaf node to obtain the target prefix tree.
8. The method according to any one of claims 1 to 7, characterized in that, The method further includes: traversing the nodes of the target prefix tree, obtaining node information for each node, the node information including the prefix and heap structure corresponding to each node; and generating an offline index file based on the node information of each node.
9. The method according to claim 8, characterized in that, The node information also includes the number of child nodes for each node, and the method further includes: when constructing an online prefix tree based on the offline index file, reading the number of child nodes for each node in the offline index file, and allocating storage space based on the number of child nodes to construct the online prefix tree.
10. The method according to claim 8, characterized in that, The method further includes: reading the offline index file and extracting the node information of each node; constructing an online prefix tree based on the node information of each node, wherein the node information of each node in the online prefix tree includes the child node information corresponding to each node and a list of terms composed of ordered terms in the prefix and heap structure.
11. The method according to claim 10, characterized in that, The method further includes: obtaining keywords; traversing the online prefix tree based on the strings included in the keywords; determining the target node matching the keywords from the online prefix tree; and filtering associated words matching the keywords from the word list corresponding to the target node.
12. The method according to claim 11, characterized in that, The step of determining the target node matching the keyword from the online prefix tree includes: starting from the first character of the keyword, taking the root node of the online prefix tree as the current node, and traversing from the current node; when there is a child node representing the currently traversed character among the child nodes of the current node, then taking the child node as the new current node, obtaining the next character of the keyword as the new currently traversed character, traversing to the child nodes of the new current node, and returning to the step of taking the child node as the new current node when there is a child node representing the currently traversed character among the child nodes of the current node, until the execution ends when there is no child node representing the currently traversed character among the child nodes of the current node; when there is no child node representing the currently traversed character among the child nodes of the current node, the current node is taken as the target node matching the keyword.
13. The method according to claim 11, characterized in that, The step of filtering associated words that match the keyword from the word list corresponding to the target node includes: performing prefix matching on each word in the word list corresponding to the target node with the keyword, and using words with successful prefix matching as associated words that match the keyword; sorting the words with successful prefix matching according to their order in the word list and returning a list of associated words that match the keyword.
14. An index file construction apparatus, characterized in that, The device includes: an initial construction module, used to construct an initial prefix tree based on terms, wherein each node of the initial prefix tree corresponds to a prefix, the prefix being composed of the strings represented by each node on the path from the root node to the node and the string represented by the node itself, and the term being recorded on the node whose prefix is the same as the term; a heap structure construction module, used to, for each non-leaf node, filter out at most a target number of terms from the terms recorded on the path from the non-leaf node to the leaf node according to the term weight score, and construct a heap structure corresponding to the non-leaf node based on the target number of terms, wherein the target number is the number of associated words required in the search scenario; and a node merging module, used to, when the number of terms in the heap structure corresponding to the non-leaf node is less than the target number, merge the non-leaf node with its child nodes to obtain a target prefix tree, wherein the target prefix tree is used to traverse the target node that matches the keyword in the search scenario, and determine the terms from the heap structure corresponding to the target node as associated words of the keyword.
15. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 13.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 13.
17. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 13.