File generation method and device, computer equipment, readable storage medium and product

Through a file generation method based on preset annotations, the efficiency reduction problem of search engine code files due to nested structure modification is solved, automatic code generation is realized, and development efficiency and accuracy are improved.

CN120144115APending Publication Date: 2025-06-13SF TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311715338.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-13
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

In the prior art, the code files of search engines are prone to modifying other codes due to modification of nested structures, resulting in large workloads for developers and easy omissions, thereby reducing file generation efficiency.

Method used

Provides a file generation method, which can obtain source files and template files by responding to file generation instructions, scan preset annotations in the source files, and render the template files based on these annotations to generate target files.

Benefits of technology

This method does not require developers to write code manually, which improves the readability, maintainability and reusability of the code, and improves file generation efficiency, ensures the accuracy of the generated files, and avoids production accidents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120144115A_ABST
    Figure CN120144115A_ABST
Patent Text Reader

Abstract

The invention relates to a file generation method and device, computer equipment, a readable storage medium and a product, and relates to the technical field of computers. The method comprises the following steps: in response to a file generation instruction for a target search engine, obtaining a source file and a template file corresponding to the file generation instruction; scanning the source file to obtain a preset annotation in the source file; and based on the preset annotation, performing template rendering on the template file, and generating a target file corresponding to the file generation instruction. By adopting the method, the file generation efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and particularly to a file generation method, apparatus, computer device, readable storage medium, and product. Background Art

[0002] A search engine is a retrieval technology that retrieves specified information from the Internet according to user needs and a certain algorithm and uses a specific strategy to feedback it to the user.

[0003] For the operation of a search engine, it is implemented by manually writing code files. However, code files can be nested continuously. Once a modification occurs in a certain place in the file, the corresponding other codes in that place also need to be modified. This not only involves a large amount of work for developers, but also is prone to omissions, resulting in a reduction in the code file generation efficiency. Summary of the Invention

[0004] Based on this, in view of the above technical problems, it is necessary to provide a file generation method, apparatus, computer device, readable storage medium, and product that can improve the file generation efficiency.

[0005] In a first aspect, this application provides a file generation method. The method includes:

[0006] In response to a file generation instruction for a target search engine, obtain a source file and a template file corresponding to the file generation instruction;

[0007] Scan the source file to obtain preset annotations in the source file;

[0008] Based on the preset annotations, perform template rendering on the template file to generate a target file corresponding to the file generation instruction.

[0009] In one embodiment, the performing template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction includes:

[0010] Based on the preset annotations, perform template rendering on the template file to obtain a rendered file corresponding to the template file;

[0011] Obtain the file format requirements corresponding to the target search engine, and perform file format adjustment on the rendered file based on the file format requirements to obtain the target file.

[0012] In one embodiment, the rendered file includes a definition file and a constant file, and the template file includes a definition template file and a constant template file;

[0013] Rendering the template file based on the preset annotation to obtain a rendered file corresponding to the template file, including:

[0014] Parsing the preset annotation to obtain annotation information corresponding to the preset annotation;

[0015] Respectively screening out a first variable item in the defined template file and a second variable item in the constant template file;

[0016] Based on the annotation information, respectively determining a first target value corresponding to the first variable item and a second target value corresponding to the second variable item;

[0017] Rendering the defined template file according to the first target value to obtain the defined file;

[0018] Rendering the constant template file according to the second target value to obtain the constant file.

[0019] In one embodiment, the parsing the preset annotation to obtain annotation information corresponding to the preset annotation includes:

[0020] Traversing the preset annotation to obtain a meta-annotation corresponding to the preset annotation;

[0021] Parsing the meta-annotation to obtain meta-annotation information corresponding to the meta-annotation;

[0022] If the meta-annotation information includes a sub-annotation, updating the meta-annotation to the sub-annotation and returning to the step: parsing the meta-annotation to obtain meta-annotation information corresponding to the meta-annotation;

[0023] If the meta-annotation information does not include a sub-annotation, using the meta-annotation information as the annotation information.

[0024] In one embodiment, before the step of responding to a file generation instruction for a target search engine, the method further includes:

[0025] Obtaining source code corresponding to the target search engine;

[0026] Creating the preset annotation according to business requirements and the scope of annotation application;

[0027] Adding the preset annotation to a specified position in the source code to obtain a source file corresponding to the target search engine.

[0028] In one embodiment, before the step of scanning the source file to obtain a preset annotation in the source file, the method further includes:

[0029] Perform data integrity verification on the source file to obtain a data integrity verification result;

[0030] Scanning the source file to obtain preset annotations in the source file includes:

[0031] If the data integrity verification result is passed, scan the source file to obtain preset annotations in the source file.

[0032] In a second aspect, the present application also provides a file generation device. The device includes:

[0033] An instruction response module, configured to respond to a file generation instruction for a target search engine, and obtain a source file and a template file corresponding to the file generation instruction;

