Indexes

Updated at:

Each document consists of multiple fields, and each field contains a series of terms. Indexes are built to speed up retrieval. Based on the direction of the mapping, indexes can be classified into the following types:

  • Inverted index (index): An inverted index stores the mapping from terms to DocIDs, in the form of term --> (Doc1,Doc2,...,DocN). Inverted indexes are mainly used in retrieval. They allow the engine to quickly locate the documents that correspond to the keywords in a user query.

  • Forward index (attribute): A forward index stores the mapping from DocIDs to fields, in the form of DocID --> (term1,term2,...termn). Forward indexes are classified into single-value and multi-value attributes. A single-value attribute has a fixed length (excluding the STRING type), so lookups are efficient and updates are supported. A multi-value attribute indicates that a field contains multiple values (the number of values is not fixed). Because its length is not fixed, lookups are slower than for single-value attributes, and updates are not supported. Forward indexes are mainly used after a document is found by a query: the engine uses the docid value to quickly obtain the attributes of the document for statistics, sorting, and filtering. The basic forward index field types currently supported by the engine include: INT8 (8-bit signed numeric type), UINT8 (8-bit unsigned numeric type), INT16 (16-bit signed numeric type), UINT16 (16-bit unsigned numeric type), INTEGER (32-bit signed numeric type), UINT32 (32-bit unsigned numeric type), INT64 (64-bit signed numeric type), UINT64 (64-bit unsigned numeric type), FLOAT (32-bit floating-point number), DOUBLE (64-bit floating-point number), and STRING (string type). A multi-value attribute is simply a field that may contain an indefinite number of single-value attributes. For each of the preceding single-value attribute types, the engine supports a corresponding multi-value attribute type, such as multi_int8 and multi_string.

  • Summary (summary): Summaries are stored in a similar way to attributes. However, a summary stores the multiple fields of a document together and builds a mapping for them, so the engine can quickly locate the corresponding summary content from a docid. Summaries are mainly used to display results. Summary content is generally large, so retrieving too many summaries for each query is not recommended. Only the documents whose results are finally displayed have their summaries retrieved. Because summaries are large, the engine provides a compression mechanism for storing them. If summary compression is configured in the schema, the engine compresses summaries by using zlib before storing them. When reading summaries, the engine first decompresses them and then returns them to the user.