org.cdlib.xtf.textEngine
Class BoostSet

Object
  extended by BoostSet

public class BoostSet
extends Object

Holds a set of boost factors to apply to individual documents in the document set.

Author:
Martin Haye

Nested Class Summary
private  class BoostSet.DocIter
          Iterates all the document keys in an index
private  class BoostSet.LineIter
          Iterates all the lines in a boost file
 
Field Summary
private  float[] boostByDoc
          Set of boost values, one per document ID
private static WeakHashMap cache
          Cached data.
private static float DEFAULT_MARKER
          Marker for the default value
private  String field
          Field to find document keys in
private  int nWarnings
          Number of warnings emitted so far.
 
Constructor Summary
private BoostSet(IndexReader indexReader, File inFile, String field)
          Do not construct directly; use getCachedSet(IndexReader, File, String) instead.
 
Method Summary
 float getBoost(int docId, float defaultBoost)
          Get the boost factor associated with the given document, or the default boost value if not found.
static BoostSet getCachedSet(IndexReader indexReader, File inFile, String field)
          Retrieves BoostSet for a given File from a given reader.
private  void warn(String msg)
          If less than 10 warnings have been emitted, we print this one out.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

private static WeakHashMap cache
Cached data. If the reader goes away, our cache will too.


field

private String field
Field to find document keys in


nWarnings

private int nWarnings
Number of warnings emitted so far. After 10, we suppress them.


boostByDoc

private float[] boostByDoc
Set of boost values, one per document ID


DEFAULT_MARKER

private static float DEFAULT_MARKER
Marker for the default value

Constructor Detail

BoostSet

private BoostSet(IndexReader indexReader,
                 File inFile,
                 String field)
          throws IOException
Do not construct directly; use getCachedSet(IndexReader, File, String) instead. Constructs a BoostSet by reading a file containing document key -> boost factor mappings, and correlating it with the keys in the given index reader.

Throws:
IOException
Method Detail

getCachedSet

public static BoostSet getCachedSet(IndexReader indexReader,
                                    File inFile,
                                    String field)
                             throws IOException
Retrieves BoostSet for a given File from a given reader. Maintains a cache so that if the same File is requested again for this reader, we don't have to re-read the boost data.

Parameters:
indexReader - Index to correlate the data to
inFile - Which file to read
field - Field used to key boost values
Returns:
Group data for the specified field
Throws:
IOException

getBoost

public final float getBoost(int docId,
                            float defaultBoost)
Get the boost factor associated with the given document, or the default boost value if not found.

Parameters:
docId - Document ID to look up
defaultBoost - What to return if not found
Returns:
Boost factor, or defaultBoost if not found.

warn

private void warn(String msg)
If less than 10 warnings have been emitted, we print this one out. Otherwise, we suppress it.

Parameters:
msg - The message to emit