[0034] An annotation acquisition module, configured to scan the source file to obtain preset annotations in the source file;

[0035] A file generation module, configured to perform template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction.

[0036] In a third aspect, the present application also provides a computer device. The computer device includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0037] Respond to a file generation instruction for a target search engine, and obtain a source file and a template file corresponding to the file generation instruction;

[0038] Scan the source file to obtain preset annotations in the source file;

[0039] Perform template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction.

[0040] In a fourth aspect, the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0041] Respond to a file generation instruction for a target search engine, and obtain a source file and a template file corresponding to the file generation instruction;

[0042] Scan the source file to obtain preset annotations in the source file;

[0043] Perform template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction.

[0044] In a fifth aspect, the present application also provides a computer program product. The computer program product includes a computer program which, when executed by a processor, implements the following steps:

[0045] In response to a file generation instruction for a target search engine, obtain a source file and a template file corresponding to the file generation instruction;

[0046] Scan the source file to obtain preset annotations in the source file;

[0047] Based on the preset annotations, perform template rendering on the template file to generate a target file corresponding to the file generation instruction.

[0048] The above file generation method, device, computer device, readable storage medium and product first respond to a file generation instruction for a target search engine to obtain a source file and a template file corresponding to the generation instruction, so as to facilitate subsequent generation of a target file based on the source file and the template file. Then, the source file is scanned to obtain preset annotations in the source file, eliminating the need for developers to manually write code, which can not only improve the readability, maintainability and reusability of the code, but also improve the file generation efficiency. Finally, based on the preset annotations, template rendering is performed on the template file, that is, the annotation information scanned from the preset annotations is added to the template file, thereby generating a target file corresponding to the file generation instruction. Using the template file can make the file structure clearer, easier to understand, facilitate developers to better combine and manage files, and improve development efficiency and maintainability. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is a schematic diagram of an application scenario of the file generation method in an embodiment;

[0050] Figure 2 It is a schematic flowchart of the file generation method in an embodiment;

[0051] Figure 3 It is a schematic flowchart of a process of template rendering in an embodiment;

[0052] Figure 4 It is a schematic flowchart of another process of template rendering in an embodiment;

[0053] Figure 5 It is a schematic flowchart of a process of recursive parsing in an embodiment;

[0054] Figure 6 It is a schematic flowchart of a process of annotation creation in an embodiment;

[0055] Figure 7 It is a schematic flowchart of a process of data integrity verification in an embodiment;

[0056] Figure 8 is a structural block diagram of a file generation device in an embodiment;

[0057] Figure 9 is an internal structure diagram of a computer device in an embodiment. Detailed implementation manners

[0058] In order to make the objectives, technical solutions and advantages of the present application more clear and understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0059] A search engine is a retrieval technology that retrieves specified information from the Internet according to user needs and certain algorithms, and uses specific strategies to feedback the information to users, providing fast and highly relevant information services for information retrieval users. Currently, when using a search engine, developers need to manually write code files first, then write corresponding Java (JavaScript, a computer programming language) objects, and finally use the software development kit corresponding to the search engine for data storage and retrieval. However, the code files of the search engine can be continuously nested. Once a certain code or a certain file structure in the file is modified, the corresponding other codes and other hierarchical structures also need to be modified accordingly. For developers, this is not only time-consuming and laborious, but also prone to missed modifications, which will not only reduce the efficiency of file generation, but also lead to a decrease in the accuracy of the generated files, thus easily causing production accidents.

[0060] The file generation method provided by the embodiments of the present disclosure can be applied to an application environment as Figure 1 shown. Among them, the server 102 is connected to the terminal 104. The server 102 receives a file generation instruction for a target search engine sent by the terminal 104, and obtains a source file and a template file corresponding to the file generation instruction; then scans the source file through an annotation processor pre-created and deployed in the server 102 to obtain preset annotations in the source file; finally, the server 102 performs template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction. Among them, the server 102 can be implemented by an independent server or a server cluster composed of multiple servers. The terminal 104 can be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, and Internet of Things devices.

[0061] In one embodiment, as Figure 2 shown, a file generation method is provided. Taking the method applied to the Figure 1 server 102 as an example, the method includes the following steps:

[0062] Step S202, in response to a file generation instruction for a target search engine, obtain a source file and a template file corresponding to the file generation instruction.

[0063] Among them, the target search engine refers to the search engine for which file generation is required. In this embodiment, the target search engine may be an ES (Elasticsearch) search engine. The ES search engine is a distributed, highly scalable, and highly real-time search and data analysis engine, which can easily enable a large amount of data to have the capabilities of search, analysis, and exploration.

[0064] The file generation instruction refers to an instruction for generating a target file corresponding to the target search engine. The generated target file can be used to control the target search engine for data storage and data retrieval. The source file refers to a file containing preset annotations, and the template file refers to a predefined file, which contains fixed content and variable content, and these contents are directly used and modified when generating the target file.

