A search keyword rewriting method, device, equipment and storage medium
By automatically rewriting search keywords through MyBatis interceptors and configuration tables, the high development cost and omissions in modifications of existing technologies are solved, achieving efficient keyword rewriting and avoiding direct modification of SQL statements and intrusion into business logic.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2026-03-31
AI Technical Summary
Existing technologies require manual coding when rewriting search keywords, resulting in high development costs, easy omissions during modification, and a lack of elegance, especially when modifying existing systems.
This approach utilizes MyBatis interceptors to intercept and parse Structured Query Language (SQL) statements. By automatically rewriting keywords through configuration tables and remote dictionary services, it avoids directly modifying SQL statements. The MyBatis interceptor intercepts SQL statements, parses table names and condition types, and performs automatic replacement using preset configuration tables and arrays of replaceable words.
It reduces the need for developers to directly modify SQL statements, improves development efficiency, avoids program errors, and reduces intrusion into business logic code.
Smart Images

Figure CN117171207B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for rewriting search keywords. Background Technology
[0002] In search implementation, it's often necessary to rewrite search keywords to help users better understand the search function. For example, when a user searches for "power bank," records in the database containing both "power bank" and "charger" should match the user's search query. However, there are also scenarios where incorrect keyword replacements are needed. For instance, if a user enters "InterContinental Hotel," the actual search should replace it with "InterContinental Grand Hotel." Furthermore, users may save different data in the database; some might save "power bank," while others might save "charger." In existing solutions, keyword rewriting typically requires developers to manually write code for keyword replacement. Implementing keyword replacement in code, along with related SQL (Structured Query Language), is cumbersome and inelegant. Especially when modifying an existing system, every query line of code needs to be modified, resulting in significant costs. Additionally, it's easy to miss changes, causing online issues. Therefore, how to automatically rewrite database keywords without modifying SQL statements is a pressing problem to be solved. Summary of the Invention
[0003] In view of this, the purpose of this invention is to provide a method, apparatus, device, and storage medium for rewriting search keywords, which eliminates the need to explicitly call the search keyword replacement configuration and modify the SQL when writing SQL, thereby accelerating development efficiency and reducing unnecessary program errors caused by processing omissions. The specific solution is as follows:
[0004] Firstly, this application discloses a method for rewriting search keywords, including:
[0005] The MyBatis interceptor is used to intercept and obtain the Structured Query Language (SCL) statement, the SCL statement is parsed to obtain the corresponding parsing result, and the table name of the preset configuration table corresponding to the SCL statement is obtained based on the parsing result.
[0006] Obtain all target condition statements corresponding to the structured query language statement from the parsing results, and traverse the target condition statements to obtain the condition type corresponding to the target condition statement;
[0007] Determine whether the condition type is a Like type. If the condition type is a Like type, obtain the preset column name corresponding to the target condition statement based on the target condition statement, and determine whether the structured query language statement needs to be rewritten based on the table name and the preset column name.
[0008] If rewriting is required, a replaceable word array is obtained based on the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement;
[0009] Determine whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, iterate through the replaceable word array to form a new conditional statement, and use the new conditional statement to replace the target conditional statement to complete the keyword rewriting.
[0010] Optionally, before intercepting and obtaining the Structured Query Language statement using the MyBatis interceptor, the method further includes:
[0011] Create a configuration table, and configure the table name, a first preset number of column names, the replacement type corresponding to each column, the explanation for each column, and a second preset number of replaceable words for the configuration table.
[0012] Optionally, after creating the configuration table, the following steps are also included:
[0013] When the system starts, it reads the data from the configuration table and caches the data in a Map based on the distributed caching method corresponding to the remote dictionary service.
[0014] Optionally, obtaining the array of replaceable words based on the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement includes:
[0015] The table name, the preset column name, and the value of the target condition statement determined based on the target condition statement are concatenated to obtain the target string;
[0016] The target string is identified as a keyword, and the value corresponding to the keyword is obtained by calling the remote dictionary service, so as to determine the array of replaceable words based on the value corresponding to the keyword.
[0017] Optionally, the step of intercepting and obtaining the Structured Query Language statement using the MyBatis interceptor includes:
[0018] Create a target class that implements the Interceptor interface of the MyBatis interceptor, and add a target annotation to the target class so that the interception object of the MyBatis interceptor can be determined based on the target annotation;
[0019] The Interceptor interception interface and the interception object are used to intercept and obtain structured query language statements.
[0020] Optionally, after determining whether the condition type is a Like type, the method further includes:
[0021] If the condition type is not Like, the process ends directly.
[0022] Optionally, after determining whether the structured query language statement needs to be rewritten based on the table name and the preset column names, the method further includes:
[0023] If no rewriting of the structured query language statement is required, the process can be terminated directly.
[0024] Optionally, after determining whether the replaceable word array exists in the preset configuration table, the method further includes:
[0025] If the array of replaceable words does not exist in the preset configuration table, the process ends directly.
[0026] Secondly, this application discloses a search keyword rewriting device, comprising:
[0027] The parsing result acquisition module is used to intercept and acquire structured query language statements using MyBatis interceptors, parse the structured query language statements, and obtain the corresponding parsing results;
[0028] The table name acquisition module is used to obtain the table name of the preset configuration table corresponding to the structured query language statement based on the parsing result;
[0029] The condition type acquisition module is used to obtain all target condition statements corresponding to the structured query language statement from the parsing result, and to traverse the target condition statements to obtain the condition type corresponding to the target condition statement.
[0030] The first judgment module is used to determine whether the condition type is a Like type. If the condition type is a Like type, then the preset column name corresponding to the target condition statement is obtained based on the target condition statement.
[0031] The second judgment module is used to determine whether the structured query language statement needs to be rewritten based on the table name and the preset column name;
[0032] The replaceable word array acquisition module is used to acquire a replaceable word array based on the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement if rewriting is required.
[0033] The third judgment module is used to determine whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, the replaceable word array is traversed to form a new conditional statement, and the new conditional statement is used to replace the target conditional statement to complete the keyword rewriting.
[0034] Thirdly, this application discloses an electronic device, including:
[0035] Memory, used to store computer programs;
[0036] A processor is used to execute the computer program to implement the aforementioned search keyword rewriting method.
[0037] Fourthly, this application discloses a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the aforementioned method for rewriting search keywords.
[0038] When rewriting search keywords, this application first uses a MyBatis interceptor to intercept and obtain Structured Query Language (SCL) statements, parses the SCL statements to obtain corresponding parsing results, and obtains the table name of the preset configuration table corresponding to the SCL statements based on the parsing results; it then obtains all target condition statements corresponding to the SCL statements from the parsing results, and iterates through the target condition statements to obtain the condition types corresponding to the target condition statements; finally, it determines whether the condition type is a Like type. If the condition type is a Like type, then based on the target... The method retrieves the preset column names corresponding to the target condition statement based on the table name and the preset column names, and determines whether the structured query language statement needs to be rewritten. If rewriting is required, a replaceable word array is obtained based on the table name, the preset column names, and the value of the target condition statement determined by the target condition statement. Finally, it checks whether the replaceable word array exists in the preset configuration table. If it does, the replaceable word array is traversed to form a new condition statement, which is then used to replace the target condition statement, thus completing the keyword rewriting. Therefore, this application intercepts and modifies structured query language statements during execution using replaceable keyword configuration and MyBatis interceptors. The interceptor searches for keyword replacement configurations and modifies the corresponding structured query language statements. This eliminates the need for developers to explicitly call keyword replacement configurations and modify structured query language statements when writing them, accelerating development efficiency and reducing unnecessary program errors caused by oversights. Furthermore, the rewriting is achieved through configuration, eliminating the need for additional development work. It can avoid intrusion into business logic code and eliminates the need for developers to manually handle and rewrite logic. Attached Figure Description
[0039] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0040] Figure 1 This is a flowchart of a search keyword rewriting method disclosed in this application;
[0041] Figure 2 This application discloses a flowchart of a specific method for rewriting search keywords.
[0042] Figure 3This is a schematic diagram of a search keyword rewriting device disclosed in this application;
[0043] Figure 4 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0044] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0045] Common solutions involve retrieving replacement keywords and executing related SQL statements within the code, which is cumbersome and inelegant. Especially when modifying an existing system, every query requires modification, resulting in significant costs. Furthermore, omissions in modifications can easily occur, leading to online issues and program errors. To address these technical problems, this application discloses a search keyword rewriting method that automatically rewrites database keywords without altering the SQL statements by leveraging search term configuration and MyBatis interception technology.
[0046] See Figure 1 As shown in the figure, an embodiment of the present invention discloses a method for rewriting search keywords, including:
[0047] Step S11: Intercept and obtain the Structured Query Language (SCL) statement using the MyBatis interceptor, parse the SCL statement to obtain the corresponding parsing result, and obtain the table name of the preset configuration table corresponding to the SCL statement based on the parsing result.
[0048] In this embodiment, before intercepting and obtaining the Structured Query Language (SCL) statement using the MyBatis interceptor, a configuration table needs to be created. This configuration table needs to be configured with the table name, a first preset number of column names, the replacement type corresponding to each column, an explanation of each column, and a second preset number of replaceable words. MyBatis is an excellent persistence layer framework that supports custom SQL, stored procedures, and advanced mappings. In the internet era, MyBatis has become the preferred framework for persistence layers in current internet Java development. That is, the replaceable words first need to be configured, including which tables and fields to target, the words that can be substituted for each other, and the corresponding replacement types (synonyms, error words, etc.). The configuration table needs to be created as follows:
[0049] Table 1
[0050] Column names illustrate type Example ...... ...... ...... ...... table The table name that needs to be rewritten varchar xx_article column Column names that need to be rewritten varchar content keywords Alternative words (comma-separated) varchar Haircut type type varchar Synonyms ...... ...... ...... ......
[0051] At the same time, when the system starts, it reads the data in the configuration table and caches the data in a Map based on the distributed caching method corresponding to the remote dictionary service.
[0052] Next, a target class is created that implements the `Interceptor` interface of the MyBatis interceptor, and a target annotation is added to the target class to determine the interception object of the MyBatis interceptor based on the target annotation. The Structured Query Language (SQL) statement is then intercepted and obtained based on the `Interceptor` interface and the interception object. Specifically, a `RewriteInterceptor` class is defined for intercepting query SQL; this class needs to implement the MyBatis `Interceptor` interface. The `@Intercepts` annotation is added to this class to declare that this interceptor applies to "Select" statements. Then, the current SQL statement is obtained from the parameters of the interception method.
[0053] Object[]args=invocation.getArgs();
[0054] BoundSql boundSql=(BoundSql)args[5];
[0055] String sql=boundSql.getSql().
[0056] Next, the structured query language statement is parsed to obtain the corresponding parsing result, and the table name of the preset configuration table corresponding to the structured query language statement is obtained based on the parsing result.
[0057] It involves parsing the SQL statement to obtain the SQLStatement:
[0058] DbType dbType=JdbcConstants.MYSQL;
[0059] List <sqlstatement>statementList=SQLUtils.parseStatements(sql,dbType);
[0060] SQLStatement sqlStatement=statementList.get(0).
[0061] Retrieve the table name corresponding to the SQL statement from SQLStatement:
[0062] MySqlSchemaStatVisitor visitor=new MySqlSchemaStatVisitor();
[0063] sqlStatement.accept(visitor);
[0064] Map<TableStat.Name,TableStat> tables=visitor.getTables();
[0065] Set<TableStat.Name> tableNameSet=tables.keySet();
[0066] for(TableStat.Name name:tableNameSet){
[0067] String tableName=name.getName();
[0068] }
[0069] Step S12: Obtain all target condition statements corresponding to the structured query language statement from the parsing result, and traverse the target condition statements to obtain the condition type corresponding to the target condition statement.
[0070] In this embodiment, after obtaining the parsing result, all target condition statements corresponding to the structured query language statement can be obtained from the parsing result, and the target condition statements can be traversed to obtain the condition type corresponding to the target condition statement. Specifically, all Conditions are obtained from the visitor, and the Conditions are traversed:
[0071] List<TableStat.Condition> conditions=visitor.getConditions();
[0072] for(Condition condition:conditions){
[0073] / / Iterate through and process each Condition
[0074] };
[0075] Therefore, you can call condition.getOperator() to get the condition type.
[0076] Step S13: Determine whether the condition type is a Like type. If the condition type is a Like type, obtain the preset column name corresponding to the target condition statement based on the target condition statement, and determine whether the structured query language statement needs to be rewritten based on the table name and the preset column name.
[0077] In this embodiment, it is necessary to determine whether the condition type is a Like type. If it is not Like, the subsequent steps are skipped and the process ends directly. If the condition type is Like type, the preset column name corresponding to the target condition statement is obtained based on the target condition statement. This requires calling condition.getColumn().getName() to obtain the corresponding column name. Then, based on the table name and the preset column name, it is determined whether the Structured Query Language statement needs to be rewritten. This involves concatenating the key after obtaining the column name, in the format {table}_{column}; indicating that this column in this table needs to be replaced.
[0078] Step S14: If rewriting is required, obtain an array of replaceable words based on the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement.
[0079] In this embodiment, if the structured query language statement does not need to be rewritten, the subsequent steps are skipped and the process ends directly. Therefore, it is checked whether the key exists in the cache. If it exists, it means that the structured query language statement needs to be rewritten. Then, the replaceable word array is obtained based on the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement. This involves calling condition.getValues().get(0) to get the value of the like condition, denoted as LikeValue; concatenating the string {table}_{column}_{LikeValue} as the key, and calling Redis to get the value corresponding to this key (which is an array, denoted as KeywordArray).
[0080] Step S15: Determine whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, iterate through the replaceable word array to form a new conditional statement, and use the new conditional statement to replace the target conditional statement to complete the keyword rewriting.
[0081] In this embodiment, determining whether KeywordArray exists means determining whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, it is traversed. The traversed items are denoted as keywords; and new SQL conditions are constructed, in the format ({column}like{keyword1}or{column}like{keyword2}or{column}like{keyword3}...). The original SQL conditions are replaced with the new SQL conditions, and finally, the new SQL is executed to complete the entire process.
[0082] As can be seen from the above, when rewriting search keywords, this application first uses a MyBatis interceptor to intercept and obtain a Structured Query Language (SCL) statement, parses the SCL statement to obtain the corresponding parsing result, and obtains the table name of the preset configuration table corresponding to the SCL statement based on the parsing result; it then obtains all target condition statements corresponding to the SCL statement from the parsing result, and iterates through the target condition statements to obtain the condition type corresponding to the target condition statement; finally, it determines whether the condition type is a Like type. If the condition type is a Like type, then based on... The target condition statement obtains the preset column name corresponding to the target condition statement, and determines whether the structured query language statement needs to be rewritten based on the table name and the preset column name. If rewriting is required, a replaceable word array is obtained based on the table name, the preset column name, and the value of the target condition statement determined by the target condition statement. Finally, it is determined whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, it is traversed to form a new condition statement, and the new condition statement is used to replace the target condition statement to complete the keyword rewriting. It can be seen that this application, through replaceable keyword configuration and MyBatis interceptors, intercepts and modifies the structured query language statement when it is executed, searches for keyword replacement configuration in the interceptor, and modifies the corresponding structured query language statement. In this way, developers do not need to explicitly call the keyword replacement configuration and modify the structured query language statement when writing structured query language statements, thus speeding up development efficiency and reducing unnecessary program errors introduced due to processing omissions. At the same time, the corresponding rewriting is achieved through configuration, without additional development work. It can avoid intrusion into business logic code and eliminates the need for developers to manually handle and rewrite logic.
[0083] See Figure 2 As shown, this embodiment of the invention discloses a specific method for rewriting search keywords, including:
[0084] First, the replaceable words need to be configured, including which tables and fields to replace, the words that can be substituted, and the corresponding replacement types (synonyms, incorrect words, etc.). Create a configuration table as shown in Table 1. At system startup, this table is read and the data is cached in a Map. For efficiency, a distributed cache (Redis) is used for data caching. For this table, all read data is traversed; the data is saved in Redis, where the key is the string `{table}_{column}`, indicating that this column in this table needs to be replaced; the values in the `keywords` column are split by commas to obtain array A; array A is traversed, each item being W; these are concatenated into a string using the format `{table}_{column}_{W}`, denoted as string K; this string is saved in Redis, where the key is string K and the value is array A.
[0085] Afterwards, the SQL statement can be intercepted. In this application, this is mainly achieved through MyBatis interceptors. After interception, the table name and conditional statements in the SQL can be obtained and iterated through to determine if the conditional statements are of type `LIKE`. If not, the process ends directly. If it is of type `LIKE`, the column names of the conditional statements are obtained, and the SQL statement is checked for rewriting based on the table name and column names. If not, the process ends directly. If so, the value of the conditional statements is obtained, and replaceable phrases are retrieved based on the table name, column name, and value. It is then checked whether the replaceable phrase exists in the configuration table. If not, the process ends directly. If it exists, the replaceable phrases are iterated through, and new SQL conditions are constructed based on the iterated items. The new SQL conditions replace the original SQL conditions. Finally, the new SQL is executed to complete the entire process. In this way, database keyword rewriting is achieved without modifying the SQL statement by leveraging search term configuration and MyBatis interception technology. For example, when a user searches for "power bank", the developer might write the SQL "select * from xxx where column like '%power bank%'". This solution retrieves the replaceable words corresponding to "power bank" from the configuration table and automatically replaces them with "select * from xxx where (column like '%power bank%' or column like '%power bank%')".
[0086] As shown above, this application can intercept and modify Structured Query Language (SCL) statements during execution through replaceable keyword configuration and MyBatis interceptors. The interceptor searches for keyword replacement configurations and modifies the corresponding SCL statements. This eliminates the need for developers to explicitly call keyword replacement configurations and modify SCL statements when writing them, thus accelerating development efficiency and reducing unnecessary program errors caused by oversights. Furthermore, the rewriting is achieved through configuration, requiring no additional development work. It avoids intrusion into business logic code, eliminating the need for developers to manually handle the rewriting logic.
[0087] See Figure 3 As shown, an embodiment of the present invention discloses a search keyword rewriting device, comprising:
[0088] The parsing result acquisition module 11 is used to intercept and acquire the structured query language statement using the MyBatis interceptor, parse the structured query language statement, and obtain the corresponding parsing result;
[0089] The table name acquisition module 12 is used to obtain the table name of the preset configuration table corresponding to the structured query language statement based on the parsing result;
[0090] The condition type acquisition module 13 is used to obtain all target condition statements corresponding to the structured query language statement from the parsing result, and to traverse the target condition statements to obtain the condition type corresponding to the target condition statement.
[0091] The first judgment module 14 is used to determine whether the condition type is a Like type. If the condition type is the Like type, then the preset column name corresponding to the target condition statement is obtained based on the target condition statement.
[0092] The second judgment module 15 is used to determine whether the structured query language statement needs to be rewritten based on the table name and the preset column name.
[0093] The replaceable word array acquisition module 16 is used to acquire a replaceable word array based on the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement if rewriting is required.
[0094] The third judgment module 17 is used to determine whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, the replaceable word array is traversed to form a new conditional statement, and the new conditional statement is used to replace the target conditional statement to complete the keyword rewriting.
[0095] As can be seen from the above, when rewriting search keywords, this application first uses a MyBatis interceptor to intercept and obtain a Structured Query Language (SCL) statement, parses the SCL statement to obtain the corresponding parsing result, and obtains the table name of the preset configuration table corresponding to the SCL statement based on the parsing result; it then obtains all target condition statements corresponding to the SCL statement from the parsing result, and iterates through the target condition statements to obtain the condition type corresponding to the target condition statement; finally, it determines whether the condition type is a Like type. If the condition type is a Like type, then based on... The target condition statement obtains the preset column name corresponding to the target condition statement, and determines whether the structured query language statement needs to be rewritten based on the table name and the preset column name. If rewriting is required, a replaceable word array is obtained based on the table name, the preset column name, and the value of the target condition statement determined by the target condition statement. Finally, it is determined whether the replaceable word array exists in the preset configuration table. If the replaceable word array exists, it is traversed to form a new condition statement, and the new condition statement is used to replace the target condition statement to complete the keyword rewriting. It can be seen that this application, through replaceable keyword configuration and MyBatis interceptors, intercepts and modifies the structured query language statement when it is executed, searches for keyword replacement configuration in the interceptor, and modifies the corresponding structured query language statement. In this way, developers do not need to explicitly call the keyword replacement configuration and modify the structured query language statement when writing structured query language statements, thus speeding up development efficiency and reducing unnecessary program errors introduced due to processing omissions. At the same time, the corresponding rewriting is achieved through configuration, without additional development work. It can avoid intrusion into business logic code and eliminates the need for developers to manually handle and rewrite logic.
[0096] In some specific embodiments, the apparatus may further include:
[0097] The configuration table creation module is used to create a configuration table and configure the configuration table with the table name, a first preset number of column names, the replacement type corresponding to each column, the explanation of each column, and a second preset number of replaceable words.
[0098] In some specific embodiments, the apparatus may further include:
[0099] The data caching module is used to read the data in the configuration table when the system starts up, and cache the data in a Map based on the distributed caching method corresponding to the remote dictionary service.
[0100] In some specific embodiments, the parsing result acquisition module 11 can be used to create a target class that implements the Interceptor interface of the MyBatis interceptor, and add a target annotation to the target class so as to determine the interception object of the MyBatis interceptor based on the target annotation; and intercept and obtain structured query language statements based on the Interceptor interface and the interception object.
[0101] In some specific embodiments, the apparatus may further include:
[0102] The first termination module is used to terminate directly if the condition type is not a Like type.
[0103] In some specific embodiments, the apparatus may further include:
[0104] The second termination module is used to terminate the process directly if no rewriting of the structured query language statement is required.
[0105] In some specific embodiments, the apparatus may further include:
[0106] The third termination module is used to terminate the process directly if the replaceable word array does not exist in the preset configuration table.
[0107] In some specific embodiments, the replaceable word array acquisition module 16 can be used to concatenate the table name, the preset column name, and the value of the target condition statement determined based on the target condition statement to obtain a target string; determine the target string as a keyword, and obtain the value corresponding to the keyword by calling the remote dictionary service, so as to determine the replaceable word array according to the value corresponding to the keyword.
[0108] Furthermore, embodiments of this application also disclose an electronic device, Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0109] Figure 4 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the search keyword rewriting method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0110] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0111] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0112] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the search keyword rewriting method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0113] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned search keyword rewriting method. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0114] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0115] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0116] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0117] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0118] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.< / sqlstatement>
Claims
1. A search keyword rewriting method, characterized by, The method comprises the following steps: intercepting and obtaining a structured query language statement by using a MyBatis interceptor, parsing the structured query language statement to obtain a corresponding parsing result, and obtaining a table name of a preset configuration table corresponding to the structured query language statement based on the parsing result; obtaining all target condition statements corresponding to the structured query language statement from the parsing result, and traversing the target condition statements to obtain a condition type corresponding to the target condition statements; judging whether the condition type is a Like type, and if the condition type is the Like type, obtaining a preset column name corresponding to the target condition statement based on the target condition statement, and determining whether the structured query language statement needs to be rewritten according to the table name and the preset column name; if rewriting is needed, obtaining a replaceable word array based on the table name, the preset column name and a value of the target condition statement determined based on the target condition statement; judging whether the replaceable word array exists in the preset configuration table, and if the replaceable word array exists, traversing the replaceable word array to form a new condition statement, and replacing the target condition statement with the new condition statement to complete keyword rewriting; before the step of intercepting and obtaining the structured query language statement by using the MyBatis interceptor, the method further comprises the steps of: creating a configuration table, and configuring the configuration table with the table name, a first preset number of column names, a replacement type corresponding to each column, an explanation corresponding to each column and a second preset number of replaceable words; after the step of creating the configuration table, the method further comprises the steps of: when the system starts, reading data in the configuration table, and caching the data into a Map based on a distributed cache mode of a remote dictionary service; the step of obtaining the replaceable word array based on the table name, the preset column name and the value of the target condition statement determined based on the target condition statement comprises the steps of: splicing the table name, the preset column name and the value of the target condition statement determined based on the target condition statement to obtain a target string; determining the target string as a keyword, and obtaining a value corresponding to the keyword by calling the remote dictionary service, so as to determine the replaceable word array according to the value corresponding to the keyword.
2. The search keyword rewriting method of claim 1, wherein, the step of intercepting and obtaining the structured query language statement by using the MyBatis interceptor comprises the steps of: creating a target class to implement an Interceptor interception interface of the MyBatis interceptor, and adding a target annotation to the target class, so as to determine an interception object of the MyBatis interceptor based on the target annotation; intercepting and obtaining the structured query language statement based on the Interceptor interception interface and the interception object.
3. The search keyword rewriting method according to claim 1 or 2, characterized by, after the step of judging whether the condition type is the Like type, the method further comprises the steps of: if the condition type is not the Like type, directly ending.
4. The search keyword rewriting method of claim 1, wherein, after the step of determining whether the structured query language statement needs to be rewritten according to the table name and the preset column name, the method further comprises the steps of: If the structured query language sentence does not need to be rewritten, directly end.
5. The search keyword rewriting method of claim 1, wherein, The judgment whether the preset configuration table has the replaceable word array further includes: If the preset configuration table does not have the replaceable word array, directly end.
6. A search keyword rewriting apparatus characterized by comprising: Comprise: The analysis result acquisition module is used for intercepting and acquiring the structured query language sentence by using the MyBatis interceptor, analyzing the structured query language sentence, and obtaining the corresponding analysis result; The table name acquisition module is used for acquiring the table name of the preset configuration table corresponding to the structured query language sentence based on the analysis result; The condition type acquisition module is used for acquiring all target condition sentences corresponding to the structured query language sentence from the analysis result, and traversing the target condition sentences to obtain the condition type corresponding to the target condition sentence; The first judgment module is used for judging whether the condition type is the Like type, and if the condition type is the Like type, acquiring the preset column name corresponding to the target condition sentence based on the target condition sentence; The second judgment module is used for determining whether the structured query language sentence needs to be rewritten according to the table name and the preset column name; The replaceable word array acquisition module is used for acquiring the replaceable word array based on the table name, the preset column name, and the value of the target condition sentence determined based on the target condition sentence if rewriting is needed; The third judgment module is used for judging whether the preset configuration table has the replaceable word array, and if the preset configuration table has the replaceable word array, traversing the replaceable word array to form a new condition sentence, and replacing the target condition sentence by using the new condition sentence to complete the keyword rewriting; The device is also used for creating a configuration table, and configuring the table name, a first preset number of column names, a replacement type corresponding to each column, an explanation corresponding to each column, and a second preset number of replaceable words for the configuration table; The device is also used for reading data in the configuration table when the system starts, and caching the data into a Map based on a distributed cache mode of a remote dictionary service; The replaceable word array acquisition module is used for splicing the table name, the preset column name, and the value of the target condition sentence determined based on the target condition sentence to obtain a target string; The target string is determined as a keyword, and the value corresponding to the keyword is acquired by calling the remote dictionary service, so as to determine the replaceable word array according to the value corresponding to the keyword.
7. An electronic device, comprising: Comprise: Memory for saving computer programs; Processor for executing the computer programs to realize the steps of the search keyword rewriting method in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, For storing computer programs; wherein the computer programs are executed by the processor to realize the steps of the search keyword rewriting method in any one of claims 1 to 5. For storing computer programs; wherein the computer programs are executed by the processor to realize the steps of the search keyword rewriting method in any one of claims 1 to 5.
Citation Information
Patent Citations
Data storage method, querying method and device
CN101968806A
Query statement rewriting method and device
CN110969024A