Inverted index processing method and device for searching database, medium and equipment

By using memory and disk, write-ahead logs and background threads to manage the inverted index structure in the search database, it solves the problem of the Lucene engine being unable to achieve real-time search and the inflexible inverted index structure, achieving real-time search and efficient search efficiency.

CN118708671APending Publication Date: 2024-09-27INFINI DATA (BEIJING) TECHNOLOGY CO LTD

Patent Information

Application Number
CN202410841518.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

The Lucene search engine cannot implement real-time search, and its inverted index and forward index are not logically separated. As a result, search can only be performed after the document is placed, which lacks flexibility.

Method used

By introducing memory and disk, write-ahead logs and background threads into the search database, two inverted index structures that can be searched in real time are created, the write-ahead log is used for data persistence, and the data source is switched and updated when the data volume reaches the threshold. The inverted index structure ensures the real-time performance and flexibility of the inverted index.

Benefits of technology

It realizes real-time search, avoids the problem that search can only be performed after placing the order, improves search efficiency, and logically separates the forward index and the inverted index, enhancing the flexibility of processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708671A
    Figure CN118708671A
Patent Text Reader

Abstract

The invention discloses an inverted index processing method and device for searching a database, a medium and equipment, and the method comprises the steps: writing a text type field in a document into a first inverted index structure of a latest data source memory, and writing the document into a pre-writing log at the same time; and when it is monitored that the document is written into the pre-writing log, the background thread creates a third inverted index structure and writes the text type field. When the first inverted index structure reaches a data volume threshold value, the first inverted index structure stops writing and notifies the third inverted index structure to be also created to the same position in the pre-writing log, the created third inverted index structure is written into a data source disk, a new data source is created after reading is completed after writing is completed, and data source switching is conducted. According to the method and the device, the text type field can be written into the specially designed inverted index structure, so that the process of only processing the inverted index is very flexible. And meanwhile, the created inverted index structure can be searched in real time, so that the search efficiency is also effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a method, device, medium and equipment for processing an inverted index of a search database. Background Art

[0002] Lucene is an open source search engine library used by many search engines. In Lucene's terms, a segment is the smallest unit for writing and searching. When a new document is added, a new segment is created for the document in memory. The corresponding content can only be searched after the segment in memory is written to disk. It can be seen that Lucene cannot perform real-time search. Lucene's memory only serves as a cache for accumulated batches, and searches can only be performed on segments that have been written to disk.

[0003] And when searching the added documents, the forward index and inverted index created based on the documents will be operated at the same time, that is, the forward index and inverted index are not separated logically, so there is a lack of flexibility when only processing the inverted index. Summary of the invention

[0004] Based on this, it is necessary to provide an inverted index processing method, device, medium and equipment for searching a database to solve the problem that a single search of an inverted index structure lacks flexibility and can only be performed after the document is stored on disk.

[0005] A method for processing an inverted index of a search database, wherein the search database includes a memory, a disk, a write-ahead log, and a background thread. The data in the memory and the disk are used as data sources, and the atomic quantity tracks the latest data source. In the process of continuous data writing, a new data source will be created, and the version of the data source will increase accordingly, and the atomic quantity will be updated accordingly. Two inverted index structures that can be searched in real time are initially created in the memory as the first data source, and the atomic quantity initially tracks the first data source. The method includes:

[0006] Get the uploaded document;

[0007] Writing the text type field in the document into the first inverted index structure of the latest data source memory tracked by the atomic quantity, and writing the document into the write-ahead log; wherein the first inverted index structure is the inverted index structure currently written into the two inverted index structures in the data source, and the second inverted index structure is the inverted index structure currently not written into the two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure;

[0008] When the background thread detects that a document is written to the write-ahead log, a third inverted index structure is created through the background thread, and the text type field in the document is written into the created third inverted index structure;

[0009] When the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the write-ahead log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure, and the first inverted index structure is removed. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

[0010] In one embodiment, the search database further includes a search engine, and the method further includes:

[0011] If a real-time search request from a client is received during the writing process of the text type field, the search engine accesses the latest data source through atomic quantities and creates a snapshot of the data source. The snapshot maintains the state of the search engine when accessing the data source. The search engine synchronously accesses the memory and the disk in the snapshot to read the inverted index structure corresponding to the real-time search request in the memory and search to obtain a first search result, and reads the inverted index structure corresponding to the real-time search request in the disk and searches to obtain a second search result;

[0012] The first search result and the second search result are combined to obtain a real-time search response, and the real-time search response is fed back to the client.

[0013] In one of the embodiments, the method further includes: creating a snapshot based on the latest data source accessed by the search engine, the data source will be switched, a new data source will be created, and the old data source will be deleted after the switch and all searches for creating snapshots of the old data source are completed.

[0014] In one embodiment, writing the text type field in the document into the first inverted index structure in the latest data source memory includes:

