Apache Solr Documentation

6.5 Ref Guide (PDF Download)
Solr Tutorial
Solr Community Wiki

Older Versions of this Guide (PDF)

Ref Guide Topics

Meta-Documentation

*** As of June 2017, the latest Solr Ref Guide is located at https://lucene.apache.org/solr/guide ***

Please note comments on these pages have now been disabled for all users.

Skip to end of metadata
Go to start of metadata

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.

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:

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

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:

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 techproductsfor example:

Invoking the Term Vector Component

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

http://localhost:8983/solr/techproducts/tvrh?q=*%3A*&start=0&rows=10&fl=id,includes

Request Parameters

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

http://localhost:8983/solr/techproducts/tvrh?q=includes:[* TO *]&rows=10&indent=true&tv=true&tv.tf=true&tv.df=true&tv.positions=true&tv.offsets=true&tv.payloads=true&tv.fl=includes

Boolean Parameters

Description

Type
tvShould the component run or notboolean
tv.docIdsReturns term vectors for the specified list of Lucene document IDs (not the Solr Unique Key).comma seperated integers
tv.flReturns term vectors for the specified list of fields. If not specified, the fl parameter is used.comma seperated list of field names

tv.all

A shortcut that invokes all the boolean parameters listed below.

boolean

tv.df

Returns the Document Frequency (DF) of the term in the collection. This can be computationally expensive.

boolean

tv.offsets

Returns offset information for each term in the document.

boolean

tv.positions

Returns position information.

boolean
tv.payloadsReturns payload information.boolean

tv.tf

Returns document term frequency info per term in the document.

boolean

tv.tf_idf

Calculates TF / DF (ie: 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.

Requires the parameters tv.tf and tv.df to be "true". This can be computationally expensive.  (The results are not shown in example output)

boolean

 

To learn more about TermVector component output, see the Wiki page: http://wiki.apache.org/solr/TermVectorComponentExampleOptions

For schema requirements, see the Wiki page: http://wiki.apache.org/solr/FieldOptionsByUseCase

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.

 

  • No labels

7 Comments

  1. Example URLs should reflect the default "<requestDispatcher handleSelect="false" >" configuration of collection1 example, by starting with the following:

    http://localhost:8983/solr/tvrh/

    and remove "qt=tvrh".

     

    1. Dorian: thanks for noticing that – i fixed the examples on this page to better reflect the collection1 example configuration, and did some other general cleaup of the page.

  2. Not sure if this is due to my configuration but I was unable to display the output for termVectors using the Solr 4.5 Query interface without debugQuery being set to true. This may be relevant to the page.

    1. Mark: debugQuery is definitely not neccessary to retrieve term vectors from solr – neither talking directly to a request handler, or using the Query page in the admin ui.

      If you are having difficulties getting term vectors to work, please contact the solr-user@lucene mailing list.

  3. Please change the documentation to reflect that what is referred to here as TF-IDF is not actually TF-IFD, as it says in the source code. See SOLR-3818   SOLR-3818 - TermVectorComponent tfidf is not tf/idf by anyone's definition Open

  4. How do I receive the term vector WITHOUT the actual documents themselves?

    Meaning, only the  <lst name="termVectors">...</lst> without <result name="response" numFound="1670000" start="5">

     

    <response>
     
     <lst name="responseHeader">
     
    <int name="status">0</int>
     
    <int name="QTime">0</int>
     
    </lst>
     
     <result name="response" numFound="1670000" start="5">
     
     
     
     
     
     
    </result>
     
     
    </response>