[0065] In one embodiment, there may be one type or multiple different types of template files corresponding to the target search engine. Different types of template files can generate different target files. The type of the template file can be set according to the experience of developers or the current business requirements, and no limitation is made here.

[0066] In one embodiment, the template file can be stored in a template engine. The template engine refers to an engine that can generate documents in a specific format. In this embodiment, the template engine can be a Freemarker engine, and the template engine can be deployed on a server.

[0067] Specifically, if the server receives a file generation instruction for the target search engine uploaded by the terminal, the server can parse the file generation instruction to obtain the instruction identifier corresponding to the file generation instruction, and then query the corresponding source file in the server database and the corresponding template file in the template engine based on the instruction identifier. Among them, the instruction identifier refers to an identifier used to query the source file corresponding to the file generation instruction and the template file corresponding to the file generation instruction, and may include but is not limited to file name, file path, file version number, etc.

[0068] Step S204, scan the source file to obtain the preset annotations in the source file.

[0069] Among them, the annotation processor is a tool for processing annotations, used to automatically scan and process the annotations in the source file during compilation, so as to generate the target file based on the annotations. In this way, it is not necessary for developers to manually write code, which reduces the workload of developers and improves the efficiency of file generation.

[0070] In one embodiment, the annotation processor can be implemented through standard interfaces in Java. Developers can write a class that implements the javax.annotation.processing.Processor interface. The javax.annotation.processing.Processor is a tool used to declare annotation processors and allow annotation processors to communicate with the annotation processing tool environment. Then, they can package it into a Jar (Java Archive) file and load it into javac (java compiler) during compilation.

[0071] A preset annotation refers to a pre-defined annotation. An annotation is a way to add supplementary information in the source code and can be used to describe the characteristics and behaviors of program elements such as classes, methods, and property values. Annotations can be used at compile time, runtime, or in development tools to provide additional information and instructions, enhancing the readability and maintainability of the code.

[0072] In one embodiment, the preset annotations can include annotations on class files. For example, for the name of the file, if it is testES (the file name corresponding to the ES search engine), a TestESConstant (testES constant) file will be generated. If the file name is empty, the original class name plus Constant will be used as the file name by default. Another example is the file name prefix. If the file name prefix is empty, no definition file will be generated.

[0073] In one embodiment, the preset annotations can also include annotations on property values. For example, all properties of the annotated class are of the keyword type by default. Another example is the time format annotation, i.e., the format annotation. This annotation is used on properties and its function is to convert date-type data into the required format, generally "yyyy-MM-dd (year-month-day) || yyyy-MM-dd HH:mm:ss (year-month-day hour:minute:second)".

[0074] Specifically, after the server obtains the source file and the template file, it calls the annotation processor to control the annotation processor to scan the source file and read the annotations pre-defined on program elements such as classes and property values in the source file.

[0075] Step S206: Based on the preset annotations, perform template rendering on the template file to generate a target file corresponding to the file generation instruction.

[0076] Among them, template rendering refers to adding annotation information corresponding to preset annotations to a template file. The target file can include a definition file and a constant file. The definition file refers to the definition file of the storage format of the target search engine, which stipulates information such as the data storage path and data type. The constant file refers to a file that stores fixed and unchangeable values, and the data in the constant file are all data that cannot be changed.

[0077] Specifically, after the server obtains the preset annotations in the source file through the annotation processor, it can parse the preset annotations to obtain the annotation information corresponding to the preset annotations, and then based on the annotation information, perform template rendering on the template file, that is, combine the annotation information with the template file to obtain the definition file and the constant file.

[0078] In this embodiment, first, in response to a file generation instruction for the target search engine, obtain the source file and the template file corresponding to the generation instruction, so as to subsequently generate the target file based on the source file and the template file. Then scan the source file to obtain the preset annotations in the source file. The annotation processor is a tool for processing annotations, which is used to automatically scan and process annotations during compilation to generate additional code, without the need for developers to manually write code. It can not only improve the readability, maintainability and reusability of the code, but also improve the file generation efficiency. Finally, based on the preset annotations, perform template rendering on the template file, that is, add the annotation information scanned from the preset annotations to the template file, so as to generate the target file corresponding to the file generation instruction. Using the template file can make the file structure clearer and easier to understand, facilitate developers to better combine and manage files, and improve the development efficiency and maintainability.

[0079] In one embodiment, as Figure 3 shown, based on the preset annotations, performing template rendering on the template file to generate the target file corresponding to the file generation instruction includes:

[0080] Step S302, based on the preset annotations, perform template rendering on the template file to obtain a rendered file corresponding to the template file.

[0081] Among them, the rendered file refers to the file obtained by combining the annotation information corresponding to the preset annotations with the template file.