[0015] Segmenting the text type field to obtain multiple terms;

[0016] Based on the multiple terms, multiple term mapping relationships are created; wherein each term mapping relationship is used to map the relationship between a term and a temporary number added when the document changes state, the document changes state when it is written, updated, or deleted, and the temporary number is added to the term mapping relationship to which the changed term belongs, and whenever the document changes state, the added temporary number is +1, and the initial added temporary number is 0;

[0017] Creating a first number mapping relationship from a temporary number to a document number; wherein the first number mapping relationship is used to indicate the document number of the changed document each time a state of the document changes;

[0018] Creating a second number mapping relationship from a document number to a temporary number; wherein the second number mapping relationship is used to indicate at least one temporary number corresponding to a document of each document number and whether the document is deleted each time its status changes;

[0019] The created multiple term mapping relationships, the first number mapping relationship, and the second number mapping relationship are used as the first inverted index structure.

[0020] In one embodiment, the method further comprises:

[0021] When searching for a target term, the plurality of term mapping relationships are read, and a temporary number is obtained from the term mapping relationship corresponding to the target term as a target temporary number;

[0022] Reading the first number mapping relationship, and obtaining the document number corresponding to the target temporary number from the first number mapping relationship as the target document number;

[0023] Reading the second number mapping relationship, and determining whether the last state change of the target document was due to deletion;

[0024] If the last state change of the target document was due to deletion, it is determined that the target term is not in the target document; if the last state change of the target document was not due to deletion, it is determined whether the target temporary number is equal to the maximum value of the temporary numbers corresponding to the target document;

[0025] If the target temporary number is equal to the maximum value of the temporary numbers corresponding to the target document, it is determined that the target term is in the target document; if the target temporary number is not equal to the maximum value of the temporary numbers corresponding to the target document, it is determined that the target term is not in the target document.

[0026] In one embodiment, writing the text type field in the document into a first inverted index structure in a memory in a data source and writing the document into a write-ahead log includes:

[0027] After the field-level real-time processing function is turned on, determining the real-time field and the non-real-time field in the text type field;

[0028] The real-time fields in the text type fields are written into the first inverted index structure in the memory of the data source, and the real-time fields and non-real-time fields in the text type fields are written into the write-ahead log.

[0029] In one embodiment, the method further comprises:

[0030] When a real-time search is performed on a non-real-time field, if an accurate search result is not required, the corresponding inverted index structure is read from the disk in the data source and searched;

[0031] If accurate search results are required, the document is read from the inverted index structure of the disk and the write-ahead log in the data source and searched.

[0032] An inverted index processing device for a search database, the search database includes a memory, a disk, a pre-write log and a background thread, the data in the memory and the disk are used as data sources, the atomic quantity tracks the latest data source, in the process of data being continuously written, a new data source will be created, the version of the data source increases accordingly, and the atomic quantity is updated accordingly, two inverted index structures that can be searched in real time are initially created in the memory as a first data source, the atomic quantity initially tracks the first data source, and the inverted index processing device for the search database includes:

[0033] A first writing module is used to obtain an uploaded document; and write a text type field in the document into a first inverted index structure in the memory of the latest data source tracked by the atomic quantity, and write the document into a pre-write log; wherein the first inverted index structure is the inverted index structure currently written into the two inverted index structures in the data source, and the second inverted index structure is the inverted index structure currently not written into the two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure;

[0034] The second writing module is used to create a third inverted index structure through the background thread when the background thread detects that a document is written to the pre-write log, and write the text type field in the document into the created third inverted index structure; and when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the pre-write log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. On the basis of the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure, the current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity tracking the latest data source is atomically updated.

[0035] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor executes the steps of the above-mentioned inverted index processing method for searching a database.

[0036] A device for processing an inverted index of a search database comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the inverted index processing method of the search database.

[0037] The present invention provides an inverted index processing method, device, medium and equipment for searching a database, which writes a text type field in a document into a first inverted index structure in the memory of the latest data source, and writes the document into a pre-write log at the same time. When it is detected that a document is written in the pre-write log, a background thread creates a third inverted index structure and writes the text type field. When the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the pre-write log, the created third inverted index structure is written to the disk, and a second data source is created after the disk is written and can be read. Based on the first data source, the second data source includes a third inverted index structure, removes the first inverted index structure, and uses the current second inverted index structure as the updated first inverted index structure, and creates a new inverted index structure as the updated second inverted index structure. At this time, the new data source is created, and the atomic quantity tracking the latest data source is atomically updated. In the present invention, the forward index and the inverted index are logically separated, and the text type field will be written into the specially designed inverted index structure, so it is very flexible in the process of only processing the inverted index. At the same time, the created inverted index structure can be searched in real time, which also avoids the search only after the disk is written, effectively improving the search efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0039] in:

