The Term Vector Component

The TermVectorComponent is a search component designed to return additional information about documents matching your search.

For each document in the response, the TermVectorCcomponent can return the term vector, the term frequency, inverse document frequency, position, and offset information.

Term Vector Component Configuration

The TermVectorComponent is not enabled implicitly in Solr - it must be explicitly configured in your solrconfig.xml file. The examples on this page show how it is configured in Solr’s “techproducts” example:

bin/solr -e techproducts

To enable the this component, you need to configure it using a searchComponent element:

<searchComponent name="tvComponent" class="org.apache.solr.handler.component.TermVectorComponent"/>

A request handler must then be configured to use this component name. In the techproducts example, the component is associated with a special request handler named /tvrh, that enables term vectors by default using the tv=true parameter; but you can associate it with any request handler:

<requestHandler name="/tvrh" class="org.apache.solr.handler.component.SearchHandler">
  <lst name="defaults">
    <bool name="tv">true</bool>
  <arr name="last-components">

Once your handler is defined, you may use in conjunction with any schema (that has a uniqueKeyField) to fetch term vectors for fields configured with the termVector attribute, such as in the techproducts sample schema. For example:

<field name="includes"
       termOffsets="true" />

Invoking the Term Vector Component

The example below shows an invocation of this component using the above configuration:

<lst name="termVectors">
  <lst name="GB18030TEST">
    <str name="uniqueKey">GB18030TEST</str>
  <lst name="EN7800GTX/2DHTV/256M">
    <str name="uniqueKey">EN7800GTX/2DHTV/256M</str>
  <lst name="100-435805">
    <str name="uniqueKey">100-435805</str>
  <lst name="3007WFP">
    <str name="uniqueKey">3007WFP</str>
    <lst name="includes">
      <lst name="cable"/>
      <lst name="usb"/>
  <lst name="SOLR1000">
    <str name="uniqueKey">SOLR1000</str>
  <lst name="0579B002">
    <str name="uniqueKey">0579B002</str>
  <lst name="UTF8TEST">
    <str name="uniqueKey">UTF8TEST</str>
  <lst name="9885A004">
    <str name="uniqueKey">9885A004</str>
    <lst name="includes">
      <lst name="32mb"/>
      <lst name="av"/>
      <lst name="battery"/>
      <lst name="cable"/>
      <lst name="card"/>
      <lst name="sd"/>
      <lst name="usb"/>
  <lst name="adata">
    <str name="uniqueKey">adata</str>
  <lst name="apple">
    <str name="uniqueKey">apple</str>

Term Vector Request Parameters

The example below shows some of the available request parameters for this component:

http://localhost:8983/solr/techproducts/tvrh?q=includes:[* TO *]&rows=10&indent=true&tv=true&
If true, the Term Vector Component will run.
For a given comma-separated list of Lucene document IDs (not the Solr Unique Key), term vectors will be returned.
For a given comma-separated list of fields, term vectors will be returned. If not specified, the fl parameter is used.
If true, all the boolean parameters listed below (tv.df, tv.offsets, tv.positions, tv.payloads, and tv.tf_idf) will be enabled.
If true, returns the Document Frequency (DF) of the term in the collection. This can be computationally expensive.
If true, returns offset information for each term in the document.
If true, returns position information.
If true, returns payload information.
If true, returns document term frequency info for each term in the document.

If true, calculates TF / DF (i.e.,: TF * IDF) for each term. Please note that this is a literal calculation of "Term Frequency multiplied by Inverse Document Frequency" and not a classical TF-IDF similarity measure.

This parameter requires both and tv.df to be "true". This can be computationally expensive. (The results are not shown in example output)

To see an example of TermVector component output, see the Wiki page:

For schema requirements, see also the section Field Properties by Use Case.

SolrJ and the Term Vector Component

Neither the SolrQuery class nor the QueryResponse class offer specific method calls to set Term Vector Component parameters or get the "termVectors" output. However, there is a patch for it: SOLR-949.