A device for modifying a Lucene index file, comprising a processor and a machine readable storage medium which stores machine executable instructions corresponding to a control logic for modifying the Lucene index file, wherein by executing the machine executable instructions, the processor is caused to:
- acquire a target field to be modified, an old term to be modified under the target field and a new term for replacing the old term;
- by traversing every segment in an index folder,
- generate corresponding information of the new term under the target field of the segment according to corresponding information of the old term under the target field of the segment, and
- generate a new index file of the segment based on information under other fields of the segment, and corresponding information of other terms and corresponding information of the new term under the target field of the segment, wherein the other fields comprise all fields except the target field under the segment, the other terms comprise all terms except the new term and the old term under the target field, and the new index file comprises an inverted index file including term information in the Lucene index file;
- and
- replace a corresponding original index file in the index folder with the new index file after processing all segments,
- wherein when generating the new index file of the segment based on the information under other fields of the segment, and the corresponding information of other terms and the corresponding information of the new term under the target field of the segment, the machine executable instructions cause the processor to:
- create a memory space for the new index file to be generated, and write a file header for the new index file according to a fixed format;
- update the new index file according to corresponding information of other terms and corresponding information of the new term under the target field and the information under other fields, by traversing every field under the segment and every term under each field in a lexicographic order;
- and
- write an end-of-file for the new index file according to the fixed format, after processing all terms under all fields of the segment,
- wherein when updating the new index file according corresponding information of other terms and corresponding information of the new term under the target field and the information under other fields, the machine executable instructions cause the processor to:
- in a case where a currently processed field is not the target field, write corresponding information of all terms under the field in the new index file;
- in a case where the field is the target field and a currently processed term under the field is the old term, end a process for the term;
- in a case where the field is the target field but the currently processed term is not the old term and precedes the new term in the lexicographic order, write corresponding information of the currently processed term in the new index file;
- and
- in a case where the field is the target field but the currently processed term is not the old term and follows the new term in the lexicographic order, confirm location information of the new term and after writing corresponding information of the new term in the new index, write corresponding information of the currently processed term in the new index file.