[0040] Figure 1 It is a flowchart of the inverted index processing method of searching a database in the first embodiment;

[0041] Figure 2 The overall processing flow of the inverted index;

[0042] Figure 3 A schematic diagram of a process of writing a document into the first inverted index structure of the latest data source memory and writing the document into a write-ahead log;

[0043] Figure 4 A schematic diagram of the process of detecting and creating a third inverted index structure for documents in a background thread;

[0044] Figure 5A schematic diagram of a process of creating a new data source to write the created third inverted index structure into the disk;

[0045] Figure 6 A schematic diagram of the process of switching data sources and coexistence of two data sources;

[0046] Figure 7 A schematic diagram of the process of searching a database;

[0047] Figure 8 It is a flowchart of the inverted index processing method of searching a database in the second embodiment;

[0048] Fig. 9 Schematic diagram of the inverted index structure;

[0049] Fig.10 This is a schematic diagram of the inverted index structure after writing "Hello Pizza" in target document 1;

[0050] Fig.11 A schematic diagram of the inverted index structure after updating "Hello Pizza" in target document 1 to "Hello World";

[0051] Fig.12 This is a schematic diagram of the inverted index structure after deleting the target document 1;

[0052] Fig.13 A schematic diagram of the structure of an inverted index processing device for searching a database;

[0053] Fig.14 A structural block diagram of an inverted index processing device for searching a database. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0055] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0056] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0057] like Figure 1 As shown, Figure 1 FIG. 1 is a flow chart of the inverted index processing method for searching a database in the first embodiment. Figure 2 As shown, Figure 2 The overall processing flow of the inverted index. Optionally, we name the search database Pizza, which includes data source memory and disk, write-ahead log WAL and background thread. Among them, two inverted index structures that can be searched in real time are initially created in the data source memory, and the data source disk will also write inverted index structures that can be searched in real time during subsequent processing. In this embodiment, these created inverted index structures have two characteristics, one is that they can be searched in real time, and the other is that they are separated from other indexes such as forward indexes, and only support writing content related to inverted indexes.

[0058] The steps provided by the inverted index processing method for searching a database in the first embodiment include:

[0059] S101, obtain the uploaded document.

[0060] Optionally, the search database can obtain uploaded documents through a user interface, an application program interface, batch import, or integration with a third-party service, etc. The specific method used depends on the design and usage scenario of the database.

[0061] S102, writing the text type field in the document into the first inverted index structure of the latest data source memory tracked by the atomic quantity, and writing the document into the pre-write log.

[0062] The first inverted index structure is the inverted index structure currently written into the two inverted index structures, the second inverted index structure is the inverted index structure currently not written into the two inverted index structures, and the first inverted index structure has the same structure as the second inverted index structure.

[0063] First, we will determine which text fields are text in the document, and then only write these text fields into the first inverted index structure in memory. Other types of fields, such as vector fields, will not be written into the first inverted index structure in memory.

[0064] like Figure 3 As shown, in this embodiment, the inverted index structure of the latest data source memory is called RealtimeInverted index. The writing speed of Realtime Inverted index is very fast, and it can be a hash table, a skip table or other types of data structures. Here, since Realtime Inverted index1 is currently written, RealtimeInverted index1 serves as the first inverted index structure. Realtime Inverted index2 is not currently written, so Realtime Inverted index2 serves as the second inverted index structure. It can be understood that when executing this step, the two inverted index structures Realtime Inverted index1 and Realtime Inverted index2 can be searched in real time, but only the first inverted index structure Realtime Inverted index1 has content written, so valid content will only be output when Realtime Inverted index1 is queried.

[0065] At the same time, we write the complete document to the Write-Ahead Log (WAL), which is used as a transit station to temporarily save text type fields. The advantage of this is that even if a system crash or power outage occurs before the data is written to the disk, the search database Pizza can still recover the operation based on the information in the write-ahead log, thus ensuring the consistency and durability of the database.

[0066] S103: When the background thread detects that a document is written into the write-ahead log, a third inverted index structure is created through the background thread, and the text type field in the document is written into the created third inverted index structure.

[0067] like Figure 4 As shown, there is a background thread in the system responsible for monitoring the write operations in the write-ahead log, and when it is detected that a text type field is written, a third inverted index structure is created for these text type fields.

[0068] It can be understood that when this step is performed, both the two inverted index structures Realtime Inverted index1 and Realtime Inverted index2 can be searched in real time.

[0069] S104, when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the write-ahead log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

[0070] Specifically, after being filled (ie, the amount of written data reaches a threshold), the first inverted index structure Realtime Inverted index1 becomes immutable. The immutable first inverted index structure Realtime Inverted index1 can no longer carry writing, but can carry searching.

