ome.services.fulltext
Class BridgeHelper

java.lang.Object
  extended by ome.services.fulltext.BridgeHelper
All Implemented Interfaces:
org.hibernate.search.bridge.FieldBridge, org.springframework.context.ApplicationEventPublisherAware
Direct Known Subclasses:
FullTextBridge, ProjectWithImageNameBridge

public abstract class BridgeHelper
extends Object
implements org.hibernate.search.bridge.FieldBridge, org.springframework.context.ApplicationEventPublisherAware

Base class for building custom FieldBridge implementations. To force handling of null values, the #add(Document, String, String, Store, org.apache.lucene.document.Field.Index, Float) methods throw NullValueException which can convert itself to a RuntimeException via NullValueException#convert(Object) if that is the simplest course of action. Alternatively, you could re-add the value with a null-token like "null".

Since:
3.0-Beta3
Author:
Josh Moore, josh at glencoesoftware.com

Field Summary
static String COMBINED
          Name of the Field which contains the union of all fields.
protected  org.springframework.context.ApplicationEventPublisher publisher
           
 
Constructor Summary
BridgeHelper()
           
 
Method Summary
protected  void add(Document d, String field, String value, org.hibernate.search.bridge.LuceneOptions opts)
          Helper method which takes the parameters from the #set(String, Object, Document, Store, org.apache.lucene.document.Field.Index, Float) method (possibly modified) as well as the parsed String value which should be added to the index, and adds two fields.
protected  void addContents(Document d, String name, ome.model.core.OriginalFile file, OriginalFilesService files, Map<String,FileParser> parsers, org.hibernate.search.bridge.LuceneOptions opts)
          Second helper method used when parsing files.
 org.apache.commons.logging.Log logger()
           
protected  Iterable<Reader> parse(ome.model.core.OriginalFile file, OriginalFilesService files, Map<String,FileParser> parsers)
          Attempts to parse the given OriginalFile.
protected
<T extends ome.model.IObject>
void
reindex(T object)
          Publishes a ReindexMessage which will get processed asynchronously.
protected
<T extends ome.model.IObject>
void
reindexAll(List<T> list)
          Publishes a ReindexMessage which will get processed asynchronously.
abstract  void set(String name, Object value, Document document, org.hibernate.search.bridge.LuceneOptions opts)
          Method to be implemented by all bridges.
 void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher publisher)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMBINED

public static final String COMBINED
Name of the Field which contains the union of all fields. This is also the default search field, so users need not append the value to search the full index. A field name need only be added to a search to eliminate other fields.

See Also:
Constant Field Values
To do:
add to constants

publisher

protected org.springframework.context.ApplicationEventPublisher publisher
Constructor Detail

BridgeHelper

public BridgeHelper()
Method Detail

logger

public final org.apache.commons.logging.Log logger()

setApplicationEventPublisher

public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher publisher)
Specified by:
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware

set

public abstract void set(String name,
                         Object value,
                         Document document,
                         org.hibernate.search.bridge.LuceneOptions opts)
Method to be implemented by all bridges. The "value" argument is an active Hibernate object, and so the full graph can be walked.

Specified by:
set in interface org.hibernate.search.bridge.FieldBridge

add

protected void add(Document d,
                   String field,
                   String value,
                   org.hibernate.search.bridge.LuceneOptions opts)
Helper method which takes the parameters from the #set(String, Object, Document, Store, org.apache.lucene.document.Field.Index, Float) method (possibly modified) as well as the parsed String value which should be added to the index, and adds two fields. One with the given field name and another to the COMBINED field which is the default search provided to users. In addition to storing the value as is, another Field will be added for both the named and COMBINED cases using a StringReader to allow Lucene to tokenize the String.

Parameters:
d - Document as passed to the set method. Do not modify.
field - Field name which probably should be modified. If this value is null, then the "value" will only be added to the COMBINED field.
value - Value which has been parsed out for this field. Should not be null. If you need to store a null value in the index, use a null token like "null".
opts - LuceneOptions, passed in from the runtime. If overriding on the interface values is required, see SimpleLuceneOptions

addContents

protected void addContents(Document d,
                           String name,
                           ome.model.core.OriginalFile file,
                           OriginalFilesService files,
                           Map<String,FileParser> parsers,
                           org.hibernate.search.bridge.LuceneOptions opts)
Second helper method used when parsing files. The OriginalFile will be passed to parse(OriginalFile, OriginalFilesService, Map) to generate Reader instances, which will be read until they signal an end, however it is not the responsibility of this instance to close the Readers since this happens asynchronously. The contents of the file will be parsed both to COMBINED and "file.contents".

Parameters:
d - Document as passed to set. Do not modify.
file - Non-null, possibly unloaded OriginalFile which is used to look up the file on disk.
files - OriginalFileServer which knows how to find where this OriginalFile is stored on disk.
parsers - Map of FileParser instances to be used based on the Format of the OriginalFile
boost - Positive float which increases or decreases search importance for a field. Default is 1.0.

reindex

protected <T extends ome.model.IObject> void reindex(T object)
Publishes a ReindexMessage which will get processed asynchronously.


reindexAll

protected <T extends ome.model.IObject> void reindexAll(List<T> list)
Publishes a ReindexMessage which will get processed asynchronously.


parse

protected Iterable<Reader> parse(ome.model.core.OriginalFile file,
                                 OriginalFilesService files,
                                 Map<String,FileParser> parsers)
Attempts to parse the given OriginalFile. If any of the necessary components is null, then it will return an empty, but not null Iterable. Also looks for the catch all parser under "*"

Parameters:
file - Can be null.
Returns:
will not be null.


OmeroJava Api

Version: Beta-4.2.0-r7571-b29

Copyright © 2009 The University of Dundee. All Rights Reserved.