Package net.sf.okapi.tm.pensieve.seeker
Class PensieveSeeker
- java.lang.Object
-
- net.sf.okapi.tm.pensieve.seeker.PensieveSeeker
-
- All Implemented Interfaces:
AutoCloseable
,Iterable<TranslationUnit>
,ITmSeeker
public class PensieveSeeker extends Object implements ITmSeeker, Iterable<TranslationUnit>
Used to query the TM- Author:
- Christian Hargraves, HARGRAVEJE
-
-
Constructor Summary
Constructors Constructor Description PensieveSeeker(org.apache.lucene.index.IndexWriter indexWriter)
Creates an instance of TMSeeker.PensieveSeeker(org.apache.lucene.store.Directory indexDir)
Creates an instance of TMSeeker
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the searcherprotected org.apache.lucene.search.IndexSearcher
createIndexSearcher()
org.apache.lucene.store.Directory
getIndexDir()
Get the current LuceneDirectory
protected org.apache.lucene.search.IndexSearcher
getIndexSearcher()
Iterator<TranslationUnit>
iterator()
gets an iterator to traverse all translation units in the indexdirprotected org.apache.lucene.index.IndexReader
openIndexReader()
List<TmHit>
searchExact(TextFragment query, Metadata metadata)
Get a list of exact matches for a given text fragment, taking inline codes in account.List<TmHit>
searchFuzzy(TextFragment queryFrag, int threshold, int max, Metadata metadata)
Search for exact and fuzzy matches-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
PensieveSeeker
public PensieveSeeker(org.apache.lucene.store.Directory indexDir) throws IllegalArgumentException
Creates an instance of TMSeeker- Parameters:
indexDir
- The Directory implementation to use for the queries- Throws:
IllegalArgumentException
- If the indexDir is not set
-
PensieveSeeker
public PensieveSeeker(org.apache.lucene.index.IndexWriter indexWriter) throws IllegalArgumentException
Creates an instance of TMSeeker. This constructor is used for near-real-time (NRT) mode to make index changes visible to a new searcher with fast turn-around time.- Parameters:
indexWriter
- The IndexWriter implementation to use for the queries, needed for NRT- Throws:
IllegalArgumentException
- If the indexDir is not set
-
-
Method Detail
-
iterator
public Iterator<TranslationUnit> iterator()
gets an iterator to traverse all translation units in the indexdir- Specified by:
iterator
in interfaceIterable<TranslationUnit>
- Returns:
- the iterator for translation units
-
getIndexDir
public org.apache.lucene.store.Directory getIndexDir()
Get the current LuceneDirectory
- Returns:
- the current Lucene
Directory
-
createIndexSearcher
protected org.apache.lucene.search.IndexSearcher createIndexSearcher() throws org.apache.lucene.index.CorruptIndexException, IOException
- Throws:
org.apache.lucene.index.CorruptIndexException
IOException
-
getIndexSearcher
protected org.apache.lucene.search.IndexSearcher getIndexSearcher() throws org.apache.lucene.index.CorruptIndexException, IOException
- Throws:
org.apache.lucene.index.CorruptIndexException
IOException
-
openIndexReader
protected org.apache.lucene.index.IndexReader openIndexReader() throws org.apache.lucene.index.CorruptIndexException, IOException
- Throws:
org.apache.lucene.index.CorruptIndexException
IOException
-
searchExact
public List<TmHit> searchExact(TextFragment query, Metadata metadata)
Description copied from interface:ITmSeeker
Get a list of exact matches for a given text fragment, taking inline codes in account.- Specified by:
searchExact
in interfaceITmSeeker
- Parameters:
query
- the fragment to search formetadata
- the metadata attributes to also match against, null for no metadata.- Returns:
- a list of exact matches
-
searchFuzzy
public List<TmHit> searchFuzzy(TextFragment queryFrag, int threshold, int max, Metadata metadata)
Search for exact and fuzzy matches- Specified by:
searchFuzzy
in interfaceITmSeeker
- Parameters:
queryFrag
- the fragment to query.threshold
- the minimal score value to return.max
- the maximum number of hits to return.metadata
- any associated attributes to use for filter.- Returns:
- the list of hits of the given argument.
- Throws:
IllegalArgumentException
- If threshold is greater than 100 or less than 0
-
close
public void close()
Description copied from interface:ITmSeeker
Close the searcher- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceITmSeeker
-
-