[0071] When the amount of data written to the first inverted index structure reaches a threshold, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same location in the write-ahead log, and writes the third inverted index structure to disk for persistence. Therefore, the third inverted index structure has the same structure and written content as the first inverted index structure, thereby maintaining data consistency and integrity. Figure 5 As shown in the figure, the search database Pizza will write the created third inverted index structure to the disk to store the data for a long time. At this time, the new data source, that is, the second data source, is created. Figure 6 As shown, the atomic quantity that tracks the latest data source is updated to track the second data source. The previous first data source is not deleted immediately.

[0072] like Figure 5As shown, after the third inverted index structure is completely written to the disk, an inverted archive file Archive Inverted index that can be searched in real time will be formed. The inverted archive file Archive Inverted index has a high compression rate and high-performance reading capability, and is particularly suitable for storing large-scale structured data. From the above example, we can find that the inverted index structure realtime Inverted index and the archive file Archive Inverted index to be generated on the disk are one-to-one corresponding. Further, after the disk is written and can be read, a second data source is created. On the basis of the first data source, it contains the newly written Archive Inverted index to the disk, removes realtime Inverted index1, and uses the current second inverted index structure realtime Inverted index2 as the updated first inverted index structure realtime Inverted index2, and creates a new inverted index structure as the updated second inverted index structure realtime Inverted index3 to receive subsequent new document writing. It can be seen that in the whole process, there are always 2 inverted index structures realtime Inverted index. The old inverted index structure is written to the disk and becomes an archive file, and new inverted index structures are constantly created.

[0073] Furthermore, in a specific embodiment, the search database further includes a search engine Query Engine, which is responsible for processing the search request of the client. On this basis, the search database also performs the following steps: Figure 7 As shown, during the writing process of the text type field, if a real-time search request request is received from the client, the search engine QueryEngine accesses the latest data source through atomic quantities and creates a snapshot of the data source. The search engine synchronously accesses the memory and disk in the snapshot to read the inverted index structure corresponding to the real-time search request in the memory and search to obtain the first search result, and reads the inverted index structure corresponding to the real-time search request in the disk and searches to obtain the second search result; then the first search result and the second search result are merged to obtain a real-time search response, and finally the real-time search response is fed back to the client.

[0074] In this way, the search database can respond to the client's search request and return the result in a timely manner for searches that only require an inverted index. And because the search results in the memory and disk are summarized, the feedback to the client will not be missed.

[0075] Furthermore, the creation of the snapshot is based on the latest data source accessed by the search engine. The data source will be switched, a new data source will be created, and the old data source will be deleted after the switch and all searches for creating snapshots of the old data source are completed.

[0076] The inverted index processing method of the above-mentioned search database writes the text type field in the document into the first inverted index structure in the memory of the latest data source, and writes the document into the pre-write log at the same time. When it is detected that there is a document written in the pre-write log, the background thread creates a third inverted index structure and writes the text type field. When the amount of data written to the first inverted index structure reaches the threshold, the data source is ready to switch, update the latest data source, stop writing the first inverted index structure and notify the third inverted index structure to be created at the same position in the pre-write log, write the created third inverted index structure to the disk, and create a second data source after the disk is written and can be read. On the basis of the first data source, the second data source includes the third inverted index structure, removes the first inverted index structure, and uses the current second inverted index structure as the updated first inverted index structure, and creates a new inverted index structure as the updated second inverted index structure. At this time, the new data source is created, and the atomic quantity tracking the latest data source is atomically updated. In the present invention, the forward index and the inverted index are logically separated, and the text type field will be written into the specially designed inverted index structure, so it is very flexible in the process of only processing the inverted index. At the same time, the created inverted index structure can be searched in real time, which also avoids the search only after the disk is written, effectively improving the search efficiency.

[0077] Furthermore, considering that the real-time framework of the search database Pizza depends on the memory structure, that is, the inverted index structure must be created in the memory to support real-time, the cost of this is that the memory usage will increase. At the same time, in some scenarios, users may only have real-time search requirements for certain fields. Therefore, in a specific embodiment, S102 can be optimized as follows: after the field-level real-time processing function is turned on, determine the real-time fields and non-real-time fields in the text type field; write the real-time fields in the text type field into the first inverted index structure of the latest data source memory, and write the real-time fields and non-real-time fields in the text type field into the pre-write log.

[0078] Specifically, after the field-level real-time processing function is turned on, the search database Pizza will determine which fields in the text type field need real-time search (corresponding to real-time fields) and which fields do not need real-time search (corresponding to non-real-time fields). For example, it can be determined by entering the real-time mark in the text type field. Fields with real-time marks are real-time fields, and fields without real-time marks are non-real-time fields. Or analyze the frequency of data changes in each field. If the value of a field changes frequently and needs to be reflected in the search results in real time, then this field may require real-time search. On the contrary, if the data of a field changes less or the changes have little effect on the search results, then it can be considered that real-time search is not needed. Then, only these real-time fields are written to the first inverted index structure in the memory, and both real-time fields and non-real-time fields are written to the pre-write log.