[0082] Specifically, the server parses the preset annotations to obtain the annotation information corresponding to the preset annotations, determines the target value to be added to the template file based on the annotation information, and adds the target value to the specified position in the template file to obtain the rendered file.

[0083] Step S304, obtain the file format requirements corresponding to the target search engine, and adjust the file format of the rendered file to obtain the target file.

[0084] Among them, the file format requirement refers to the file specification requirement corresponding to the target search engine. That is to say, the generated target file needs to meet the file specification requirement of the target search engine to be used on the target search engine.

[0085] Specifically, obtain the file specification requirement corresponding to the preset target search engine. For example, the outermost layer of the file is fixed as the properties class, and the file is divided into one or more field blocks inside, and one or more keys can be included in the field blocks. Then, according to this file specification requirement, adjust the file format of the rendered file to make the file format of the rendered file conform to this file specification requirement, and obtain the target file with the adjusted file format.

[0086] In this embodiment, by adjusting the file format of the rendered file to conform to the file format requirement of the target search engine, it is ensured that the finally obtained target file can run on the target search engine.

[0087] In one embodiment, as Figure 4 shown, based on the preset annotation, perform template rendering on the template file to obtain the rendered file corresponding to the template file, including:

[0088] Step S402, parse the preset annotation to obtain the annotation information corresponding to the preset annotation.

[0089] Step S404, respectively screen out the first variable items in the definition template file and the second variable items in the constant template file.

[0090] Among them, the annotation information refers to the information used to explain the preset annotation. The template file includes a definition template file and a constant template file. The definition template file refers to the template file used to generate the definition file, and the constant template file refers to the template file used to generate the constant file. The variable item refers to the item whose value can change in the template file. For example, a template file contains "Today's matters", and "Today's matters" is a fixed item that must exist and cannot be changed, but the value corresponding to "Today's matters" is changeable. "Today's matters" can be matter A or matter B, and this is the variable item. The first variable item refers to the item whose value can change predefined in the definition template file. The second variable item refers to the item whose value can change predefined in the constant template file.

[0091] Specifically, the server parses the preset annotation in the source file to obtain the annotation information used for explanation in the preset annotation. And obtain the definition template file and the constant template file, screen out the first variable items whose values can change predefined in the definition template file, and screen out the second variable items whose values can change predefined in the constant template file.

[0092] Step S406: Based on the annotation information, determine the first target value corresponding to the first change item and the second target value corresponding to the second change item respectively.

[0093] Among them, the first target value refers to the value added to the first change item. The second target value refers to the value added to the second change item.

[0094] Specifically, the server can filter out the annotation information corresponding to the first change item and the annotation information corresponding to the second change item, so as to determine the first target value corresponding to the first change item based on the annotation information corresponding to the first change item, and determine the second target value corresponding to the second change item based on the annotation information corresponding to the second change item.

[0095] Step S408: According to the first target value, perform template rendering on the definition template file to obtain a definition file.

[0096] Step S410: According to the second target value, perform template rendering on the constant template file to obtain a constant file.

[0097] Specifically, after the server obtains the first target value and the second target value, it adds the first target value to the first change item to obtain a definition file, and adds the second target value to the second change item to obtain a constant file.

[0098] In one embodiment, the order of rendering the definition template file and rendering the constant template file is not limited. It can be to render the definition template file first and then the constant template file, or to render the constant template file first and then the definition template file, or to render the definition template file and the constant template file simultaneously.

[0099] In this embodiment, by determining the target value and the change item, and then adding the target value to the change item to obtain the target file. In this way, when facing code nesting, there is no need to manually modify all the associated codes. Instead, directly use the annotation processor to scan out the preset annotations, and then add the target values corresponding to the preset annotations to the change items in the template file, achieving the purpose of quickly generating the definition file and the constant file, improving the efficiency of file generation. Moreover, manual writing is prone to the phenomenon of missing modification. Therefore, this embodiment also improves the accuracy of the generated files and avoids the occurrence of production accidents.

[0100] In one embodiment, as Figure 5 shown, parse the preset annotation to obtain the annotation information corresponding to the preset annotation, including:

[0101] Step S502: Traverse the preset annotation to obtain the meta-annotation corresponding to the preset annotation.

[0102] Among them, considering the nested structure of the preset annotations in the source file, in this embodiment, when parsing the annotations, a recursive parsing method is adopted, which can parse the annotations with a multi-layer structure, thereby ensuring the accuracy and integrity of the annotations, and further improving the accuracy and integrity of the generated definition file and constant file. The meta-annotation can refer to the first-layer annotation in the preset annotation.

[0103] For example, assuming the annotation of the source file is @A: {@B:}, @A is the first-layer annotation, that is, the meta-annotation, and @B belongs to another annotation under @A, that is, the second-layer annotation.

