net.datacrow.core.services
Class OnlineSearchHelper

java.lang.Object
  extended by net.datacrow.core.services.OnlineSearchHelper
All Implemented Interfaces:
IOnlineSearchClient

public class OnlineSearchHelper
extends java.lang.Object
implements IOnlineSearchClient

Simple online search which can run completely in the background. It has implemented the IOnlineSearchClient interface. This class can be used by other processes which want to enable online search (such as the FileImporter)

Author:
Robert Jan van der Waals

Constructor Summary
OnlineSearchHelper(int module, int itemMode)
          Creates a new instance.
 
Method Summary
 void addError(java.lang.String message)
          Passes an error message to this client.
 void addError(java.lang.Throwable t)
          Passes an error to this client.
 void addMessage(java.lang.String message)
          Passes a message to this client.
 void addObject(DcObject dco)
          Passes a result / item to this client.
 void addWarning(java.lang.String warning)
          Passes a warning message to this client.
 void clear()
          Free resources.
 DcObject getDcObject()
           
 DcModule getModule()
          Returns the current module.
 void processed(int i)
          The current result number being processed (x of x).
 void processing()
          Indicates a task is currently running.
 void processingTotal(int i)
          Passes the count of results which are going to be processed.
 DcObject query(DcObject item)
          Queries for new information for the supplied item.
 DcObject query(DcObject base, java.lang.String query, int[] matcherFieldIdx)
          Queries for items and checks if they are similar to the supplied item the item most similar to the base item will be returned.
 java.util.List<DcObject> query(java.lang.String query, DcObject client)
          Searches for items based on the provided query string.
 int resultCount()
          Returns the total count of added items (see IOnlineSearchClient.addObject(DcObject))
 void setMaximum(int maximum)
          The maximum search result.
 void setMode(SearchMode mode)
          The search mode to be used.
 void setRegion(Region region)
          The region to be used.
 void setServer(IServer server)
          The server to be used.
 void stopped()
          Indicates a task has been stopped and a new task can be started.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnlineSearchHelper

public OnlineSearchHelper(int module,
                          int itemMode)
Creates a new instance.

Parameters:
module - The module index
itemMode - SearchTask._ITEM_MODE_FULL or SearchTask._ITEM_MODE_SIMPLE
Method Detail

setServer

public void setServer(IServer server)
The server to be used.

Parameters:
server -

setRegion

public void setRegion(Region region)
The region to be used.

Parameters:
region -

setMode

public void setMode(SearchMode mode)
The search mode to be used.

Parameters:
mode -

setMaximum

public void setMaximum(int maximum)
The maximum search result.

Parameters:
maximum -

query

public DcObject query(DcObject item)
Queries for new information for the supplied item. Uses the services URL as stored in the item (see DcObject._SYS_SERVICEURL).

Parameters:
item -
Returns:
The supplied item. Either updated or not.

query

public DcObject query(DcObject base,
                      java.lang.String query,
                      int[] matcherFieldIdx)
Queries for items and checks if they are similar to the supplied item the item most similar to the base item will be returned. Similarity is based on the values of the provided field indices.

Parameters:
base - The item to check the results against.
query - The query to base the search on.
matcherFieldIdx - The field indices used to check for similarity.
Returns:
The most similar result or null.

query

public java.util.List<DcObject> query(java.lang.String query,
                                      DcObject client)
Searches for items based on the provided query string.

Parameters:
query -
Returns:
Collection of results.

clear

public void clear()
Free resources.

Parameters:
except - Do not clear the resources of this item.

addError

public void addError(java.lang.Throwable t)
Description copied from interface: IOnlineSearchClient
Passes an error to this client.

Specified by:
addError in interface IOnlineSearchClient

addError

public void addError(java.lang.String message)
Description copied from interface: IOnlineSearchClient
Passes an error message to this client.

Specified by:
addError in interface IOnlineSearchClient

addMessage

public void addMessage(java.lang.String message)
Description copied from interface: IOnlineSearchClient
Passes a message to this client.

Specified by:
addMessage in interface IOnlineSearchClient

addObject

public void addObject(DcObject dco)
Description copied from interface: IOnlineSearchClient
Passes a result / item to this client.

Specified by:
addObject in interface IOnlineSearchClient

addWarning

public void addWarning(java.lang.String warning)
Description copied from interface: IOnlineSearchClient
Passes a warning message to this client.

Specified by:
addWarning in interface IOnlineSearchClient

getDcObject

public DcObject getDcObject()

getModule

public DcModule getModule()
Description copied from interface: IOnlineSearchClient
Returns the current module.

Specified by:
getModule in interface IOnlineSearchClient
Returns:
The module

processed

public void processed(int i)
Description copied from interface: IOnlineSearchClient
The current result number being processed (x of x).

Specified by:
processed in interface IOnlineSearchClient

processing

public void processing()
Description copied from interface: IOnlineSearchClient
Indicates a task is currently running.

Specified by:
processing in interface IOnlineSearchClient

processingTotal

public void processingTotal(int i)
Description copied from interface: IOnlineSearchClient
Passes the count of results which are going to be processed. This way the client knows how many items to expect.

Specified by:
processingTotal in interface IOnlineSearchClient
Parameters:
i - The total count.

resultCount

public int resultCount()
Description copied from interface: IOnlineSearchClient
Returns the total count of added items (see IOnlineSearchClient.addObject(DcObject))

Specified by:
resultCount in interface IOnlineSearchClient

stopped

public void stopped()
Description copied from interface: IOnlineSearchClient
Indicates a task has been stopped and a new task can be started.

Specified by:
stopped in interface IOnlineSearchClient