net.sf.dictccfe.and
Class Search

java.lang.Object
  extended by net.sf.dictccfe.and.Thr
      extended by net.sf.dictccfe.and.Search
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SearchExact, SearchSimilar

public abstract class Search
extends Thr

Base class for exact and similar searching.

Version:
$Revision$
Author:
Daniel Stoinski

Nested Class Summary
 class Search.DictConfig
          Dictionary configuration.
 
Field Summary
private  Search.DictConfig m_cfg
          Dictionary configuration.
private  android.database.sqlite.SQLiteDatabase m_db
          The dictionary index database.
private  java.lang.CharSequence m_keyword
          The keyword to search.
private  ISearchResult m_searchresult
          The callback for results.
 
Constructor Summary
Search()
          Initializes an empty object.
 
Method Summary
protected abstract  void dosearch(android.database.sqlite.SQLiteDatabase aDb, java.lang.CharSequence aKey, ISearchResult aSearchResult)
          The real implementation of the searching algorithm.
protected  Search.DictConfig getDictConfig()
          Returns the configuration of the dictionary index database.
private static java.io.File getDictFile(java.lang.String aDictFileName)
          Returns the full path of the dictionary file.
 void run()
          Searches for keywords or descriptions.
 void search(java.lang.CharSequence aKey, ISearchResult aSearchResult)
          Searches for the keyword.
 void setDb(android.database.sqlite.SQLiteDatabase aDb)
          Sets the dictionary index database.
 
Methods inherited from class net.sf.dictccfe.and.Thr
getGoon, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_db

private android.database.sqlite.SQLiteDatabase m_db
The dictionary index database.


m_cfg

private Search.DictConfig m_cfg
Dictionary configuration.


m_keyword

private java.lang.CharSequence m_keyword
The keyword to search.


m_searchresult

private ISearchResult m_searchresult
The callback for results.

Constructor Detail

Search

public Search()
Initializes an empty object.

Method Detail

getDictFile

private static java.io.File getDictFile(java.lang.String aDictFileName)
Returns the full path of the dictionary file. It first tries the basename of the given path relatively to IdxLoader.DICT_DIR. If such file does not exist, then the method to open the given filename as it is.

Parameters:
aDictFileName - the dictionary file name.
Returns:
the name of the dictionary file. null if none of the dictionary files were found.

setDb

public final void setDb(android.database.sqlite.SQLiteDatabase aDb)
Sets the dictionary index database. It also compiles SQL statements returned by getStatementStrings() into the array of statements stmts.

Parameters:
aDb - the dictionary index database to set.

getDictConfig

protected final Search.DictConfig getDictConfig()
Returns the configuration of the dictionary index database.

Returns:
the configuration of the dictionary index database. May be also null.

search

public final void search(java.lang.CharSequence aKey,
                         ISearchResult aSearchResult)
Searches for the keyword.

Parameters:
aKey - the keyword to search.
aSearchResult - interface for search result callbacks.

run

public final void run()
Searches for keywords or descriptions. In fact in only calls dosearch() for the database, keyword and the interface for result callbacks.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class Thr

dosearch

protected abstract void dosearch(android.database.sqlite.SQLiteDatabase aDb,
                                 java.lang.CharSequence aKey,
                                 ISearchResult aSearchResult)
                          throws java.lang.Exception
The real implementation of the searching algorithm.

Parameters:
aDb - the database in which to search for keywords and/or description. It is never null.
aKey - the keyword to search. It is never null.
aSearchResult - the interface for search result callbacks. This parameter may be null.
Throws:
java.lang.Exception - the exceptions throw by this method are shown using ISearchResult.showException().