Text search method and device
By performing character conversion and distance calculation on the input keywords, determining the target keywords and performing text searches, the inefficiency and low accuracy problems caused by the complexity of regular expressions in the prior art are solved, and efficient and accurate text search is achieved.
Patent Information
- Application Number
- CN202411519801.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-25
AI Technical Summary
In the prior art, when text searches based on regular expressions, the syntax is complex, difficult to understand and use, resulting in low efficiency and accuracy.
By receiving keywords input by the client, character conversion is performed to generate a converted character sequence, obtain the candidate character sequence of candidate keywords, calculate the distance between the candidate character sequence and the converted character sequence, determine the target keyword and send the associated search text.
Improves the matching tolerance and accuracy of text searches, ensures the relevance and accuracy of search results, improves user experience and reduces waiting time.
Smart Images

Figure CN119513281A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet technology, and in particular to a text search method and device. Background Art
[0002] With the continuous development of the global economy and the improvement of the financial market, a large amount of text data is generated every day in the financial industry, such as financial statements, market analysis reports, financial news, policy documents, etc. These text data are not only huge in quantity, but also complex and changeable in content, containing a large amount of professional terms and key information. Practitioners in financial institutions need to quickly and accurately extract useful information from these text data to support core businesses such as decision-making, risk management, and investment decisions.
[0003] In the related art, text search is performed based on regular expressions, and text content related to the search terms is displayed; however, the syntax of regular expressions is relatively complex, containing a variety of special characters and metacharacters. The combination of these symbols is diverse, and it takes a lot of time and effort to learn and understand them, which reduces the efficiency and accuracy of text search. Summary of the invention
[0004] The present disclosure provides a text search method and device to solve one of the technical problems in the related art at least to a certain extent. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, a text search method is provided, comprising: receiving an input keyword sent by a client; performing character conversion on the input keyword to obtain a converted character sequence corresponding to the input keyword; obtaining a candidate character sequence obtained by performing character conversion on multiple candidate keywords in a keyword library; for any candidate character sequence, determining a distance between the any candidate character sequence and the converted character sequence; determining a target keyword from each of the candidate keywords based on the distance corresponding to each of the candidate character sequences, and sending a search text associated with the target keyword to the client.
[0006] According to a second aspect of an embodiment of the present disclosure, a text search device is provided, comprising: a receiving module for receiving an input keyword sent by a client; a conversion module for performing character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword; an acquisition module for obtaining a candidate character sequence obtained by performing character conversion on multiple candidate keywords in a keyword library; a first determination module for determining, for any candidate character sequence, the distance between the candidate character sequence and the conversion character sequence; and a second determination module for determining a target keyword from each of the candidate keywords based on the distance corresponding to each of the candidate character sequences, and sending a search text associated with the target keyword to the client.
[0007] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the text search method as described in the embodiment of the first aspect of the present disclosure.
[0008] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can execute the text search method as described in the embodiment of the first aspect of the present disclosure.
[0009] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including: a computer program, wherein when the computer program is executed by a processor, the text search method as described in the embodiment of the first aspect of the present disclosure is implemented.
[0010] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0011] In the technical scheme, by receiving the input keyword sent by the client, the input keyword is converted into a character to obtain a converted character sequence corresponding to the input keyword, thereby converting the input keyword into a standardized form, so as to better match the candidate keywords in the keyword library and improve the matching fault tolerance. Then, a candidate character sequence obtained by character conversion of multiple candidate keywords in the keyword library is obtained, and for any candidate character sequence, the distance between any candidate character sequence and the converted character sequence is determined. According to the distance corresponding to each candidate character sequence, a target keyword is determined from each candidate keyword, and a search text associated with the target keyword is sent to the client, so that the similarity between the input keyword and the candidate keyword is quantified by calculating the distance, the matching accuracy is improved, the most similar candidate keyword is selected as the target keyword, the relevance and accuracy of the search results are ensured, and the search results are returned to the client in a timely manner, thereby improving the user experience and reducing the waiting time of the user. In particular, when determining the distance between any candidate character sequence and the converted character sequence, by A character matrix is constructed to quantify the distance between characters, and a path search is performed between a set starting point and an end point. The distance between two character sequences is calculated based on the elements on at least one candidate regular path searched, thereby realizing dynamic planning of path search and improving the accuracy and efficiency of path search, thereby accurately determining the similarity between the candidate keyword and the input keyword, and improving the accuracy of text search; in addition, when performing character conversion on the input keyword to obtain a converted character sequence corresponding to the input keyword, any character in the input keyword is disassembled to obtain a disassembly result of any character; a coding sequence matching the disassembly result of any character is obtained; the coding sequence of each character is spliced according to the arrangement position of each character in the input keyword to obtain a converted character sequence corresponding to the input keyword, thereby realizing the decomposition of complex characters into more basic components, thereby considering more details in the matching process, improving the accuracy and precision of character matching, and better handling spelling errors and ambiguous input, improving the robustness and fault tolerance of the system.
[0012] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0014] Figure 1 is a flowchart of a text search method shown in the first embodiment of the present disclosure;
[0015] Figure 2is a flowchart of a text search method shown in the second embodiment of the present disclosure;
[0016] Figure 3 is a schematic diagram of a path search shown in an embodiment of the present disclosure;
[0017] Figure 4 is a flowchart of a text search method shown in the third embodiment of the present disclosure;
[0018] Figure 5 is a schematic diagram of character matrix initialization shown in an embodiment of the present disclosure;
[0019] Figure 6 is a schematic diagram of a character matrix including various elements shown in an embodiment of the present disclosure;
[0020] Figure 7 is a flowchart of a text search method shown in the fourth embodiment of the present disclosure;
[0021] Figure 8 It is a schematic diagram of the principle of the text search method shown in the embodiment of the present disclosure;
[0022] Fig. 9 is a structural schematic diagram of a text search device shown in the fifth embodiment of the present disclosure;
[0023] Fig.10 It is a schematic diagram of the structure of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0026] It should be noted that in the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, and are in compliance with relevant laws and regulations and do not violate public order and good morals.
[0027] In a related search system, users want the system to display information related to the search terms. In some search scenarios, users want the system to have a certain degree of intelligence and fault tolerance. Traditional approaches to this problem are generally based on regular expressions or keyword matching rules. For example, a regular expression is defined based on a matching text pattern, or a keyword list is converted into several regular expressions. For example, regular expressions include character sequences (such as "hello"), character classes (such as [az] for any lowercase letter), quantifiers (such as * for zero or more occurrences of the preceding element), boundary matching (such as ^ for the start of a line and $ for the end of a line), grouping (using brackets ()), and other special characters; for another example, in most programming languages, there are built-in regular expression engines or libraries that are used to search for text that matches a specific regular expression. The search usually returns a Boolean value (True / False) or a list (or iterator) containing all matches; for another example, regular expressions are used to verify whether text conforms to a specific format, such as an email address, phone number, URL, etc. By defining a regular expression that matches these specific formats, you can verify whether the text in the user input or system database meets the specific format.
[0028] However, since the syntax of regular expressions is relatively complex and contains a variety of special characters and metacharacters, the combination of these symbols is diverse, and it takes a lot of time and effort to learn and understand them. For non-professionals or beginners, the regular expression pattern may be difficult to understand intuitively. In addition, due to the high complexity and poor readability of regular expressions, when regular expressions need to be modified or maintained, it may become very difficult and easy to introduce new errors. Regular expression errors may not be easy to detect, and debugging and repairing regular expressions will take a lot of time. In addition, different regular expression engines may interpret and process certain special characters differently, which may cause the same regular expression to behave inconsistently in different environments, increasing the complexity of debugging and testing.
[0029] In view of the above problems, the present disclosure proposes a text search method and device.
[0030] The text search method and device according to the embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0031] Figure 1 It is a flowchart of the text search method shown in the first embodiment of the present disclosure.
[0032] like Figure 1 As shown, the text search method includes the following steps:
[0033] Step 101: receiving input keywords sent by a client.
[0034] To ensure the timeliness of text search, as an example, a user enters keywords on the client, and in response to the search operation, the keywords entered on the client are sent to a text search device (such as a search engine). The text search device receives the input keywords sent by the client and performs a text search.
[0035] Step 102: Perform character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword.
[0036] In order to improve the degree of text matching, as a possible implementation method, the input keywords are standardized to handle spelling errors and ambiguous inputs and improve the matching success rate.
[0037] As an example, a character conversion operation is performed on an input keyword to generate a standardized character sequence corresponding to the keyword, such as converting the keyword into pinyin, replacing homophones, converting simplified and traditional characters, and encoding the keyword according to specific rules (such as stroke order, glyph structure).
[0038] Step 103: Acquire a candidate character sequence obtained by performing character conversion on a plurality of candidate keywords in the keyword library.
[0039] In order to improve the efficiency of text search, as an example, character conversion is performed on candidate keywords in advance to obtain candidate character sequences of multiple candidate keywords. During text search, candidate character sequences corresponding to the multiple candidate keywords are directly obtained for matching.
[0040] Step 104: for any candidate character sequence, determine the distance between any candidate character sequence and the conversion character sequence.
[0041] In order to improve the accuracy of text search, as a possible implementation method, the similarity between any candidate character sequence and the converted character sequence is determined, and based on the similarity, a target keyword is determined from the candidate keywords, thereby determining the search text associated with the target keyword.
[0042] As an example, the similarity between the candidate character sequence and the conversion character sequence is quantified based on the distance between the candidate character sequence and the conversion character. Therefore, for each candidate character sequence, the distance between it and the conversion character sequence of the user input keyword is calculated. It should be noted that the smaller the distance, the higher the similarity between the two sequences.
[0043] Step 105 : determining a target keyword from the candidate keywords according to the distances corresponding to the candidate character sequences, and sending a search text associated with the target keyword to the client.
[0044] As a possible implementation manner, at least one candidate keyword whose distance is less than a set distance threshold is selected as the target keyword according to the calculated distance.
[0045] As an example, a target character sequence is determined from each candidate character sequence based on the distances corresponding to each candidate character sequence; wherein the distance corresponding to the target character sequence is less than a set distance threshold; and the candidate keyword corresponding to the target character sequence is used as the target keyword.
[0046] That is, according to the distance between the candidate character sequence and the conversion character sequence, one or more target character sequences whose distance is less than a preset distance threshold are selected from multiple candidate character sequences, and then the candidate keywords corresponding to the target character sequences are used as target keywords.
[0047] As another possible implementation, according to the calculated distance, a candidate keyword with the smallest distance is selected as the target keyword.
[0048] That is, according to the distance between the candidate character sequence and the conversion character sequence, one or more target character sequences with the smallest distance are selected from multiple candidate character sequences, and then the candidate keywords corresponding to the target character sequences are used as target keywords.
[0049] Then, the text search device retrieves search results related to the target keyword from the database or index, and sends the search results in text form to the client for the user to view and use.
[0050] In summary, by receiving the input keyword sent by the client, the input keyword is converted into a character to obtain a converted character sequence corresponding to the input keyword, and the input keyword is converted into a standardized form, so as to better match the candidate keywords in the keyword library and improve the matching fault tolerance. Then, the candidate character sequence obtained by character conversion of multiple candidate keywords in the keyword library is obtained, and for any candidate character sequence, the distance between any candidate character sequence and the converted character sequence is determined, and the target keyword is determined from each candidate keyword according to the distance corresponding to each candidate character sequence. The search text associated with the target keyword is sent to the client, and the similarity between the input keyword and the candidate keyword is quantified by calculating the distance, thereby improving the matching accuracy, selecting the most similar candidate keyword as the target keyword, ensuring the relevance and accuracy of the search results, and returning the search results to the client in a timely manner, thereby improving the user experience and reducing the user's waiting time.
[0051] In order to clearly explain how to determine the distance between any candidate character sequence and the conversion character sequence for any candidate character sequence in the above embodiment, the present disclosure proposes another text search method.
[0052] Figure 2 It is a flowchart of a text search method shown in the second embodiment of the present disclosure.
[0053] like Figure 2 As shown, the text search method includes the following steps:
[0054] Step 201: receiving input keywords sent by a client.
[0055] Step 202: Perform character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword.
[0056] Step 203: Acquire a candidate character sequence obtained by performing character conversion on a plurality of candidate keywords in the keyword library.
[0057] Step 204: Generate a character matrix according to the distance between any candidate character sequence and the characters in the conversion character sequence.
[0058] In order to accurately determine the distance between the candidate character sequence and the conversion character sequence, as a possible implementation method, a character matrix is constructed based on the distance between the characters in any candidate character sequence and the characters in the conversion character sequence, and the distance between the candidate character sequence and the conversion character sequence is determined based on the character matrix.
[0059] The distance between characters in the candidate character sequence and the conversion character sequence may be determined in the following two ways:
[0060] (1) In response to any two characters being numbers, the absolute value of the difference between any two characters is used as the distance between any two characters;
[0061] That is to say, when the characters in the candidate character sequence (such as the candidate keywords converted into the numerical sequence corresponding to the strokes) and the converted character sequence (the input keyword converted into the numerical sequence corresponding to the strokes) are all numbers, the absolute value of the difference between any two characters is taken as the distance between any two characters.
[0062] (2) In response to any two characters being letters, querying a letter distance table, wherein the letter distance table includes distances between a plurality of letters; and determining the distance between any two characters from the letter distance table.
[0063] That is to say, when the characters in the candidate character sequence (such as the candidate keyword converted to a pinyin sequence) and the conversion character sequence (the input keyword converted to a pinyin sequence) are all letters, the letter distance table is queried and the distance between any two characters is determined from the letter distance table.
[0064] Step 205, taking the element in the last row and first column of the character matrix as the starting point of the path search, and taking the element in the first row and last column of the character matrix as the end point of the path search.
[0065] In order to accurately determine the distance between the candidate character sequence and the conversion character sequence, as a possible implementation method, a path search is performed in the character matrix, and the shortest distance of the searched path is used as the distance between the candidate character sequence and the conversion character sequence. It should be noted that in order to realize the dynamic planning of the path, the path searched in the character matrix must meet the set boundary, continuity and monotonicity. The boundary is used to limit the starting point and end point of the path search, the continuity is used to indicate the step size of the path search, and the monotonicity is used to indicate the direction of the path search.
[0066] In the embodiment of the present disclosure, the starting point and the end point of the path search are first determined. To facilitate dynamic path planning, as an example, the lower left corner of the character matrix (i.e., the element in the last row and the first column) is used as the starting point of the path search, and the upper right corner of the character matrix (the element in the first row and the last column) is used as the end point of the path search.
[0067] Step 206 , performing a path search between the starting point and the end point to obtain at least one candidate regular path in the character matrix.
[0068] In order to improve the rationality and efficiency of the path search, as a possible implementation method, a path search is performed between a starting point and an end point based on a set path search direction and a set path search step size.
[0069] As an example, a set path search direction and a set path search step length are obtained; between a starting point and an end point, a path search is performed based on the set path search direction and the set path search step length to obtain at least one candidate regular path.
[0070] For example, Figure 3 As shown, the starting point of the path search is the lower left corner of the character matrix, the end point is the upper right corner of the character matrix, the step length of the path search is one grid, and the direction of the path search is upward, rightward, and diagonally to the upper right.
[0071] Step 207: Determine the distance between any candidate character sequence and the conversion character sequence according to the elements on each candidate regular path in the character matrix.
[0072] It should be understood that, since the elements on the candidate regular paths can intuitively show the matching relationship between characters, by comparing the elements on different candidate regular paths, the optimal path can be selected to ensure that the most similar candidate keywords are found.
[0073] As an example, the distances of each candidate regular path are determined based on the elements on each candidate regular path in the character matrix; based on the distances of each candidate regular path, a target regular path with the shortest distance is determined from among the candidate regular paths; and the distance of the target regular path is used as the distance between any candidate character sequence and the conversion character sequence.
[0074] That is to say, the elements on each candidate regular path are added to obtain the distance of each candidate regular path. By comparing the distances of each candidate regular path, the target regular path with the shortest distance can be determined from each candidate regular path, and the distance of the target regular path is used as the distance between any candidate character sequence and the conversion character sequence.
[0075] Step 208: determine a target keyword from the candidate keywords according to the distances corresponding to the candidate character sequences, and send a search text associated with the target keyword to the client.
[0076] It should be noted that the execution process of steps 201 to 203 and step 208 can be implemented in any way in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.
[0077] In summary, a character matrix is generated according to the distance between characters in any candidate character sequence and the conversion character sequence; the elements in the first column of the last row in the character matrix are used as the starting point of the path search, and the elements in the last column of the first row of the character matrix are used as the end point of the path search; a path search is performed between the starting point and the end point to obtain at least one candidate regular path in the character matrix; the distance between any candidate character sequence and the conversion character sequence is determined according to the elements on each candidate regular path in the character matrix. Thus, by constructing a character matrix to quantify the distance between characters and performing a path search between the set starting point and end point, dynamic planning of the path search is realized, and the accuracy and efficiency of the path search are improved. The distance between the two character sequences is calculated based on the elements on at least one searched candidate regular path, and the similarity between the candidate keyword and the input keyword is accurately determined, thereby improving the accuracy of text search.
[0078] Based on any of the above embodiments, a character matrix is generated based on the distance between any candidate character sequence and the characters in the conversion character sequence. Figure 4 The embodiments are described in detail.
[0079] Figure 4 It is a flowchart of a text search method shown in the third embodiment of the present disclosure.
[0080] like Figure 4 As shown, the text search method includes the following steps:
[0081] Step 401, determining the first column of the character matrix according to each character in one of the candidate character sequence and the conversion character sequence.
[0082] In order to achieve high efficiency and accuracy in path search, as a possible implementation method, a character matrix is initialized based on each character in any candidate character sequence and conversion character sequence.
[0083] As an example, the first column of the character matrix is generated based on each character in one of the candidate character sequences and the converted character sequences.
[0084] Step 402: Determine the nth row of the character matrix according to each character in the other sequence of any candidate character sequence and the conversion character sequence.
[0085] As an example, based on each character in another sequence of any candidate character sequence and the converted character sequence, an n-th row of the character matrix is generated.
[0086] For example, if any candidate character sequence is [2,1,5], the conversion character sequence is [5,2,1,9], such as Figure 5 As shown, the first column of the character matrix is determined according to each element in the conversion character sequence, and the last row (ie, the nth row) of the character matrix is determined according to each element in any candidate character sequence.
[0087] Step 403, determining the element in the i-th row and j-th column in the character matrix according to the distance between the element in the i-th row and the 1st column and the element in the n-th row and the j-th column in the character matrix.
[0088] Wherein, i is a positive integer less than n, and j is a positive integer greater than 1 and less than or equal to m.
[0089] For example, continuing with Figure 5 Take the character matrix in as an example, for other elements in the character matrix, such as Figure 6 As shown, the element in the i-th row and i-th column is determined based on the distance between the element in the i-th row and 1-th column and the element in the n-th row and j-th column in the character matrix. For example, i=1, j=2, the element in the 1st row and 2nd column is the absolute value of the difference between the element in the 1st row and 1st column (i.e., 9) and the element in the 5th row and 2nd column (i.e., 2).
[0090] It should be noted that the elements of the lower corners of the character matrix can be preset.
[0091] In summary, according to each character in one of the candidate character sequences and the conversion character sequence, the first column of the character matrix is determined; according to each character in the other of the candidate character sequence and the conversion character sequence, the nth row of the character matrix is determined; according to the distance between the element in the i-th row and the first column of the character matrix and the element in the n-th row and the j-th column of the character matrix, the element in the i-th row and the j-th column of the character matrix is determined. Thus, the construction of the character matrix takes into account both the character correspondence between sequences and the distance information between characters, effectively reflects the similarity between the two character sequences, and thus facilitates the determination of the similarity between the subsequent candidate character sequence and the conversion character sequence.
[0092] In order to clearly explain how to perform character conversion on the input keyword in the above embodiment to obtain a conversion character sequence corresponding to the input keyword, the present disclosure proposes another text search method.
[0093] Figure 7 It is a flowchart of a text search method shown in the fourth embodiment of the present disclosure.
[0094] like Figure 7 As shown, the text search method includes the following steps:
[0095] Step 701: receiving input keywords sent by the client.
[0096] Step 702: Decompose any character in the input keyword to obtain a decomposition result of the character.
[0097] In order to improve the accuracy of text matching, as an example, any character in the input keyword is decomposed into strokes to obtain a stroke decomposition result of any character.
[0098] As another example, the input keyword is converted into characters to obtain a conversion character sequence of the input keyword in a specified language. For example, the input keyword is "bingguan" (for example, in some regional dialects or input errors, "hotel" is mistakenly entered as "bingguan"), and the character conversion of "bingguan" is performed to obtain the Chinese pinyin of "bingguan", and "bingguan" is used as the conversion character sequence of "bingguan".
[0099] It should be noted that for the conversion character sequence "bingguan", there is no exactly identical sequence in the candidate character sequences corresponding to the candidate keywords in the keywords. The distance between it and the candidate character sequence "binguan" is 1, which is less than the set distance threshold. Then, content related to the target keyword "hotel" corresponding to "binguan" is returned to the client. Therefore, converting the input keyword into a standardized form to better match the candidate keywords in the keyword library can not only handle common spelling mistakes but also recognize the user's fuzzy input, thus significantly improving the success rate and accuracy of keyword matching.
[0100] Step 703: Obtain the coding sequence that matches the disassembled result of any character.
[0101] As an example, each stroke corresponds to a code. For instance, "1" represents the "horizontal" and "rising stroke" in Chinese character strokes, "2" represents the "vertical" and "vertical hook" in Chinese character strokes, and "3" represents the "left-falling stroke" in Chinese character strokes. According to the disassembled result of any character, by querying the coding table, the coding sequence that matches the disassembled result can be obtained. Among them, the coding table includes the codes corresponding to each stroke.
[0102] Step 704: Concatenate the coding sequences of each character according to the arrangement position of each character in the input keyword to obtain the conversion character sequence corresponding to the input keyword.
[0103] It should be understood that since each character in the input keyword has a corresponding arrangement position in the input keyword. For example, if the input keyword is "text", the arrangement position of the character "文" in the input keyword is 1, and the arrangement position of the character "本" in the input keyword is 2.
[0104] Therefore, in order to accurately determine the conversion character sequence corresponding to the input keyword, based on the arrangement position of each character in the input keyword, the coding sequences of each character are concatenated to obtain the conversion character sequence corresponding to the input keyword.
[0105] Step 705: Obtain the candidate character sequences obtained by character conversion of multiple candidate keywords in the keyword library.
[0106] Step 706: For any candidate character sequence, determine the distance between any candidate character sequence and the conversion character sequence.
[0107] Step 707: Determine the target keyword from each candidate keyword according to the distances corresponding to each candidate character sequence, and send the search text associated with the target keyword to the client.
[0108] It should be noted that the execution process of step 701 and steps 705 to 707 can be implemented in any way in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.
[0109] In summary, for any character in the input keyword, any character is disassembled to obtain the disassembly result of any character; a coding sequence matching the disassembly result of any character is obtained; according to the arrangement position of each character in the input keyword, the coding sequence of each character is spliced to obtain the conversion character sequence corresponding to the input keyword, thereby decomposing complex characters into more basic components, so that more details can be considered in the matching process, the accuracy and precision of character matching can be improved, and spelling errors and ambiguous input can be better handled, thereby improving the robustness and fault tolerance of the system.
[0110] Based on any embodiment of the present disclosure, Figure 8 As shown, the text search method of the embodiment of the present disclosure can also be implemented based on the following steps:
[0111] 1. Receive input search terms (input keywords) sent by the client;
[0112] 2. Perform character conversion on the input search term to obtain a conversion character sequence;
[0113] 3. Obtain n keywords from the keyword database, and perform character conversion on the n keywords to obtain n candidate character sequences; it should be noted that the character conversion method in step 3 is the same as that in step 2. For example, in step 2, the input search term is converted into pinyin, and in step 3, the n keywords are also converted into pinyin;
[0114] 4. Based on the conversion character sequence and the candidate character sequence, a character matrix is constructed, and based on the character matrix, the distance between the conversion character sequence and the n candidate character sequences is calculated;
[0115] 5. Determine whether there is a distance less than a set distance threshold among the n distances, and output the relevant text of the keyword among the keywords corresponding to the distance less than the set distance threshold.
[0116] Corresponding to the text search method provided in the above-mentioned embodiment, the present disclosure also provides a text search device. Since the text search device provided in the embodiment of the present disclosure corresponds to the text search method provided in the above-mentioned embodiment, the implementation method of the text search method is also applicable to the text search device provided in the embodiment of the present disclosure, and will not be described in detail in the embodiment of the present disclosure.
[0117] Fig. 9 It is a structural diagram of a text search device shown in the fifth embodiment of the present disclosure.
[0118] like Fig. 9 As shown, the text search device 900 includes: a receiving module 910 , a conversion module 920 , an acquisition module 930 , a first determination module 940 and a second determination module 950 .
[0119] Among them, the receiving module 910 is used to receive the input keyword sent by the client; the conversion module 920 is used to perform character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword; the acquisition module 930 is used to obtain a candidate character sequence obtained by performing character conversion on multiple candidate keywords in the keyword library; the first determination module 940 is used to determine the distance between any candidate character sequence and the conversion character sequence for any candidate character sequence; the second determination module 950 is used to determine the target keyword from each candidate keyword according to the distance corresponding to each candidate character sequence, and send the search text associated with the target keyword to the client.
[0120] As a possible implementation method of an embodiment of the present disclosure, the first determination module 940 is used to generate a character matrix based on the distance between characters in any candidate character sequence and the conversion character sequence; use the elements in the last row and first column of the character matrix as the starting point of the path search, and use the elements in the first row and last column of the character matrix as the end point of the path search; perform a path search between the starting point and the end point to obtain at least one candidate regular path in the character matrix; determine the distance between any candidate character sequence and the conversion character sequence based on the elements on each candidate regular path in the character matrix.
[0121] As a possible implementation manner of the embodiment of the present disclosure, the distance between any two characters is determined by the following modules: a third determination module.
[0122] Among them, the third determination module is used to respond to any two characters being numbers, use the absolute value of the difference between any two characters as the distance between any two characters; respond to any two characters being letters, query the letter distance table; wherein the letter distance table includes the distances between multiple letters; and determine the distance between any two characters from the letter distance table.
[0123] As a possible implementation method of the embodiment of the present disclosure, the first determination module 940 is used to determine the distance of each candidate regular path based on the elements on each candidate regular path in the character matrix; determine the target regular path with the shortest distance from each candidate regular path based on the distance of each candidate regular path; and use the distance of the target regular path as the distance between any candidate character sequence and the conversion character sequence.
[0124] As a possible implementation method of the embodiment of the present disclosure, the character matrix is an n*m matrix, and the first determination module 940 is used to determine the first column of the character matrix according to each character in one of the candidate character sequences and the conversion character sequence; determine the nth row of the character matrix according to each character in the other of the candidate character sequences and the conversion character sequence; determine the element in the i-th row and j-th column of the character matrix according to the distance between the element in the i-th row and the first column of the character matrix and the element in the n-th row and the j-th column; wherein i is a positive integer less than n, and j is a positive integer greater than 1 and less than or equal to m.
[0125] As a possible implementation method of the embodiment of the present disclosure, the first determination module 940 is used to obtain a set path search direction and a set path search step; between the starting point and the end point, a path search is performed based on the set path search direction and the set path search step to obtain at least one candidate regular path.
[0126] As a possible implementation method of the embodiment of the present disclosure, the second determination module 950 is used to determine a target character sequence from each candidate character sequence based on the distance corresponding to each candidate character sequence; wherein the distance corresponding to the target character sequence is less than a set distance threshold; and the candidate keyword corresponding to the target character sequence is used as the target keyword.
[0127] As a possible implementation method of the embodiment of the present disclosure, the conversion module 920 is used to disassemble any character in the input keyword to obtain the disassembly result of any character; obtain a coding sequence that matches the disassembly result of any character; and splice the coding sequence of each character according to the arrangement position of each character in the input keyword to obtain a conversion character sequence corresponding to the input keyword.
[0128] As a possible implementation of the embodiment of the present disclosure, the conversion module 920 is used to perform character conversion on the input keyword to obtain a converted character sequence of the input keyword in a specified language.
[0129] The text search device of the disclosed embodiment receives input keywords sent by a client, performs character conversion on the input keywords to obtain a conversion character sequence corresponding to the input keywords, and realizes conversion of the input keywords into a standardized form, so as to better match candidate keywords in a keyword library and improve matching fault tolerance. Then, a candidate character sequence obtained by performing character conversion on multiple candidate keywords in the keyword library is obtained, and for any candidate character sequence, the distance between any candidate character sequence and the conversion character sequence is determined, and a target keyword is determined from each candidate keyword according to the distance corresponding to each candidate character sequence, and a search text associated with the target keyword is sent to the client, so that the similarity between the input keyword and the candidate keyword is quantified by calculating the distance, the matching accuracy is improved, the most similar candidate keyword is selected as the target keyword, the relevance and accuracy of the search results are ensured, and the search results are returned to the client in a timely manner, thereby improving the user experience and reducing the waiting time of the user.
[0130] In an exemplary embodiment, an electronic device is also provided.
[0131] Among them, electronic equipment includes:
[0132] processor;
[0133] a memory for storing processor-executable instructions;
[0134] The processor is configured to execute instructions to implement the text search method proposed in any of the aforementioned embodiments.
[0135] As an example, Fig.10 is a schematic diagram of the structure of an electronic device 1000 shown in an exemplary embodiment of the present disclosure, such as Fig.10 As shown, the electronic device 1000 may further include:
[0136] The memory 1010 and the processor 1020, and the bus 1030 connecting different components (including the memory 1010 and the processor 1020), the memory 1010 stores a computer program, and when the processor 1020 executes the program, the text search method described in the embodiment of the present disclosure is implemented.
[0137] Bus 1030 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0138] The electronic device 1000 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 1000, including volatile and non-volatile media, removable and non-removable media.
[0139] The memory 1010 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 1040 and / or cache memory 1050. The server 1000 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 1060 may be used to read and write non-removable, non-volatile magnetic media ( Fig.10 not shown, usually called a "hard drive"). Although Fig.10 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 1030 via one or more data medium interfaces. The memory 1010 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.
[0140] A program / utility 1080 having a set (at least one) of program modules 1070 may be stored, for example, in the memory 1010, such program modules 1070 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 1070 generally perform the functions and / or methods of the embodiments described in the present disclosure.
[0141] The electronic device 1000 may also communicate with one or more external devices 1090 (e.g., keyboard, pointing device, display 1091, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1000, and / or communicate with any device that enables the electronic device 1000 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 1092. In addition, the electronic device 1000 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 1093. As shown, the network adapter 1093 communicates with other modules of the electronic device 1000 through a bus 1030. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1000, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0142] The processor 1020 executes various functional applications and data processing by running the programs stored in the memory 1010 .
[0143] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the text search method of the embodiment of the present disclosure, and will not be repeated here.
[0144] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of an electronic device to complete the text search method proposed in any of the above embodiments. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0145] In an exemplary embodiment, a computer program product is also provided, including a computer program / instruction, wherein the computer program / instruction implements the text search method proposed in any of the above embodiments when executed by a processor.
[0146] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0147] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A text search method, characterized in that: include: Receive input keywords sent by the client; Performing character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword; Obtaining a candidate character sequence obtained by performing character conversion on a plurality of candidate keywords in the keyword library; For any candidate character sequence, determining the distance between the any candidate character sequence and the conversion character sequence; According to the distances corresponding to the candidate character sequences, a target keyword is determined from the candidate keywords, and a search text associated with the target keyword is sent to the client.
2. The method according to claim 1, characterized in that The step of determining the distance between any candidate character sequence and the conversion character sequence for any candidate character sequence includes: Generate a character matrix according to the distance between any candidate character sequence and the characters in the conversion character sequence; The element in the last row and the first column of the character matrix is used as the starting point of the path search, and the element in the first row and the last column of the character matrix is used as the end point of the path search; Performing a path search between the starting point and the end point to obtain at least one candidate regular path in the character matrix; The distance between any candidate character sequence and the conversion character sequence is determined according to the elements on each candidate regular path in the character matrix.
3. The method according to claim 2, characterized in that The distance between any two characters is determined using the following steps: In response to the arbitrary two characters being numbers, taking the absolute value of the difference between the arbitrary two characters as the distance between the arbitrary two characters; In response to any two characters being letters, querying a letter distance table; wherein the letter distance table includes distances between a plurality of letters; From the letter distance table, determine the distance between any two characters.
4. The method according to claim 2, characterized in that: The determining, according to the elements on each of the candidate regular paths in the character matrix, the distance between any candidate character sequence and the conversion character sequence comprises: Determining the distance of each candidate regular path according to the elements on each candidate regular path in the character matrix; According to the distances of the candidate regular paths, determine the target regular path with the shortest distance from the candidate regular paths; The distance of the target regularized path is used as the distance between any candidate character sequence and the conversion character sequence.
5. The method according to claim 2, characterized in that: The character matrix is an n*m matrix; The step of generating a character matrix according to the distances between characters in any candidate character sequence and the converted character sequence comprises: Determine the first column of the character matrix according to each character in one of the candidate character sequences and the conversion character sequences; Determine the nth row of the character matrix according to each character in the other sequence of any candidate character sequence and the conversion character sequence; Determine the element in the i-th row and j-th column of the character matrix according to the distance between the element in the i-th row and the 1st column and the element in the n-th row and the j-th column of the character matrix; wherein i is a positive integer less than n, and j is a positive integer greater than 1 and less than or equal to m.
6. The method according to claim 2, characterized in that The performing a path search between the starting point and the end point to obtain at least one candidate regular path in the character matrix includes: Get the set path search direction and set path search step size; Between the starting point and the end point, a path search is performed based on the set path search direction and the set path search step length to obtain the at least one candidate regular path.
7. The method according to claim 1, characterized in that Determining the target keyword from each of the candidate keywords according to the distances corresponding to each of the candidate character sequences includes: Determine a target character sequence from each of the candidate character sequences according to the distances corresponding to each of the candidate character sequences; wherein the distance corresponding to the target character sequence is less than a set distance threshold; The candidate keyword corresponding to the target character sequence is used as the target keyword.
8. The method according to claim 1, characterized in that The performing character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword includes: For any character in the input keyword, decompose the any character to obtain a decomposition result of the any character; Obtaining a coding sequence that matches the decomposition result of any of the characters; According to the arrangement position of each character in the input keyword, the encoding sequence of each character is spliced to obtain a conversion character sequence corresponding to the input keyword.
9. The method according to claim 1, characterized in that: The performing character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword includes: The input keyword is subjected to character conversion to obtain a conversion character sequence of the input keyword in a specified language.
10. A text search device, characterized in that: include: A receiving module, used to receive input keywords sent by the client; A conversion module, used for performing character conversion on the input keyword to obtain a conversion character sequence corresponding to the input keyword; An acquisition module, used for acquiring a candidate character sequence obtained by performing character conversion on a plurality of candidate keywords in a keyword library; A first determination module, configured to determine, for any candidate character sequence, a distance between the candidate character sequence and the conversion character sequence; The second determination module is used to determine a target keyword from each of the candidate keywords according to the distances corresponding to each of the candidate character sequences, and send a search text associated with the target keyword to the client.