[0104] Specifically, the server can first traverse the preset annotations in the source file to obtain the first-layer annotations in the preset annotations, that is, the meta-annotations, and the meta-annotations can be one or more.

[0105] Step S504, parse the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation.

[0106] Among them, the meta-annotation information refers to the information used to explain the meta-annotation.

[0107] Specifically, the server parses the meta-annotation, that is, expands the meta-annotation, to obtain the meta-annotation information corresponding to the meta-annotation. From the meta-annotation information, the interpretation information of the meta-annotation can be obtained. Further, from the interpretation information, it can be detected whether the meta-annotation includes sub-annotations.

[0108] Step S506, if the meta-annotation information includes sub-annotations, update the meta-annotation to the sub-annotation, and return to the step: parse the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation.

[0109] Among them, the sub-annotation refers to the preset annotation subordinate to the meta-annotation. Still taking @A: {@B:} as an example, @B can be the sub-annotation of @A.

[0110] Specifically, detecting whether the meta-annotation information includes sub-annotations, that is, detecting whether there are other preset annotations in the meta-annotation information. If it is detected that the meta-annotation information includes sub-annotations, update the meta-annotation to the sub-annotation, that is, parse the sub-annotation to obtain the annotation information corresponding to the sub-annotation, and detect whether there are other preset annotations in the annotation information corresponding to the sub-annotation. Repeat the above steps until the stop condition is reached. Among them, the stop condition can be to stop when it is detected that the meta-annotation information no longer includes sub-annotations, or to stop when the detected annotation layer reaches the preset layer threshold. The preset layer threshold refers to the detection layer when presetting recursive parsing of annotations, and can also be set according to the actual application situation.

[0111] Step S508, if the meta-annotation information does not include sub-annotations, use the meta-annotation information as the annotation information.

[0112] Specifically, if it is detected that there is no sub-annotation in the meta-annotation information, that is, the meta-annotation does not have other preset annotations to which it belongs, the annotation information of the meta-annotation is directly obtained.

[0113] In this embodiment, by using the recursive parsing method, multi-layer annotations in the source file are parsed, so as to improve the integrity and accuracy of the obtained annotation information, and further improve the integrity and accuracy of the definition file and constant file finally generated based on the annotation information.

[0114] In one embodiment, as Figure 6 shown, before the step of responding to the file generation instruction for the target search engine, the following steps are further included:

[0115] Step S602: Obtain the source code corresponding to the target search engine.

[0116] Step S604: Create a preset annotation according to the business requirements and the annotation scope of action.

[0117] Among them, the business requirements refer to the requirements that the generated target file needs to meet. The annotation scope of action refers to the application scope of the preset annotation, which may include the source code stage and the bytecode file stage. In this embodiment, the preset annotation scope of action is specified in the bytecode file stage.

[0118] Specifically, the server obtains the source code corresponding to the target search engine and obtains the business requirements corresponding to the generation of the target file this time, so as to create a preset annotation with the application scope in the bytecode file stage according to the business requirements.

[0119] Step S606: Add the preset annotation to the specified position in the source code to obtain the source file corresponding to the target search engine.

[0120] Among them, the specified position refers to the annotation insertion position preset in the source code.

[0121] Specifically, after obtaining the preset annotation, locate the annotation insertion position in the source code, which can be the insertion position corresponding to the class or the insertion position corresponding to the method, and add the preset annotation to the corresponding annotation insertion position to obtain the source file.

[0122] In this embodiment, creating a preset annotation based on the business requirements and the annotation scope of action, so as to generate the source file, not only avoids the reduction of the preset annotation creation efficiency caused by improper division of the annotation scope of action, that is, each time a single class is modified, all the content needs to be regenerated again, but also makes the created annotation more in line with the actual situation and improves the accuracy of the annotation. Further improves the accuracy and generation efficiency of the finally obtained target file.

[0123] In one embodiment, before scanning the source file to obtain the preset annotations in the source file, the file generation method further includes: performing data integrity verification on the source file to obtain a data integrity verification result; scanning the source file to obtain the preset annotations in the source file, including: if the data integrity verification result is passed, scanning the source file to obtain the preset annotations in the source file.

[0124] Among them, the data integrity verification result is used to characterize whether there are preset annotations in the source file and whether the annotation format of the preset annotations in the source file is correct. The data integrity verification result may include passed and failed.

[0125] Specifically, before the server uses the annotation processor to scan the source file, it can first detect whether there are preset annotations in the source file. If there are no preset annotations, it is determined that the data integrity verification result is failed, and a signal indicating the absence of preset annotations is returned to the terminal. If there are preset annotations, it further detects whether the annotation format of the preset annotations is correct. For example, whether the single-line annotation starts with " / / ", whether the multi-line comment starts with " / *" and ends with "* / ", etc. If the annotation format is incorrect, it is determined that the data integrity verification result is failed, and a signal indicating the incorrect annotation format is returned to the terminal. If the annotation format is correct, it is determined that the data integrity verification result is passed, and the source file is scanned through the pre-created annotation processor to obtain the preset annotations in the source file.