[0079] It is understandable that the benefit of this treatment is that it can reduce memory usage and improve system performance and stability. For users who only have real-time search requirements for some fields, they can flexibly configure as needed to save memory resources.

[0080] Furthermore, in a specific embodiment, the following steps are also performed: when performing a real-time search on a non-real-time field, if an accurate search result is not required, the corresponding inverted index structure is read from the disk of the data source snapshot and the search is performed; if an accurate search result is required, the document is read from the inverted index structure and pre-write log on the disk of the data source snapshot and the search is performed.

[0081] Specifically, after the field-level real-time processing function is turned on, searches can be roughly divided into two categories: 1. Searches involving real-time fields; 2. Searches involving non-real-time fields. Among them, the process of searches involving real-time fields will not change after the field-level real-time processing function is turned on, so it will not be described in detail for the time being. For searches involving non-real-time fields, users can configure whether accurate results are required as needed. If accurate results are not required, the search database Pizza will read the corresponding inverted index structure from the disk and search. Those fields that are non-real-time and whose index structure is not written to the disk will not be searched. If accurate results are required, since the complete data is saved in the write-ahead log, the search database Pizza will obtain data from the inverted index structure and write-ahead log on the disk of the data source snapshot and search.

[0082] It is understandable that such a design can flexibly select appropriate data sources for search based on the user's requirements for the accuracy of search results, thereby meeting real-time search needs in different scenarios.

[0083] like Figure 8 As shown, Figure 8The flowchart of the inverted index processing method for searching a database in the second embodiment is shown in FIG. The steps provided by the inverted index processing method for searching a database in the second embodiment include:

[0084] S801, obtain the uploaded document.

[0085] Optionally, the search database can obtain uploaded documents through a user interface, an application program interface, batch import, or integration with a third-party service, etc. The specific method used depends on the design and usage scenario of the database.

[0086] S802, segment the text type field to obtain multiple terms.

[0087] Specifically, we can use a tokenizer to segment text fields. This tool will split the text into terms according to certain rules. By dividing the text content into multiple terms, search engines can locate relevant documents more accurately.

[0088] For example, if there is a text type field: "The quick brown fox jumps over the lazy dog.", the possible terms after word segmentation include: "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog".

[0089] S803, creating multiple term mapping relationships based on multiple terms.

[0090] Among them, each term mapping relationship is used to map the relationship between a term and a temporary number added to the document when the state changes. The state of the document changes when it is written, updated, and deleted. The temporary number is added to the term mapping relationship to which the changed term belongs. Every time the state of the document changes, the added temporary number is +1.

[0091] like Fig. 9 As shown, Fig. 9The diagram is a schematic diagram of the inverted index structure, where the "term->temp docIDs" created on the left is the term mapping relationship, term is the term, and temp doc ID is the temporary number. Optionally, the initial added temporary number is 0. Assuming that the written text type field contains the term "quick" but does not contain the term "brown", the term "quick" has changed, while the term "brown" has not changed. On this basis, a temporary number "1" will be added to the term mapping relationship to which the term "quick" belongs (assuming that the temporary number 0 has been added before), and the term mapping relationship to which the term "brown" belongs remains unchanged.

[0092] S804: Create a first number mapping relationship from a temporary number to a document number.

[0093] Among them, Fig. 9 As shown in the lower right side, the first number mapping relationship is used to represent the document number doc ID of the changed document each time the document status changes. It can be understood that each time a document status changes, a new temp doc ID will be generated, so one doc ID can correspond to multiple temp doc IDs, but a temp doc ID can only correspond to one doc ID.

[0094] For example, suppose the document number is 1, and the text type field written in it contains the terms "quick" and "brown". Then the document has changed, and its terms need to be added to the term mapping relationship. Since the two terms belong to the same document, the temp doc ID is the same, which is assumed to be 1. At the same time, suppose the document number is 1, and the first number mapping relationship created is "1→1". On this basis, suppose we delete document 1 again, and the status of document 1 has changed. At this time, temp doc ID=2 will be generated, and we will create another first number mapping relationship of "2→1".

[0095] S805: Create a second number mapping relationship from the document number to the temporary number.

[0096] Among them, Fig. 9 As shown in the upper right side, the second number mapping relationship is used to indicate at least one temporary number corresponding to each document number and whether the document is deleted each time its status changes. The second number mapping relationship needs to record two parts, one is the "tempdoc ID" corresponding to the doc ID, and the other is whether the "tempdoc ID" corresponding to the doc ID is deleted. If "yes", mark it with "true", if "no", mark it with "false".

[0097] For example, assume that the document numbered 1 has the terms "quick" and "brown" in its first written text type field, and then the document 1 is deleted. Then the created second number mapping relationship is expressed as: "1→[(0, false)][(1, true)]".

