Mark Overmeer > Apache-Solr-0.92 > Apache::Solr::Document



Annotate this POD


Open  2
View/Report Bugs
Module Version: 0.92   Source   Latest Release: Apache-Solr-0.98


Apache::Solr::Document - Apache Solr (Lucene) Document container


  # create and upload a new document
  my $doc = Apache::Solr::Document->new(...);
  $solr->addDocument($doc, commit => 1, overwrite => 1)

  # take first result
  my $results = $solr->select
    ( q  => 'text:gold'             # search text-fields for 'gold'
    , hl => { field => 'content' }  # highlight 'gold' in content'

  my $doc = $results->selected(3);  # fourth answer
  print $doc->rank;         # 3
  print $doc->field('subject')->{content};
  print $doc->content('subject');   # same
  print $doc->_subject;             # same, via autoload (mind the '_'!)

  my $hl  = $results->highlighted($doc);  # another ::Doc object
  print $hl->_content;              # highlighted content


This object wraps-up an document: a set of fields. Either, this is a document which has to be added to the Solr database using Apache::Solr::addDocument(), or the subset of information as returned by Apache::Solr::select().



Apache::Solr::Document->fromResult(HASH, RANK)

Create a document object from data received as result of a select search.

  boost   1.0
  fields  {}
boost => FLOAT

Boost the preference for hits in this document.

fields => HASH|ARRAY

Passed to addFields().


$obj->addField(NAME, CONTENT, OPTIONS)

CONTENT can be specified as SCALAR (reference) for performance. In that case, a reference to the original will be kept. When undef, the field gets ignored.

  boost   1.0
boost => FLOAT
$obj->addFields(HASH|ARRAY, OPTIONS)

The HASH or ARRAY containing NAME/CONTENT pairs. The OPTIONS are passed addField() as OPTIONS.


Boost value for all fields in the document.


Returns the content of the first field with NAME.


Returns the first field with NAME (or undef). This is a HASH.


All used unique names.


Returns a list of HASHs, each containing at least a name and a content. Each HASH will also contain a boost value. When a NAME is provided, only those fields are returned.


Only defined when the document contains results of a search: the ranking. A value of '0' means "best".


Returns the value of the unique key associated with the document id. Only the server knowns which field is the unique one. If it differs from the usual id, you have to set it via global value $Apache::Solr::uniqueKey



This module is part of Apache-Solr distribution version 0.92, built on December 06, 2012. Website:


Copyrights 2012 by [Mark Overmeer]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See

syntax highlighting: