org.egothor.core.query
Class Rider

java.lang.Object
  extended by org.egothor.core.query.Rider
All Implemented Interfaces:
CWI

public class Rider
extends java.lang.Object
implements CWI

When a query needs an access to an index, it gets a Rider. In most cases, the Rider is generated by a Barrel that will be accessed by the Rider. This method of construction is beneficial because the Rider can limit itself as to the maximum number of inverted lists it will read.

A Rider has the same features as an IListReader and a query uses it to get access to hit candidates. When it finds a hit, then the query communicates it to the Rider. The Rider analyzes its own current state and sends the hit to a ResultList.

Author:
Leo Galambos

Field Summary
static boolean ALL
          Move all inverted lists of this group
static boolean ANY
          Move at least one inverted list
static int MODE_MAY
          Inverted list of this mode should be available, but it is not needed
static int MODE_PRO
          Inverted list of this mode is prohibited in queries
static int MODE_REQ
          Inverted list of this mode is required for querying
 
Constructor Summary
Rider(int size, Barrel b, ResultList res)
          Constructor for the Rider object.
 
Method Summary
 boolean accepted(int sim)
          Accept the document currently being read as a hit.
 void close()
          Close all inverted lists of this rider.
 boolean defined(java.lang.String term)
          Test whether an inverted list has been constructed for the given term.
 long foundHits()
          Return the number of hits that were really read and identified as positive hits.
static CachedRider getCache()
          Gets the cache used for caching inverted list pages.
 long getLength(java.lang.String term)
          Return the length of the inverted list for the given term.
 long guessedHits()
           
 boolean hasMoreElements()
          Test whether more there are more documents to be read.
 long headUid()
          Return the unique ID of the document that is active in this Rider.
 long headUid(int mode)
          Return the uid of the doc just being read.
 double idf(java.lang.String term)
          Return the inverse document frequency for the given term.
static void initializeCache(Cache<CachedTerm,CachedIListPage> cache, int pageSize)
          Initializes the cache to be used for caching inverted lists.
 boolean isExhaused()
           
 long nextHit()
          Move to the next hit candidate.
 IListItem openIList(java.lang.String term, int mode, IListShadow washer)
          Return an IListReader capable of reading the inverted list constructed for the given term.
 long size()
          Return the size of the Barrel that is accessed by this Rider.
 long skipTo(boolean all, long id, int mode)
          Move to the document with the given unique ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_REQ

public static final int MODE_REQ
Inverted list of this mode is required for querying

See Also:
Constant Field Values

MODE_PRO

public static final int MODE_PRO
Inverted list of this mode is prohibited in queries

See Also:
Constant Field Values

MODE_MAY

public static final int MODE_MAY
Inverted list of this mode should be available, but it is not needed

See Also:
Constant Field Values

ALL

public static final boolean ALL
Move all inverted lists of this group

See Also:
Constant Field Values

ANY

public static final boolean ANY
Move at least one inverted list

See Also:
Constant Field Values
Constructor Detail

Rider

public Rider(int size,
             Barrel b,
             ResultList res)
Constructor for the Rider object. .

Parameters:
size - the number of inverted lists in a Barrel this Rider can open
b - the Barrel containing the inverted list(s)
res - hits will be communicated to the ResultList
Method Detail

getLength

public long getLength(java.lang.String term)
Return the length of the inverted list for the given term.

Parameters:
term - the term for which the inverted list was constructed
Returns:
the length of the inverted list

defined

public boolean defined(java.lang.String term)
Test whether an inverted list has been constructed for the given term.

Specified by:
defined in interface CWI
Parameters:
term - the term in question
Returns:
true if an inverted list exists for the given term, false otherwise

idf

public double idf(java.lang.String term)
Return the inverse document frequency for the given term.

Specified by:
idf in interface CWI
Parameters:
term - the term in question
Returns:
the inverse document frequency

initializeCache

public static void initializeCache(Cache<CachedTerm,CachedIListPage> cache,
                                   int pageSize)
Initializes the cache to be used for caching inverted lists.

Parameters:
cache - actual cache used for storing inverted list pages
pageSize - capacity of the inverted list page

getCache

public static CachedRider getCache()
Gets the cache used for caching inverted list pages.

Returns:
cache used for caching inverted list pages or null if the pages are not cached

openIList

public IListItem openIList(java.lang.String term,
                           int mode,
                           IListShadow washer)
Return an IListReader capable of reading the inverted list constructed for the given term.

Parameters:
term - the term in question
mode - see MODE_XXX of this ilist
washer - Description of the Parameter
Returns:
a new IListReader's head, or an existing one if already allocated.

isExhaused

public boolean isExhaused()

guessedHits

public long guessedHits()

foundHits

public long foundHits()
Return the number of hits that were really read and identified as positive hits.


size

public long size()
Return the size of the Barrel that is accessed by this Rider.

Returns:
the size of the Barrel

accepted

public boolean accepted(int sim)
Accept the document currently being read as a hit. Rider will check its own state and sends it together with the given similarity value to a ResultList defined in the constructor.

Parameters:
sim - the calculated similarity
Returns:
whether we ever want more hits to be added

headUid

public long headUid()
Return the unique ID of the document that is active in this Rider.

Returns:
the unique ID

headUid

public long headUid(int mode)
Return the uid of the doc just being read.

Parameters:
mode - see MODE_XXX
Returns:
the uid

hasMoreElements

public boolean hasMoreElements()
Test whether more there are more documents to be read.

Returns:
true if there are, false otherwise

skipTo

public long skipTo(boolean all,
                   long id,
                   int mode)
Move to the document with the given unique ID.

Parameters:
all - see ALL or ANY
id - the ID of the document to move to
mode - which group is processed
Returns:
the next uid, -1 on EOF
See Also:
IListReader.skipTo(long)

close

public void close()
Close all inverted lists of this rider.


nextHit

public long nextHit()
Move to the next hit candidate.

Returns:
the uid of the next hit, -1 on EOF