org.egothor.dir
Class Group

java.lang.Object
  extended by org.egothor.dir.Group
All Implemented Interfaces:
Resolver<CachedQuery,CachedResult>, Barrel
Direct Known Subclasses:
Tanker

public abstract class Group
extends java.lang.Object
implements Barrel, Resolver<CachedQuery,CachedResult>

A Group is a group of Barrels which are, in fact, represented as one Barrel. Such a group can have its own state, thus it also implements the Status interface. The group is organized by a Distributor that manages and routes requests and messages to active Barrels.

Author:
Leo Galambos

Field Summary
protected  CachedGroup cache
           
 
Constructor Summary
protected Group()
          Constructor for the Group object
 
Method Summary
 void close()
          Close this Group.
 long deleted()
          Total number of deleted documents in this group.
 void destroy()
          Destroy this Group.
abstract  Sequence<Barrel> elements()
          Return the elements contained in this object.
 Sequence<? extends IListMetadata> expand(java.lang.String expr)
          Return the enumeration of all IListMetadata objects which match the expression.
abstract  DocumentData expandDocMetadata(DocumentData ofBarrel, Token[] interest)
          Retrives the document data, but restrict the data block to the part relevant to some tokens of our interest.
 void forEach(Task<Barrel> task)
          Put the given task to all active (inner) barrels.
 Bitmap getBitmap(java.lang.String label)
          Return the Bitmap of a given label.
 CachedGroup getCache()
          Gets the CachedGroup used for storing query results.
 CWI getCWI(java.util.HashSet<Token> terms)
          Return the subset of CWI for the given subset of terms.
 IListMetadata getIListMeta(java.lang.String term)
          Return the inverted list metadata for the given term.
 DocumentData getMeta(long uid)
          Return the metadata for the document with the given unique identifier.
protected  void initialize(Distributor<Barrel> d)
          Constructor for the Group object.
 void initializeCache(Cache<CachedQuery,CachedResult> cache)
          Initializes a query result cache with the specified options.
 void initializeCache(Cache<CachedQuery,CachedResult> cache, boolean cacheMetadata)
          Initializes a query result cache with the specified options.
 void initializeCache(Cache<CachedQuery,CachedResult> cache, int pageSize)
          Initializes a query result cache with the specified options.
 void initializeCache(Cache<CachedQuery,CachedResult> cache, int pageSize, boolean cacheMetadata)
          Initializes a query result cache with the specified options.
 void iterate(Request<Barrel> task)
          Iterate through the active (inner) barrels in predefined and constant order and try to give them the request until one of them fulfills it.
 BarrelReader open()
          Open this Group.
 IListReader openIList(java.lang.String term, boolean clean)
          Open the inverted list constructed for the given term for reading.
 QueryResponse query(int offset, int length, int p, java.lang.String query, long max_hits2scan, double pg_rerank, java.lang.String... controls)
          Return a QueryResponse to a user query.
 void query(Query q, ResultList result)
          Submit the given query to this Group.
 boolean removeDoc(long id)
          Remove the document with the given ID and return whether the operation was successful.
 CachedResult resolve(CachedQuery cachedQuery)
          Gets the value associated with the key without the use of a cache.
 void setBitmap(java.lang.String label, Bitmap bitmap)
          Try to set the Bitmap of a given label.
 long size()
          Return the number of all documents in this Barrel (including the deleted ones).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.egothor.core.Barrel
commit
 

Field Detail

cache

protected CachedGroup cache
Constructor Detail

Group

protected Group()
Constructor for the Group object

Method Detail

initialize

protected void initialize(Distributor<Barrel> d)
Constructor for the Group object.

Parameters:
d - routes requests and messages to active Barrels

initializeCache

public void initializeCache(Cache<CachedQuery,CachedResult> cache)
Initializes a query result cache with the specified options. Does not use paging and caches complete query results.

Parameters:
cache - actual cache used for storing query results

initializeCache

public void initializeCache(Cache<CachedQuery,CachedResult> cache,
                            int pageSize)
Initializes a query result cache with the specified options. Caches complete query results.

Parameters:
cache - actual cache used for storing query results
pageSize - maximum size of a query result page

initializeCache

public void initializeCache(Cache<CachedQuery,CachedResult> cache,
                            boolean cacheMetadata)
Initializes a query result cache with the specified options. Does not use paging.

Parameters:
cache - actual cache used for storing query results
cacheMetadata - whether we want to cache complete result or just the document ID's

initializeCache

public void initializeCache(Cache<CachedQuery,CachedResult> cache,
                            int pageSize,
                            boolean cacheMetadata)
Initializes a query result cache with the specified options.

Parameters:
cache - actual cache used for storing query results
pageSize - maximum size of a query result page
cacheMetadata - whether we want to cache complete result or just the document ID's

getCache

public CachedGroup getCache()
Gets the CachedGroup used for storing query results.