[0098] S806: Use the created multiple term mapping relationships, the first number mapping relationship, and the second number mapping relationship as the first inverted index structure.

[0099] S807: When the background thread detects that a document is written into the write-ahead log, a third inverted index structure is created through the background thread, and the text type field in the document is written into the created third inverted index structure.

[0100] S808, when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the write-ahead log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

[0101] In a specific embodiment, the above steps S807-S808 are substantially the same as steps S103-S104 of the inverted index processing method for searching a database in the first embodiment, and thus are not described in detail here.

[0102] S809, when searching for a target term, read multiple term mapping relationships, and obtain a temporary number from the term mapping relationship corresponding to the target term as a target temporary number.

[0103] S810, reading the first number mapping relationship, and obtaining the document number corresponding to the target temporary number from the first number mapping relationship as the target document number.

[0104] S811, read the second number mapping relationship, and determine whether the target document was deleted when the last state was changed. If the target document was deleted when the last state was changed, execute S812 to determine that the target term is not in the target document; if the target document was not deleted when the last state was changed, execute S813.

[0105] S813, determine whether the target temporary number is equal to the maximum value of the temporary numbers corresponding to the target document. If the target temporary number is equal to the maximum value of the temporary numbers corresponding to the target document, execute S814 to determine that the target term is in the target document; if the target temporary number is not equal to the maximum value of the temporary numbers corresponding to the target document, execute S812 to determine that the target term is not in the target document.

[0106] To facilitate understanding of the above steps S810-S815, a specific example is provided below for explanation:

[0107] First we create the document:

[0108]

[0109] Among them, doc is the text type field text. After the text type field is segmented, "Hello" and "Pizza" are obtained. The document number doc ID is 1. This document creation makes the temp doc ID 0. On this basis, the inverted index structure we create is as follows Fig.10 shown.

[0110] Assuming that we want to find the document containing the target term "Pizza", we check the term mapping relationship and find that the temp doc ID corresponding to the term "Pizza" is 0, so 0 is used as the target temporary number. Through the first number mapping relationship, we find that the document number doc ID corresponding to the target temporary number 0 is 1, so 1 is used as the target document number. Then, we check the second number mapping relationship and find that the last state change of target document 1 was not caused by deletion, and the target temporary number 0 is equal to the maximum value 0 among the temporary numbers corresponding to target document 1, so S812 is executed to determine that the target term "Pizza" is in target document 1.

[0111] Furthermore, suppose the user updates the target document 1:

[0112]

[0113] We segment the doc field again to get "Hello" and "World", and add them to the inverted index structure. The inverted index structure we created is as follows: Fig.11 shown.

[0114] Query the target document 1 containing the target term "Pizza" again. In the term mapping relationship, we find that the target temporary number temp doc ID of the target term "Pizza" is 0. Then, in the first number mapping relationship, we find that the target document number doc ID corresponding to tempdoc ID 0 is 1. Then, in the second number mapping relationship, we find that the last state change of target document 1 was not caused by deletion, and the target temporary number 0 is not equal to the maximum value 1 of the temporary numbers corresponding to the target document, so S812 is executed to determine that the target term "Pizza" is not in the target document 1.

[0115] If we query the target document containing the target term "Hello", in the term mapping relationship, we find that the temporary numbers in the target term "Hello" are 0 and 1. Then, in the first number mapping relationship, we find that temp docID 0 corresponds to target document 1, and tempdoc ID 1 corresponds to target document 1. Then, in the second number mapping relationship, we find that the last state change of target document 1 was not caused by deletion, and the maximum temporary number is 1, which matches 1 but not 0. Therefore, S812 is executed for temporary number 0, and S814 is executed for temporary number 1, so "hello" is in target document 1.

[0116] Furthermore, suppose the user deletes the document with ID 1:

[0117] DELETE / _index / _doc / 1

[0118] On this basis, we create an inverted index structure as follows Fig.12 shown.

[0119] If we query the target term "World", in the term mapping relationship, we find that the largest temporary number in the target term "World" is 1, so the target temporary number temp doc ID of the target term "World" is 1. Then, in the first number mapping relationship, we find that the target document number doc ID corresponding to temp doc ID 1 is 1. Finally, in the second number mapping relationship, we find that the last state change of target document 1 was caused by deletion, so S812 is executed to determine that the target term "Hello" is not in target document 1.

[0120] In one embodiment, Fig.13 As shown, an inverted index processing device for a search database is proposed. The search database includes a data source memory and a disk, a pre-write log, and a background thread. Two inverted index structures that can be searched in real time are initially created in the memory. The device includes:

[0121] The first writing module 1301 is used to obtain the uploaded document; and write the text type field in the document into the first inverted index structure of the latest data source memory tracked by the atomic quantity, and write the document into the pre-write log; wherein the first inverted index structure is the inverted index structure currently written in the two inverted index structures in the data source, and the second inverted index structure is the inverted index structure currently not written in the two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure;