[0126] In this embodiment, by performing data integrity verification on the source file, the source files with failed data integrity verification results are excluded, reducing the workload of the annotation processor for scanning the source file, thereby improving the working efficiency of the annotation processor and further improving the generation efficiency of the target file.

[0127] In one embodiment, as Figure 7 shown, the target search engine is an ES search engine. The server receives a file generation instruction for the ES search engine sent by the terminal, and obtains the corresponding source file, definition template file, and constant template file; then scans the source file through a custom annotation processor pre-created and deployed on the server to obtain the preset annotations in the source file, and parses the preset annotations to obtain annotation information. Based on this annotation information, template rendering is performed on the definition template file and the constant template file respectively to obtain a definition file corresponding to the definition template file and a constant file corresponding to the constant template file.

[0128] In this embodiment, the annotation processor is used to automatically scan and process the annotations, thereby generating a definition file and a constant file for the ES search engine, without the need for developers to manually write code, which can not only improve the readability, maintainability, and reusability of the code, but also improve the file generation efficiency of the ES search engine.

[0129] It should be understood that although the steps in the flowcharts involved in the above-described embodiments are sequentially shown according to the indications of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps has no strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-described embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or alternately with at least a part of other steps or steps or stages in other steps.

[0130] Based on the same inventive concept, an embodiment of the present application also provides a file generation device for implementing the above-mentioned file generation method. The implementation solutions provided by this device to solve problems are similar to the implementation solutions described in the above method. Therefore, the specific limitations in one or more embodiments of the file generation device provided below can refer to the limitations on the file generation method in the above text, and will not be repeated here.

[0131] In one embodiment, as Figure 8 shown, a file generation device is provided, including: an instruction response module 802, an annotation acquisition module 804, and a file generation module 806, where:

[0132] The instruction response module 802 is configured to respond to a file generation instruction for a target search engine and obtain a source file and a template file corresponding to the file generation instruction;

[0133] The annotation acquisition module 804 is configured to scan the source file to obtain preset annotations in the source file;

[0134] The file generation module 806 is configured to perform template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction.

[0135] In one of the embodiments, the file generation module 806 further includes:

[0136] A rendering unit configured to perform template rendering on the template file based on the preset annotations to obtain a rendered file corresponding to the template file;

[0137] A format adjustment unit configured to obtain the file format requirements corresponding to the target search engine and perform file format adjustment on the rendered file based on the file format requirements to obtain the target file.

[0138] In one embodiment, the rendering unit further includes:

[0139] A parsing subunit, configured to parse the preset annotation to obtain annotation information corresponding to the preset annotation;

[0140] A change item screening subunit, configured to screen out a first change item in the definition template file and a second change item in the constant template file respectively;

[0141] A target value determination subunit, configured to respectively determine a first target value corresponding to the first change item and a second target value corresponding to the second change item based on the annotation information;

[0142] A first rendering subunit, configured to perform template rendering on the definition template file according to the first target value to obtain the definition file;

[0143] A second rendering subunit, configured to perform template rendering on the constant template file according to the second target value to obtain the constant file.

[0144] In one embodiment, the parsing subunit is further configured to:

[0145] Traverse the preset annotation to obtain a meta-annotation corresponding to the preset annotation;

[0146] Parse the meta-annotation to obtain meta-annotation information corresponding to the meta-annotation;

[0147] If the meta-annotation information includes a sub-annotation, update the meta-annotation to the sub-annotation, and return to the step: parse the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation;

[0148] If the meta-annotation information does not include a sub-annotation, use the meta-annotation information as the annotation information.

[0149] In one embodiment, the file generation device further includes:

[0150] A source code acquisition module, configured to acquire the source code corresponding to the target search engine;

[0151] An annotation creation module, configured to create the preset annotation according to service requirements and the scope of annotation application;

[0152] An addition module, configured to add the preset annotation to a specified position in the source code to obtain the source file corresponding to the target search engine.

[0153] In one embodiment, the file generation device further includes:

[0154] A data integrity verification module, which is used to perform data integrity verification on the source file to obtain a data integrity verification result;

[0155] The annotation acquisition module 804 is further configured to:

[0156] If the data integrity verification result is passed, scan the source file to obtain preset annotations in the source file.

[0157] Each module in the above file generation device can be implemented in whole or in part by software, hardware, and their combination. Each of the above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or stored in a memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0158] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as Figure 9 shown. The computer device includes a processor, a memory, and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store item recommendation data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a file generation method is implemented.

[0159] Those skilled in the art can understand that Figure 9 the structure shown in

[0160] is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have a different component layout.

[0161] In response to a file generation instruction for a target search engine, obtain a source file and a template file corresponding to the file generation instruction;

