org.compass.core.lucene
Class LuceneResource

java.lang.Object
  extended by org.compass.core.lucene.LuceneResource
All Implemented Interfaces:
Serializable, Map<String,Property[]>, Resource, AliasedObject, InternalResource

public class LuceneResource
extends Object
implements AliasedObject, InternalResource, Map<String,Property[]>

Author:
kimchy
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
LuceneResource(Document document, int docNum, LuceneSearchEngineFactory searchEngineFactory)
           
LuceneResource(String alias, Document document, int docNum, LuceneSearchEngineFactory searchEngineFactory)
           
LuceneResource(String alias, LuceneSearchEngineFactory searchEngineFactory)
           
 
Method Summary
 Resource addProperty(Property property)
          Add a property to the resource.
 Resource addProperty(String name, Object value)
          Adds a property to the resource based on resource mapping definitions.
 Resource addProperty(String name, Reader value)
          Adds a property to the resource based on resource mapping definitions.
 void addUID()
          Sets the UID for the resource based on the current ids existing withing the resource and the resource mapping associated with it.
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 void copy(Resource resource)
          Copies the content of the give Resource into the current one
 Set<Map.Entry<String,Property[]>> entrySet()
           
 Property[] get(Object key)
           
 String getAlias()
          Returns the mapping alias of the associated Resource
 float getBoost()
          Returns, at indexing time, the boost factor as set by Resource.setBoost(float).
 int getDocNum()
          Returns the Lucene document number.
 Document getDocument()
           
 String getId()
          Returns the id of the resource.
 Property[] getIdProperties()
          Returns the id properties of the resource
 Property getIdProperty()
          Returns the id property of the resource
 String[] getIds()
          Returns the id values of the resource.
 Object getObject(String name)
          Returns the object value of the property with the given name if any exists in the resource, or null.
 Object[] getObjects(String name)
          Returns an array of values of the proeprty with the given name.
 Property[] getProperties()
          Returns all the properties for the resource.
 Property[] getProperties(String name)
          Returns all the properties under the given name.
 Property getProperty(String name)
          Returns the first property under the name.
 String getSubIndex()
          Returns the sub index this resource is associated with.
 String getUID()
          Returns the unique id of the resource.
 String getValue(String name)
          Returns the string value of the property with the given name if any exist in this resource, or null.
 String[] getValues(String name)
          Returns an array of values of the property specified as the method parameter.
 boolean isEmpty()
           
 Set<String> keySet()
           
 Property[] put(String key, Property[] value)
           
 void putAll(Map<? extends String,? extends Property[]> t)
           
 Property[] remove(Object key)
           
 Resource removeProperties(String name)
          Removes all the properties under the given name.
 Resource removeProperty(String name)
          Remove the latest property added under the given name.
 ResourceKey resourceKey()
           
 Resource setBoost(float boost)
          /** Sets a boost factor for hits on any field of this document.
 void setDocNum(int docNum)
           
 Resource setProperty(Property property)
          Sest a property to the resource (removes then adds).
 Resource setProperty(String name, Object value)
          Sets a property to the resource (removes then adds) based on resource mapping definitions.
 Resource setProperty(String name, Reader value)
          Sets a property to the resource (removes then adds) based on resource mapping definitions.
 int size()
           
 String toString()
           
 Collection<Property[]> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LuceneResource

public LuceneResource(String alias,
                      LuceneSearchEngineFactory searchEngineFactory)

LuceneResource

public LuceneResource(Document document,
                      int docNum,
                      LuceneSearchEngineFactory searchEngineFactory)

LuceneResource

public LuceneResource(String alias,
                      Document document,
                      int docNum,
                      LuceneSearchEngineFactory searchEngineFactory)
Method Detail

copy

public void copy(Resource resource)
Description copied from interface: Resource
Copies the content of the give Resource into the current one

Specified by:
copy in interface Resource
Parameters:
resource - The resource to copy from

getDocument

public Document getDocument()

resourceKey

public ResourceKey resourceKey()
Specified by:
resourceKey in interface InternalResource

getSubIndex

public String getSubIndex()
Description copied from interface: InternalResource
Returns the sub index this resource is associated with.

Specified by:
getSubIndex in interface InternalResource

getValue

public String getValue(String name)
Description copied from interface: Resource
Returns the string value of the property with the given name if any exist in this resource, or null. If multiple properties exist with this name, this method returns the first value added.

Specified by:
getValue in interface Resource
Parameters:
name - The name of the property
Returns:
The first value that match the name

getObject

public Object getObject(String name)
Description copied from interface: Resource
Returns the object value of the property with the given name if any exists in the resource, or null. If multiple properties exists with this name, this methods returns the first value added.

If a converter is associated with the property in one of Compass mapping definitions, it will be used to convert the string value to an object value. If there is no converter associated with the property, the string value will be returned.

Specified by:
getObject in interface Resource
Parameters:
name - The name of the property
Returns:
The first object value that match the name (converted if possible)

getObjects

public Object[] getObjects(String name)
Description copied from interface: Resource
Returns an array of values of the proeprty with the given name. This method returns an empty array if no values are associated with the given name.

If a converter is associated with the property in one of Compass mapping definitions, it will be used to convert the string value to an object value. If there is no converter associated with the property, the string value will be returned.

Specified by:
getObjects in interface Resource

getValues

public String[] getValues(String name)
Description copied from interface: Resource
Returns an array of values of the property specified as the method parameter. This method can return null.

Specified by:
getValues in interface Resource
Parameters:
name - the name of the property
Returns:
a String[] of property values

getAlias

public String getAlias()
Description copied from interface: Resource
Returns the mapping alias of the associated Resource

Specified by:
getAlias in interface Resource
Specified by:
getAlias in interface AliasedObject
Returns:
The alias

getUID

public String getUID()
Description copied from interface: Resource
Returns the unique id of the resource. Note, the ids must be set on this resource in order to get the uid, if not a CompassException will be thrown.

Specified by:
getUID in interface Resource

getId

public String getId()
Description copied from interface: Resource
Returns the id of the resource. Used when there is only one id for the resource.

Specified by:
getId in interface Resource
Returns:
The id of the resource.

getIds

public String[] getIds()
Description copied from interface: Resource
Returns the id values of the resource.

Specified by:
getIds in interface Resource
Returns:
The id values of the resource

getIdProperty

public Property getIdProperty()
Description copied from interface: Resource
Returns the id property of the resource

Specified by:
getIdProperty in interface Resource
Returns:
The id properties of the resource

getIdProperties

public Property[] getIdProperties()
Description copied from interface: Resource
Returns the id properties of the resource

Specified by:
getIdProperties in interface Resource
Returns:
The id properties of the resource

addProperty

public Resource addProperty(String name,
                            Object value)
                     throws SearchEngineException
Description copied from interface: Resource
Adds a property to the resource based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Specified by:
addProperty in interface Resource
Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

addProperty

public Resource addProperty(String name,
                            Reader value)
                     throws SearchEngineException
Description copied from interface: Resource
Adds a property to the resource based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Specified by:
addProperty in interface Resource
Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

addProperty

public Resource addProperty(Property property)
Description copied from interface: Resource
Add a property to the resource. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). Note: Compass adds all properties specified in mapping file, adding extra properties to a Resource will make the index out of sync with mapping.

Specified by:
addProperty in interface Resource
Parameters:
property - The properyt to add

setProperty

public Resource setProperty(String name,
                            Object value)
                     throws SearchEngineException
Description copied from interface: Resource
Sets a property to the resource (removes then adds) based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Specified by:
setProperty in interface Resource
Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

setProperty

public Resource setProperty(String name,
                            Reader value)
                     throws SearchEngineException
Description copied from interface: Resource
Sets a property to the resource (removes then adds) based on resource mapping definitions. If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). ONLY use this method with resource mapping.

Specified by:
setProperty in interface Resource
Parameters:
name - the name of the property
value - the value to be set (will be converted to a string).
Throws:
SearchEngineException

setProperty

public Resource setProperty(Property property)
Description copied from interface: Resource
Sest a property to the resource (removes then adds). If the property already exists in the resource (the name exists), it will be added on top of it (won't replace it). Note: Compass adds all properties specified in mapping file, adding extra properties to a Resource will make the index out of sync with mapping.

Specified by:
setProperty in interface Resource
Parameters:
property - The properyt to add

removeProperty

public Resource removeProperty(String name)
Description copied from interface: Resource
Remove the latest property added under the given name.

Specified by:
removeProperty in interface Resource
Parameters:
name - The last property name to remove

removeProperties

public Resource removeProperties(String name)
Description copied from interface: Resource
Removes all the properties under the given name.

Specified by:
removeProperties in interface Resource
Parameters:
name - The properties name to remove

getProperty

public Property getProperty(String name)
Description copied from interface: Resource
Returns the first property under the name.

Specified by:
getProperty in interface Resource
Parameters:
name - The name of the property
Returns:
The first proeprty that match the name

getProperties

public Property[] getProperties(String name)
Description copied from interface: Resource
Returns all the properties under the given name.

Specified by:
getProperties in interface Resource
Parameters:
name - The name of the properties
Returns:
An array of properties that match the name

getProperties

public Property[] getProperties()
Description copied from interface: Resource
Returns all the properties for the resource.

Specified by:
getProperties in interface Resource
Returns:
All the properties

getBoost

public float getBoost()
Description copied from interface: Resource
Returns, at indexing time, the boost factor as set by Resource.setBoost(float).

Note that once a document is indexed this value is no longer available from the index. At search time, for retrieved documents, this method always returns 1. This however does not mean that the boost value set at indexing time was ignored - it was just combined with other indexing time factors and stored elsewhere, for better indexing and search performance. (For more information see the "norm(t,d)" part of the scoring formula in Similarity.)

Specified by:
getBoost in interface Resource
Returns:
The boost value

setBoost

public Resource setBoost(float boost)
Description copied from interface: Resource
/** Sets a boost factor for hits on any field of this document. This value will be multiplied into the score of all hits on this document.

The default value is 1.0.

Values are multiplied into the value of Property.getBoost() of each properties of the resource. Thus, this method in effect sets a default boost for the fields of this document.

Specified by:
setBoost in interface Resource
Parameters:
boost - The boost level for the resource
See Also:
Property.setBoost(float)

setDocNum

public void setDocNum(int docNum)

getDocNum

public int getDocNum()
Returns the Lucene document number. If not set (can be in case the resource is newly created), than returns -1.


addUID

public void addUID()
Description copied from interface: InternalResource
Sets the UID for the resource based on the current ids existing withing the resource and the resource mapping associated with it.

Specified by:
addUID in interface InternalResource

toString

public String toString()
Overrides:
toString in class Object

clear

public void clear()
Specified by:
clear in interface Map<String,Property[]>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<String,Property[]>

putAll

public void putAll(Map<? extends String,? extends Property[]> t)
Specified by:
putAll in interface Map<String,Property[]>

remove

public Property[] remove(Object key)
Specified by:
remove in interface Map<String,Property[]>

put

public Property[] put(String key,
                      Property[] value)
Specified by:
put in interface Map<String,Property[]>

entrySet

public Set<Map.Entry<String,Property[]>> entrySet()
Specified by:
entrySet in interface Map<String,Property[]>

keySet

public Set<String> keySet()
Specified by:
keySet in interface Map<String,Property[]>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<String,Property[]>

size

public int size()
Specified by:
size in interface Map<String,Property[]>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<String,Property[]>

values

public Collection<Property[]> values()
Specified by:
values in interface Map<String,Property[]>

get

public Property[] get(Object key)
Specified by:
get in interface Map<String,Property[]>


Copyright (c) 2004-2008 The Compass Project.