This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Implementing the Client Library
benjaminwinger edited this page Oct 8, 2014
·
8 revisions
Permissions:
Note that to communicate with AIS, the application that uses the client library must have the permission: "dracode.permission.AIS_SEARCH"
Creating the IndexClient
IndexClient ic = new IndexClient(listener, context);
Once the IndexClient has established a connection with the remote AIS search service you can load files to be searched though the connectedToService funtion from the IndexListener interface.
@Override
public void connectedToService(){
ci.loadIndex(filePath);
}
IndexClient Methods
public boolean isServiceConnected(); // checks if the service is connected after
// the IndexClient has been initialized. If false, the
// service may not be installed
/* creates a service file to tell the indexer that the this app can handle parsing
files with the extensions in the list extensions
@params dir directory to store the file
name name of the service
extensions the extensions the file can parse
*/
public static void createServiceFile(String dir, String name, List<String> extensions);
/*
unloads the index for the file at filePath and disconnects from the
search service
*/
public void close(Context c, String filePath);
/*
manually calls for the building of an index if necessary. should not have to
be called if the indexer is running normally
*/
public void buildIndex(String filePath, ArrayList<String> contents);
/*
Tells the IndexService to load the file at filePath
Note that files do not need to be loaded to be searched and at the moment
there is no performance difference, but in future there will be a
considerable performance increase, especially with large indexes, when
loading an index before searching it.
Do not load more than a few documents at a time
*/
public void loadIndex(String filePath);
/*
Tells the IndexService to unload the file at filePath
can be used instead of close() to unload an index without disconnecting from the IndexService
*/
public void unloadIndex(final String filePath);
/*
calls for a search of the given term "text" of type either IndexClient.QUERY_STANDARD or
IndexClient.QUERY_BOOLEAN
starts search on page "page", returns set number "set" of "hits" results
if "kill" it will cancel any previous searches
*/
public void search(String text, int type, String filePath, int page, int hits, int set, boolean kill);
/*
same as search but searches in multiple files all starting at page 0. directories can be used to
search all files in that directory.
*/
public void searchIn(String text, int type, List<String> filePath, int hits, int set, boolean kill);
/*
same as searchIn but searches file names rather than contents
*/
public void searchInPath(String text, int type, List<String> filePath, int hits, int set, boolean kill)
IndexListener Methods
// called after IndexClient.buildIndex(filePath, contents)
// indicates that the index has been built and can be loaded with IndexClient.loadIndex(filePath)
@Override
public void indexCreated(String s);
// success equals:
// 0 if the index loaded successfully
// 1 if the index was already loaded
// 2 if the index doesn't exist; should manually call IndexClient.buildIndex(filePath, contents)
// -1 if there was an error while loading the index
@Override
public void indexLoaded(String file, int success);
// called after IndexClient.unloadIndex(filePath)
// indicates success or failure
@Override
public void indexUnloaded(String path, boolean result);
// called after IndexClient.find()
@Override
public void searchCompleted(String path, PageResult[] pageResults);
// called after IndexClient.findName()
@Override
public void searchCompleted(String s, List<String> ls);
// called if there was an error while searching
@Override
public void errorWhileSearching(String path, String error) {
Make sure to close the IndexClient when the activity closes.
@Override
public void onDestroy(){
...
ic.close(this, filePath);
}
Additionally, to enable file parsing, an application should create a service that extends Service and implements ClientService.
public interface ClientService {
/**
* Template
*/
/*private final MClientService.Stub mBinder = new MClientService.Stub() {
public List<String> getWords(String path){
return this.getWords(path);
}
};*/
/**
* Load libraries to access the file here so that it only has to be done once.
* Only load information specific to each file. Generic loading should be done in
* the onCreate function
* This will always be the first function called
*
* @param path - the path of the file to be loaded
*/
public void loadFile(String path);
/**
* The indexer will query the contents of each page one at a time.
* Sending all of the information at once is too large to transfer in some files.
*
* @param page - the page of the file to be returned
* @return - A string containing all of the words on the page
*/
public String getWordsForPage(int page);
/**
* @return - the number of pages in the file specified at loadFile(String path)
*/
public int getPageCount();
/*
Load as much as possible in the constructor as the loadFile function may
be called multiple times.
*/
public void onCreate();
public IBinder onBind(Intent i);
}