DLESE Tools
v1.6.0

org.dlese.dpc.index.reader
Class DocumentMap

java.lang.Object
  extended by org.dlese.dpc.index.reader.DocumentMap
All Implemented Interfaces:
Map

public class DocumentMap
extends Object
implements Map

A Map for accessing the data stored in a Lucene Document as field/value pairs. All data is loaded from the index into the Map when any Map accessor method is called (e.g. eager loading), making data available even if the underlying index later changes, but also making access to very large Documents inefficient. Each stored field in the Document corresponds to a key in the Map. For example documentMap.get("title") gets the text that was indexed and stored under the field name "title" for the Document. Supports read operations only. A DocumentMap is available from search results by calling ResultDoc.getDocMap().

Example that uses JSTL inside a JSP page (assumes result is an instance of ResultDoc):

The title is: ${result.docMap["title"]}.

Author:
John Weatherley
See Also:
Document, ResultDoc, LazyDocumentMap

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
DocumentMap()
          Constructor for the DocumentMap object.
DocumentMap(org.apache.lucene.document.Document doc)
          Constructor for the DocumentMap object.
 
Method Summary
 void clear()
          Method not supported.
 boolean containsKey(Object fieldName)
          Determines whether a given field exists in the Lucene Document.
 boolean containsValue(Object value)
          Determines whether the given field value is present in the Lucene Document.
 Set entrySet()
          Gets the Set of field/value entries for the Lucene Document.
 Object get(Object fieldName)
          Gets the text content of the given Lucene field as a String or null if the given field is not available or was not stored in the index.
 boolean isEmpty()
          Determines whether there are no fields in this Document.
 Set keySet()
          Gets the field names in the Lucene Document.
 Object put(Object key, Object value)
          Method not supported.
 void putAll(Map t)
          Method not supported.
 Object remove(Object key)
          Method not supported.
 int size()
          Gets the number of fields in the Document.
 Collection values()
          Gets all field values that are present in the Lucene Document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

DocumentMap

public DocumentMap(org.apache.lucene.document.Document doc)
Constructor for the DocumentMap object.

Parameters:
doc - The Lucene Document that is exposed by this Map.

DocumentMap

public DocumentMap()
Constructor for the DocumentMap object.

Method Detail

get

public Object get(Object fieldName)
Gets the text content of the given Lucene field as a String or null if the given field is not available or was not stored in the index. Text contains all stored values for the given field.

Specified by:
get in interface Map
Parameters:
fieldName - A Lucene Document field name
Returns:
The text of the field as a String, a Date, or null if not available.

keySet

public Set keySet()
Gets the field names in the Lucene Document.

Specified by:
keySet in interface Map
Returns:
The field names

entrySet

public Set entrySet()
Gets the Set of field/value entries for the Lucene Document. Each Map.Entry Object in the Set contains the field name (key) and corresponding field value. The field value will be an empty String if the given field was not set to be stored in the index.

Specified by:
entrySet in interface Map
Returns:
The Set of field/value entries for the Lucene Document
See Also:
Map.Entry

containsKey

public boolean containsKey(Object fieldName)
Determines whether a given field exists in the Lucene Document.

Specified by:
containsKey in interface Map
Parameters:
fieldName - A field name
Returns:
True if the field exists in the Lucene Document

values

public Collection values()
Gets all field values that are present in the Lucene Document.

Specified by:
values in interface Map
Returns:
The field values

containsValue

public boolean containsValue(Object value)
Determines whether the given field value is present in the Lucene Document.

Specified by:
containsValue in interface Map
Parameters:
value - A field value
Returns:
True if the field value is present in this Document

isEmpty

public boolean isEmpty()
Determines whether there are no fields in this Document.

Specified by:
isEmpty in interface Map
Returns:
True if there are no fields in the Document.

size

public int size()
Gets the number of fields in the Document.

Specified by:
size in interface Map
Returns:
The number of fields in the Document

putAll

public void putAll(Map t)
Method not supported.

Specified by:
putAll in interface Map
Parameters:
t - Not supported.

put

public Object put(Object key,
                  Object value)
Method not supported.

Specified by:
put in interface Map
Parameters:
key - Not supported.
value - Not supported.
Returns:
Not supported.

remove

public Object remove(Object key)
Method not supported.

Specified by:
remove in interface Map
Parameters:
key - Not supported.
Returns:
Not supported.

clear

public void clear()
Method not supported.

Specified by:
clear in interface Map

DLESE Tools
v1.6.0