Returns:
cache used for storing query results or null if no cache is used

getBitmap

public Bitmap getBitmap(java.lang.String label)
Description copied from interface: Barrel
Return the Bitmap of a given label.

Specified by:
getBitmap in interface Barrel
Parameters:
label - the label of the requested Bitmap
Returns:
Bitmap of removed documents when label is null

setBitmap

public void setBitmap(java.lang.String label,
                      Bitmap bitmap)
Description copied from interface: Barrel
Try to set the Bitmap of a given label.

Specified by:
setBitmap in interface Barrel
Parameters:
label - the label of the requested Bitmap
bitmap - Bitmap of removed documents when label is null

getCWI

public CWI getCWI(java.util.HashSet<Token> terms)
Return the subset of CWI for the given subset of terms.

Parameters:
terms - a HashSet containing the terms for which CWI should be returned
Returns:
null iff this group has no global CWI and everything is computed as local.

getIListMeta

public IListMetadata getIListMeta(java.lang.String term)
Return the inverted list metadata for the given term.

Specified by:
getIListMeta in interface Barrel
Parameters:
term - the term
Returns:
an IListMetadata containing information about the inverted list constructed for the given term

getMeta

public DocumentData getMeta(long uid)
Return the metadata for the document with the given unique identifier.

Specified by:
getMeta in interface Barrel
Parameters:
uid - the unique identifier of the document in question
Returns:
a DocMetadDocumentDataing the metadata of the document

expandDocMetadata

public abstract DocumentData expandDocMetadata(DocumentData ofBarrel,
                                               Token[] interest)
Retrives the document data, but restrict the data block to the part relevant to some tokens of our interest. Full data block is retrieved if none interest is specified.


query

public QueryResponse query(int offset,
                           int length,
                           int p,
                           java.lang.String query,
                           long max_hits2scan,
                           double pg_rerank,
                           java.lang.String... controls)
                    throws ParseException
Return a QueryResponse to a user query.

Parameters:
offset - where to start reading the result list
length - read the result list up to here
p - power parameter in evaluation formula @{link org.egothor.Constants#DEFAULTMODEL}
query - the user's query
in - the Barrel to search
max_hits2scan - maximum positive hits scanned, if achieved then total number of hits is only guessed
pg_rerank - pagerank booster @{link org.egothor.core.query.ResultList}
controls - control BITMAP tokens (String)
Returns:
a QueryResponse
Throws:
ParseException - if there is difficulty parsing the query

resolve

public CachedResult resolve(CachedQuery cachedQuery)
Description copied from interface: Resolver
Gets the value associated with the key without the use of a cache.

Specified by:
resolve in interface Resolver<CachedQuery,CachedResult>
Parameters:
cachedQuery - key to get the value for
Returns:
value associated with the key

elements

public abstract Sequence<Barrel> elements()
Return the elements contained in this object.

Returns:
an Enumeration containing the elements

forEach

public void forEach(Task<Barrel> task)
Put the given task to all active (inner) barrels. It may be freely distributed as iterate does or in multithread mode. It is up to the implementation.

Parameters:
task - the task to perform

iterate

public void iterate(Request<Barrel> task)
Iterate through the active (inner) barrels in predefined and constant order and try to give them the request until one of them fulfills it.

Parameters:
task - the task to perform

expand

public Sequence<? extends IListMetadata> expand(java.lang.String expr)
Return the enumeration of all IListMetadata objects which match the expression.

Specified by:
expand in interface Barrel
Parameters:
expr - the expression to match
Returns:
null when not supported

size

public long size()
Return the number of all documents in this Barrel (including the deleted ones).

Specified by:
size in interface Barrel
Returns:
the number of documents

deleted

public long deleted()
Total number of deleted documents in this group.

Specified by:
deleted in interface Barrel
Returns:
the number of deleted documents

removeDoc

public boolean removeDoc(long id)
Remove the document with the given ID and return whether the operation was successful.

Specified by:
removeDoc in interface Barrel
Parameters:
id - the document to remove
Returns:
true if the removal was successful, false otherwise

openIList

public IListReader openIList(java.lang.String term,
                             boolean clean)
Open the inverted list constructed for the given term for reading.

Specified by:
openIList in interface Barrel
Parameters:
term - the term for which the inverted list was constructed
clean - whether to remove all the items denoted as deleted
Returns:
an IListReader which can read the inverted list

open

public BarrelReader open()
Open this Group.

Specified by:
open in interface Barrel
Returns:
a BarrelReader which can read this Group

destroy

public void destroy()
Destroy this Group.

Specified by:
destroy in interface Barrel

close

public void close()
Close this Group.

Specified by:
close in interface Barrel

query

public void query(Query q,
                  ResultList result)
Submit the given query to this Group. If we want to replace local CWI with our global (for all barrels), we can do it in sub-class just before we call super's query.

Specified by:
query in interface Barrel
Parameters:
q - the query
result - the list to search