de.aitools.aq.invertedindex.core
Class Searcher<V extends Value>

java.lang.Object
  extended by de.aitools.aq.invertedindex.core.Searcher<V>

public class Searcher<V extends Value>
extends java.lang.Object

A class to search an inverted index instance.

Version:
$Id: Searcher.java,v 1.3 2011/04/18 19:57:36 trenkman Exp $
Author:
martin.trenkmann@uni-weimar.de

Method Summary
 void close()
          Closes the searcher.
 boolean contains(java.lang.String key)
          Convenience method to check, if the index contains some mapping for the given key.
 Postlist.Head getHead(java.lang.String key)
          Convenience method to search the Postlist.Head of some Postlist if only interested in that meta-data.
 Properties getProperties()
          Returns the Properties of the underlying index.
static
<V extends Value>
Searcher<V>
open(java.lang.Class<V> clazz, Configuration config)
          Opens and returns an index instance located in Configuration.getIndexDirectory().
 Postlist<V> search(java.lang.String key)
          Returns a iterable Postlist for the given key.
 Postlist<V> search(java.lang.String key, int num)
          Returns a iterable Postlist for the given key.
 Postlist<V> search(java.lang.String key, int begin, int num)
          Returns a iterable Postlist for the given key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

open

public static <V extends Value> Searcher<V> open(java.lang.Class<V> clazz,
                                                 Configuration config)
Opens and returns an index instance located in Configuration.getIndexDirectory(). The instantiation of the native equivalent will fail, if the the given class of the index' value type does not match the type of the index on disk.

Type Parameters:
V - the value type, which is some derivative of Value.
Parameters:
clazz - the class object of the index' value type
config - the configuration of the index to load. Only parameters Configuration.getIndexDirectory() and Configuration.getMaxMemoryUsage() will be evaluated.
Returns:
a ready to use index searcher

close

public void close()
Closes the searcher. Call this method in some cleanup code to cleanly shutdown and to delete the native searcher. The searcher is then not usable anymore.


contains

public boolean contains(java.lang.String key)
Convenience method to check, if the index contains some mapping for the given key. Do not use this method, if you are going to lookup the Postlist, if such a mapping exists. For that reasons try to directly search the postlist and skip if empty.

Parameters:
key - the key to check for, if some mapping exist
Returns:
true if some mapping for the given key exist, false otherwise
See Also:
getHead(String), search(String), search(String, int), search(String, int, int)

getHead

public Postlist.Head getHead(java.lang.String key)
Convenience method to search the Postlist.Head of some Postlist if only interested in that meta-data. Do not use this method, if you are going to lookup the entire postlist afterwards. For that reasons try to directly search the postlist and skip if empty.

Parameters:
key - the key of the postlist to lookup the head for
Returns:
the Postlist.Head or null if the key is unknown
See Also:
search(String), search(String, int), search(String, int, int)

getProperties

public Properties getProperties()
Returns the Properties of the underlying index.

Returns:
the Properties of this index

search

public Postlist<V> search(java.lang.String key)
Returns a iterable Postlist for the given key.

Parameters:
key - the key to search the inverted index for
Returns:
a Postlist instance, or null for unknown keys
See Also:
search(String, int), search(String, int, int)

search

public Postlist<V> search(java.lang.String key,
                          int num)
Returns a iterable Postlist for the given key. The postlist will be truncated at the end to contain at most the first num elements. The corresponding range is [0, num). Use this method to efficiently lookup the wanted top-k entries.

Parameters:
key - the key to search the inverted index for
num - the maximal number of postlist elements to load
Returns:
a Postlist instance, or null for unknown keys
See Also:
search(String), search(String, int, int)

search

public Postlist<V> search(java.lang.String key,
                          int begin,
                          int num)
Returns a iterable Postlist for the given key. The postlist will be loaded from the index specified by begin with at most the num following elements from that position. The corresponding range is [begin, begin + num). If begin is not a valid index the returned postlist will be empty.

Parameters:
key - the key to search the inverted index for
begin - the index of the first postlist element to load
num - the maximal number of postlist elements to load
Returns:
a Postlist instance, or null for unknown keys
See Also:
search(String), search(String, int)