[0122] The second writing module 1302 is used to create a third inverted index structure through the background thread when the background thread detects that a document is written in the pre-write log, and write the text type field in the document into the created third inverted index structure; and when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, update the latest data source, stop writing to the first inverted index structure and notify the third inverted index structure to be created at the same position in the pre-write log, write the created third inverted index structure to the disk, and create a second data source after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

[0123] Fig.14 FIG. 1 shows an internal structure diagram of an inverted index processing device for searching a database in an embodiment. Fig.14 As shown, the inverted index processing device for searching a database includes a processor, a memory, and a network interface connected via a system bus. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the inverted index processing device for searching a database stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor may implement the inverted index processing method for searching a database. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor may execute the inverted index processing method for searching a database. Those skilled in the art will appreciate that Fig.14 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present application, and does not constitute a limitation on the inverted index processing device of the search database to which the scheme of the present application is applied. The specific inverted index processing device of the search database may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0124] A computer-readable storage medium stores a computer program, which implements the following steps when executed by a processor: obtaining an uploaded document; writing a text type field in the document into a first inverted index structure of the latest data source memory tracked by atomic quantity, and writing the document into a pre-write log; wherein the first inverted index structure is an inverted index structure currently written in two inverted index structures in the data source, and the second inverted index structure is an inverted index structure currently not written in two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure; when a background thread detects that a document is written in the pre-write log, a third inverted index structure is created through the background thread, and the text type field in the document is written into the first inverted index structure of the latest data source memory tracked by atomic quantity, and the document is written into a pre-write log; wherein the first inverted index structure is an inverted index structure currently not written in two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure; when a background thread detects that a document is written in the pre-write log, a third inverted index structure is created through the background thread, and the text type field in the document is written into the first inverted index structure of the latest data source memory tracked by atomic quantity, and the document is written into the pre-write log; wherein the first inverted index structure is an inverted index structure currently not written in two inverted index structures in the data source, and the text type field in the document is written into the first inverted index structure of the pre-write log; wherein ... The created third inverted index structure is written; when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the write-ahead log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

[0125] A device for processing an inverted index of a search database comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: obtaining an uploaded document; writing a text type field in the document into a first inverted index structure of a memory of a latest data source tracked by an atomic quantity, and writing the document into a pre-write log; wherein the first inverted index structure is an inverted index structure currently written into two inverted index structures in the data source, and the second inverted index structure is an inverted index structure currently not written into two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure; when a background thread detects that a document is written into the pre-write log, a third inverted index structure is created through the background thread, and Write the text type field in the document into the created third inverted index structure; when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, update the latest data source, stop writing to the first inverted index structure and notify the third inverted index structure to be created at the same position in the write-ahead log, write the created third inverted index structure to the disk, and create a second data source after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

[0126] It should be noted that the above-mentioned inverted index processing method, device, equipment and computer-readable storage medium for searching a database belong to a general inventive concept, and the contents in the embodiments of the inverted index processing method, device, equipment and computer-readable storage medium for searching a database are applicable to each other.

[0127] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0128] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0129] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for processing an inverted index of a search database, characterized in that: The search database includes memory, disk, write-ahead log and background thread. The data in the memory and disk are used as data sources. The atomic quantity tracks the latest data source. In the process of continuous data writing, a new data source will be created, and the version of the data source will increase accordingly. The atomic quantity is updated accordingly. Two inverted index structures that can be searched in real time are initially created in the memory as the first data source. The atomic quantity initially tracks the first data source. The method includes: Get the uploaded document; Writing the text type field in the document into the first inverted index structure of the latest data source memory tracked by the atomic quantity, and writing the document into the write-ahead log; wherein the first inverted index structure is the inverted index structure currently written into the two inverted index structures in the data source, and the second inverted index structure is the inverted index structure currently not written into the two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure; When the background thread detects that a document is written to the write-ahead log, a third inverted index structure is created through the background thread, and the text type field in the document is written into the created third inverted index structure; When the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the write-ahead log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. Based on the first data source, the second data source includes the third inverted index structure, and the first inverted index structure is removed. The current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity that tracks the latest data source is atomically updated.

2. The method according to claim 1, characterized in that The search database also includes a search engine, and the method further includes: If a real-time search request from a client is received during the writing process of the text type field, the search engine accesses the latest data source through atomic quantities and creates a snapshot of the data source. The snapshot maintains the state of the search engine when accessing the data source. The search engine synchronously accesses the memory and the disk in the snapshot to read the inverted index structure corresponding to the real-time search request in the memory and search to obtain a first search result, and reads the inverted index structure corresponding to the real-time search request in the disk and searches to obtain a second search result; The first search result and the second search result are combined to obtain a real-time search response, and the real-time search response is fed back to the client.

