|
| 1 | +# Indexes: Term Vectors |
| 2 | +--- |
| 3 | + |
| 4 | +{NOTE: } |
| 5 | + |
| 6 | +* A [Term Vector](https://en.wikipedia.org/wiki/Vector_space_model) is a representation of a text document |
| 7 | + as a vector of identifiers. |
| 8 | + Lucene indexes can contain term vectors for documents they index. |
| 9 | +* Term vectors can be used for various purposes, including similarity searches, information filtering |
| 10 | + and retrieval, and indexing. |
| 11 | + A book's index, for example, may have term vector enabled on the book's **subject** field, to be able |
| 12 | + to use this field to search for books with similar subjects. |
| 13 | +* RavenDB features like [MoreLikeThis](../client-api/session/querying/how-to-use-morelikethis) leverage |
| 14 | + stored term vectors to accomplish their goals. |
| 15 | + |
| 16 | +* In this page: |
| 17 | + * [Creating an index and enabling Term Vectors on a field](../indexes/using-term-vectors#creating-an-index-and-enabling-term-vectors-on-a-field) |
| 18 | + * [Using the API](../indexes/using-term-vectors#using-the-api) |
| 19 | + * [Using Studio](../indexes/using-term-vectors#using-studio) |
| 20 | + |
| 21 | +{NOTE/} |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +{PANEL: Creating an index and enabling Term Vectors on a field} |
| 26 | + |
| 27 | +Indexes that include term vectors can be created and configured using the API |
| 28 | +or Studio. |
| 29 | + |
| 30 | +## Using the API |
| 31 | + |
| 32 | +To create an index and enable Term Vectors on a specific field, we can - |
| 33 | + |
| 34 | +A. Create an index using the `AbstractIndexCreationTask`, and specify the term vectors there. |
| 35 | +B. Or, we can define our term vectors in the `IndexDefinition` (directly or using the `IndexDefinitionBuilder`). |
| 36 | + |
| 37 | +{CODE-TABS} |
| 38 | +{CODE-TAB:csharp:AbstractIndexCreationTask term_vectors_1@Indexes\TermVectors.cs /} |
| 39 | +{CODE-TAB:csharp:Operation term_vectors_2@Indexes\TermVectors.cs /} |
| 40 | +{CODE-TABS/} |
| 41 | + |
| 42 | +Available Term Vector options include: |
| 43 | + |
| 44 | +{CODE term_vectors_3@Indexes\TermVectors.cs /} |
| 45 | + |
| 46 | +Learn which Lucene API methods and constants are available [here](https://lucene.apache.org/core/3_6_2/api/all/org/apache/lucene/document/Field.TermVector.html). |
| 47 | + |
| 48 | +## Using Studio |
| 49 | + |
| 50 | +Let's use as an example one of Studio's sample indexes, `Product/Search`, that has term vector |
| 51 | +enabled on its `Name` field so a feature like [MoreLikeThis](../client-api/session/querying/how-to-use-morelikethis) |
| 52 | +can use this fiels to select a product and find products similar to it. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +We can now use a query like: |
| 57 | + |
| 58 | +{CODE-BLOCK:sql} |
| 59 | +from index 'Product/Search' |
| 60 | +where morelikethis(id() = 'products/7-A') |
| 61 | +{CODE-BLOCK/} |
| 62 | + |
| 63 | +{PANEL/} |
| 64 | + |
| 65 | +## Related articles |
| 66 | + |
| 67 | +### Indexes |
| 68 | + |
| 69 | +- [Boosting](../indexes/boosting) |
| 70 | +- [Analyzers](../indexes/using-analyzers) |
| 71 | +- [Storing Data in Index](../indexes/storing-data-in-index) |
| 72 | +- [Dynamic Fields](../indexes/using-dynamic-fields) |
| 73 | + |
| 74 | +## External articles |
| 75 | + |
| 76 | +- [Lucene API](https://lucene.apache.org/core/3_6_2/api/all/org/apache/lucene/document/Field.TermVector.html) |
0 commit comments