[0162] Scan the source file to obtain preset annotations in the source file;

[0163] Based on the preset annotation, perform template rendering on the template file to generate a target file corresponding to the file generation instruction.

[0164] In one embodiment, when the processor executes the computer program, the following steps are further implemented:

[0165] Based on the preset annotation, perform template rendering on the template file to obtain a rendered file corresponding to the template file;

[0166] Obtain the file format requirements corresponding to the target search engine, and perform file format adjustment on the rendered file based on the file format requirements to obtain the target file.

[0167] In one embodiment, when the processor executes the computer program, the following steps are further implemented:

[0168] Parse the preset annotation to obtain the annotation information corresponding to the preset annotation;

[0169] Respectively screen out the first variable items in the defined template file and the second variable items in the constant template file;

[0170] Based on the annotation information, respectively determine the first target value corresponding to the first variable item and the second target value corresponding to the second variable item;

[0171] According to the first target value, perform template rendering on the defined template file to obtain the defined file;

[0172] According to the second target value, perform template rendering on the constant template file to obtain the constant file.

[0173] In one embodiment, when the processor executes the computer program, the following steps are further implemented:

[0174] Traverse the preset annotation to obtain the meta-annotation corresponding to the preset annotation;

[0175] Parse the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation;

[0176] If the meta-annotation information includes sub-annotations, update the meta-annotation to the sub-annotations, and return to the step: parse the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation;

[0177] If the meta-annotation information does not include sub-annotations, use the meta-annotation information as the annotation information.

[0178] In one embodiment, when the processor executes the computer program, the following steps are further implemented:

[0179] Obtain the source code corresponding to the target search engine;

[0180] Create the preset annotation according to the business requirements and the scope of the annotation;

[0181] Add the preset annotation to the specified position in the source code to obtain the source file corresponding to the target search engine.

[0182] In one embodiment, when the processor executes the computer program, the following steps are further implemented:

[0183] Perform data integrity verification on the source file to obtain a data integrity verification result;

[0184] The scanning of the source file to obtain the preset annotation in the source file includes:

[0185] If the data integrity verification result is passed, scan the source file to obtain the preset annotation in the source file.

[0186] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0187] In response to a file generation instruction for a target search engine, obtain a source file and a template file corresponding to the file generation instruction;

[0188] Scan the source file to obtain the preset annotation in the source file;

[0189] Based on the preset annotation, perform template rendering on the template file to generate a target file corresponding to the file generation instruction.

[0190] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0191] Based on the preset annotation, perform template rendering on the template file to obtain a rendered file corresponding to the template file;

[0192] Obtain the file format requirements corresponding to the target search engine, and perform file format adjustment on the rendered file based on the file format requirements to obtain the target file.

[0193] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0194] Parse the preset annotation to obtain the annotation information corresponding to the preset annotation;

[0195] Respectively screen out the first variable items in the defined template file and the second variable items in the constant template file;

[0196] Based on the annotation information, respectively determine a first target value corresponding to the first variable item and a second target value corresponding to the second variable item;

[0197] According to the first target value, perform template rendering on the definition template file to obtain the definition file;

[0198] According to the second target value, perform template rendering on the constant template file to obtain the constant file.

[0199] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0200] Traverse the preset annotation to obtain a meta-annotation corresponding to the preset annotation;

[0201] Parse the meta-annotation to obtain meta-annotation information corresponding to the meta-annotation;

[0202] If the meta-annotation information includes a sub-annotation, update the meta-annotation to the sub-annotation, and return to the step: parse the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation;

[0203] If the meta-annotation information does not include a sub-annotation, use the meta-annotation information as the annotation information.

[0204] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0205] Obtain the source code corresponding to the target search engine;

[0206] Create the preset annotation according to the service requirements and the annotation scope of action;

[0207] Add the preset annotation to a specified position in the source code to obtain the source file corresponding to the target search engine.

[0208] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0209] Perform data integrity verification on the source file to obtain a data integrity verification result;

[0210] The scanning of the source file to obtain the preset annotation in the source file includes:

[0211] If the data integrity verification result is passed, scan the source file to obtain the preset annotation in the source file.

[0212] In one embodiment, a computer program product is provided, including a computer program which, when executed by a processor, implements the following steps:

[0213] In response to a file generation instruction for a target search engine, obtain a source file and a template file corresponding to the file generation instruction;

[0214] Scan the source file to obtain preset annotations in the source file;

[0215] Based on the preset annotations, perform template rendering on the template file to generate a target file corresponding to the file generation instruction.

[0216] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0217] Based on the preset annotations, perform template rendering on the template file to obtain a rendered file corresponding to the template file;

[0218] Obtain the file format requirements corresponding to the target search engine, and perform file format adjustment on the rendered file based on the file format requirements to obtain the target file.