3. The method according to claim 2, characterized in that The method further includes: creating a snapshot based on the latest data source accessed by the search engine, the data source will be switched, a new data source will be created, and the old data source will be deleted after the switch and all searches for creating snapshots of the old data source are completed.

4. The method according to claim 1 or 2, characterized in that: The step of writing the text type field in the document into the first inverted index structure of the latest data source memory tracked by the atomic quantity includes: Segmenting the text type field to obtain multiple terms; Based on the multiple terms, multiple term mapping relationships are created; wherein each term mapping relationship is used to map the relationship between a term and a temporary number added when the document changes state, the document changes state when it is written, updated, or deleted, and the temporary number is added to the term mapping relationship to which the changed term belongs, and whenever the document changes state, the added temporary number is +1, and the initial added temporary number is 0; Creating a first number mapping relationship from a temporary number to a document number; wherein the first number mapping relationship is used to indicate the document number of the changed document each time a state of the document changes; Creating a second number mapping relationship from a document number to a temporary number; wherein the second number mapping relationship is used to indicate at least one temporary number corresponding to a document of each document number and whether the document is deleted each time its status changes; The created multiple term mapping relationships, the first number mapping relationship, and the second number mapping relationship are used as the first inverted index structure.

5. The method according to claim 4, characterized in that The method further comprises: When searching for a target term, the plurality of term mapping relationships are read, and a temporary number is obtained from the term mapping relationship corresponding to the target term as a target temporary number; Reading the first number mapping relationship, and obtaining the document number corresponding to the target temporary number from the first number mapping relationship as the target document number; Reading the second number mapping relationship, and determining whether the last state change of the target document was due to deletion; If the last state change of the target document was due to deletion, it is determined that the target term is not in the target document; if the last state change of the target document was not due to deletion, it is determined whether the target temporary number is equal to the maximum value of the temporary numbers corresponding to the target document; If the target temporary number is equal to the maximum value of the temporary numbers corresponding to the target document, it is determined that the target term is in the target document; if the target temporary number is not equal to the maximum value of the temporary numbers corresponding to the target document, it is determined that the target term is not in the target document.

6. The method according to claim 1, characterized in that The text type field in the document is written into the first inverted index structure of the latest data source memory tracked by the atomic quantity, and the document is written into the pre-write log: After the field-level real-time processing function is turned on, determining the real-time field and the non-real-time field in the text type field; The real-time fields in the text type fields are written into the first inverted index structure in the memory of the data source, and the real-time fields and non-real-time fields in the text type fields are written into the write-ahead log.

7. The method according to claim 6, characterized in that The method further comprises: When a real-time search is performed on a non-real-time field, if an accurate search result is not required, the corresponding inverted index structure is read from the disk in the data source and searched; If accurate search results are required, the document is read from the inverted index structure of the disk and the write-ahead log in the data source and searched.

8. An inverted index processing device for searching a database, characterized in that: The search database includes memory, disk, write-ahead log and background thread. The data in the memory and disk are used as data sources. The atomic quantity tracks the latest data source. In the process of continuous data writing, a new data source will be created, the version of the data source will increase accordingly, and the atomic quantity will be updated accordingly. Two inverted index structures that can be searched in real time are initially created in the memory as the first data source. The atomic quantity initially tracks the first data source. The inverted index processing device of the search database includes: A first writing module is used to obtain an uploaded document; and write a text type field in the document into a first inverted index structure in the memory of the latest data source tracked by the atomic quantity, and write the document into a pre-write log; wherein the first inverted index structure is the inverted index structure currently written into the two inverted index structures in the data source, and the second inverted index structure is the inverted index structure currently not written into the two inverted index structures in the data source, and the first inverted index structure has the same structure as the second inverted index structure; The second writing module is used to create a third inverted index structure through the background thread when the background thread detects that a document is written to the pre-write log, and write the text type field in the document into the created third inverted index structure; and when the amount of data written to the first inverted index structure reaches a threshold, the data source is ready to switch, the latest data source is updated, the first inverted index structure stops writing and notifies the third inverted index structure to be created at the same position in the pre-write log, the created third inverted index structure is written to the disk, and the second data source is created after the disk is written and can be read. On the basis of the first data source, the second data source includes the third inverted index structure and removes the first inverted index structure, the current second inverted index structure is used as the updated first inverted index structure, and a new inverted index structure is created as the updated second inverted index structure. When the second data source is created, the atomic quantity tracking the latest data source is atomically updated.

9. A computer-readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 7.

10. An inverted index processing device for searching a database, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Positive index processing method and device for searching database, medium and equipment

    CN118069590A

Cited By

  • Server log document processing method and device

    CN119441169A

  • Server log file processing method and device

    CN119441169B

  • Method and system for integrating inverted indexes in database and medium

    CN119621877A