mirror of https://gitee.com/bigwinds/arangodb
62 lines
2.8 KiB
Plaintext
62 lines
2.8 KiB
Plaintext
!CHAPTER Fulltext indexes
|
|
|
|
!SUBSECTION Introduction to Fulltext Indexes
|
|
|
|
This is an introduction to ArangoDB's fulltext indexes.
|
|
|
|
A fulltext index can be used to find words, or prefixes of words inside documents.
|
|
|
|
A fulltext index can be defined on one attribute only, and will include all words contained in
|
|
documents that have a textual value in the index attribute. Since ArangoDB 2.6 the index
|
|
will also include words from the index attribute if the index attribute is an array of
|
|
strings, or an object with string value members.
|
|
|
|
For example, given a fulltext index on the `translations` attribute and the following
|
|
documents, then searching for `лиса` using the fulltext index would return only the
|
|
first document. Searching for the index for the exact string `Fox` would return the first
|
|
two documents, and searching for `prefix:Fox` would return all three documents:
|
|
|
|
{ translations: { en: "fox", de: "Fuchs", fr: "renard", ru: "лиса" } }
|
|
{ translations: "Fox is the English translation of the German word Fuchs" }
|
|
{ translations: [ "ArangoDB", "document", "database", "Foxx" ] }
|
|
|
|
If the index attribute is neither a string, an object or an array, its contents will
|
|
not be indexed. When indexing the contents of an array attribute, an array member will
|
|
only be included in the index if it is a string. When indexing the contents of an object
|
|
attribute, an object member value will only be included in the index if it is a string.
|
|
Other datatypes are ignored and not indexed.
|
|
|
|
!SECTION Accessing Fulltext Indexes from the Shell
|
|
|
|
`collection.ensureFulltextIndex(field, minWordLength)`
|
|
|
|
Creates a fulltext index on all documents on attribute *field*.
|
|
|
|
Fulltext indexes are implicitly sparse: all documents which do not have
|
|
the specified *field* attribute or that have a non-qualifying value in their
|
|
*field* attribute will be ignored for indexing.
|
|
|
|
Only a single attribute can be indexed. Specifying multiple attributes is
|
|
unsupported.
|
|
|
|
The minimum length of words that are indexed can be specified via the *minWordLength*
|
|
parameter. Words shorter than minWordLength characters will not be indexed.
|
|
*minWordLength* has a default value of 2, but this value might be changed in
|
|
future versions of ArangoDB. It is thus recommended to explicitly specify this value.
|
|
|
|
In case the index is successfully created, the index identifier is returned.
|
|
|
|
```
|
|
arangosh> db.emails.ensureFulltextIndex("body");
|
|
{ "id" : "emails/42725508", "unique" : false, "type" : "fulltext", "fields" : ["body"], "isNewlyCreated" : true }
|
|
```
|
|
|
|
Note that in addition to the specialized index creation method, there is also the
|
|
general method `collection.ensureIndex`, which can be used to create indexes of any type:
|
|
|
|
*Examples*
|
|
|
|
```
|
|
arangosh> db.emails.ensureIndex({ type: "fulltext", fields: [ "body" ] });
|
|
```
|