[0219] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0220] Parse the preset annotations to obtain annotation information corresponding to the preset annotations;

[0221] Respectively screen out a first variable item in the definition template file and a second variable item in the constant template file;

[0222] Based on the annotation information, respectively determine a first target value corresponding to the first variable item and a second target value corresponding to the second variable item;

[0223] According to the first target value, perform template rendering on the definition template file to obtain the definition file;

[0224] According to the second target value, perform template rendering on the constant template file to obtain the constant file.

[0225] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0226] Traverse the preset annotations to obtain meta-annotations corresponding to the preset annotations;

[0227] Parse the meta-annotations to obtain meta-annotation information corresponding to the meta-annotations;

[0228] If the meta-annotation information includes a sub-annotation, update the meta-annotation to the sub-annotation, and return to the step of parsing the meta-annotation to obtain the meta-annotation information corresponding to the meta-annotation;

[0229] If the meta-annotation information does not include a sub-annotation, use the meta-annotation information as the annotation information.

[0230] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0231] Obtain the source code corresponding to the target search engine;

[0232] Create the preset annotation according to the service requirements and the annotation scope of action;

[0233] Add the preset annotation to a specified position in the source code to obtain the source file corresponding to the target search engine.

[0234] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0235] Perform data integrity verification on the source file to obtain a data integrity verification result;

[0236] The scanning of the source file to obtain the preset annotation in the source file includes:

[0237] If the data integrity verification result is passed, scan the source file to obtain the preset annotation in the source file.

[0238] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0239] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memories can include read-only memory (ROM), magnetic tapes, floppy disks, flash memories, optical memories, high-density embedded non-volatile memories, resistive random access memories (ReRAM), magnetoresistive random access memories (MRAM), ferroelectric random access memories (FRAM), phase change memories (PCM), graphene memories, etc. Volatile memories can include random access memory (RAM) or external cache memories, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.

[0240] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.

[0241] The above-described embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. A method for generating a file, characterized in that, the method includes: responding to a file generation instruction for a target search engine, and obtaining a source file and a template file corresponding to the file generation instruction; scanning the source file to obtain preset annotations in the source file; based on the preset annotations, performing template rendering on the template file to generate a target file corresponding to the file generation instruction.

2. The method according to claim 1, characterized in that, the performing template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction includes: performing template rendering on the template file based on the preset annotations to obtain a rendered file corresponding to the template file; obtaining the file format requirements corresponding to the target search engine, and performing file format adjustment on the rendered file based on the file format requirements to obtain the target file.

3. The method according to claim 2, characterized in that, the rendered file includes a definition file and a constant file, and the template file includes a definition template file and a constant template file; the performing template rendering on the template file based on the preset annotations to obtain a rendered file corresponding to the template file includes: parsing the preset annotations to obtain annotation information corresponding to the preset annotations; respectively screening out a first variable item in the definition template file and a second variable item in the constant template file; based on the annotation information, respectively determining a first target value corresponding to the first variable item and a second target value corresponding to the second variable item; performing template rendering on the definition template file according to the first target value to obtain the definition file; performing template rendering on the constant template file according to the second target value to obtain the constant file.

4. The method according to claim 3, characterized in that, the parsing the preset annotations to obtain annotation information corresponding to the preset annotations includes: traversing the preset annotations to obtain meta-annotations corresponding to the preset annotations; parsing the meta-annotations to obtain meta-annotation information corresponding to the meta-annotations; if the meta-annotation information includes sub-annotations, updating the meta-annotations to the sub-annotations, and returning to the step: parsing the meta-annotations to obtain meta-annotation information corresponding to the meta-annotations; if the meta-annotation information does not include sub-annotations, using the meta-annotation information as the annotation information.

5. The method according to claim 1, characterized in that, before the step of responding to a file generation instruction for a target search engine, the method further includes: obtaining the source code corresponding to the target search engine; creating the preset annotations according to business requirements and annotation scopes; adding the preset annotations to a specified position in the source code to obtain a source file corresponding to the target search engine.

6. The method according to claim 1, characterized in that, before the step of scanning the source file to obtain preset annotations in the source file, the method further includes: Perform data integrity verification on the source file to obtain a data integrity verification result; The scanning of the source file to obtain the preset annotations in the source file includes: If the data integrity verification result is passed, scan the source file to obtain the preset annotations in the source file.

7. A file generation device, Characterized in that, The device includes: An instruction response module, configured to respond to a file generation instruction for a target search engine and obtain a source file and a template file corresponding to the file generation instruction; An annotation acquisition module, configured to scan the source file to obtain the preset annotations in the source file; A file generation module, configured to perform template rendering on the template file based on the preset annotations to generate a target file corresponding to the file generation instruction.

8. A computer device, including a memory and a processor, the memory storing a computer program, Characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, having a computer program stored thereon, Characterized in that, When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product, including a computer program, Characterized in that, When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.