QuestAgent Search Applet API
The core functionality of QuestAgent’s search feature is provided by QuestAgent’s Java search applet. This applet exposes methods that provide developers with access to its search engine features. Using QuestAgent Applet API you can run queries, obtain results, highlight keywords in found documents, etc. Combining these features with JavaScript’s ability to create HTML pages dynamically, you can create fully customized search interface for your web pages.
The QuestAgent already comes with a JavaScript API around the search applet. You may consider using this as a base for your customization.
Put simple, the most common applet API usage usage scenario looks like this:
- The QuestAgent search applet is initialized hidden (zero with and/or height) in some browser frame. That frame should not be discharged or reloaded as long as the search engine is needed.
- JavaScript is used to access the search applet’s API, to initiate search and dynamically create pages showing obtained results.
In order to successfully use QuestAgent Applet API and make changes to deployed templates, you should have at least the basic understanding of JavaScript.
Although all QuestAgent search applets provide access to the API, it’s recommended use of com.jobjects.quest.agent.LiveConnectApplet Java class, which is located in deployed jar file archive. LiveConnectApplet is a Java applet that does not provide any graphical user interface as it’s expected that all interaction will be provided by JavaScript implementation.
QuestAgent API relies on LiveConnect technology that enables communication and data interchange between Java and JavaScript. If LiveConnect is not supported (or was disabled) by browser, search interface implemented in JavaScript won’t be able to access search applet.
Getting information about available collections
| Public API method | Description |
|---|---|
int getCollectionCount() |
Returns number of index files accessible to search engine. |
String getCollectionName(int collIndex) |
Returns the name of a specified document collection. Parameter collIndex is zero based (in range 0 to (getcollectionCount()-1). |
String getCollectionId(int collIndex) |
Returns the string ID of a specified collection. |
Preparing and running search
| Public API method | Description |
|---|---|
void selectCollection(String collectionID) |
Adds specified collection to the list of selected collections. One or more collections can be selected for searching. |
void unselectCollection(String collectionID) |
Removes specified collection from the list of selected collections. |
void unselectAllCollections() |
Clears the list of selected collections. |
void setMaxHits(int maxHits) |
Set maximal number of hits to be returned for the next search. |
void setStartHit(int startHit) |
Set the first hit you want to read from results. Result enumeration starts from 1. |
int search(String query) |
Returns number of hits or negative value indicating that callback will be used. |
Obtaining results
| Public API method | Description |
|---|---|
int getHitCount() |
Returns number of hits available in the result set. |
int getTotalHitCount() |
Returns number of hits found. |
int getFirstHit() |
Returns index of the first hit available in the result set. |
int getLastHit() |
Returns index of the last hit available in the result set. |
String getHitTitle(int hitIndex) |
Returns document title for a specified hit index. If document has no title, returns its path (location). |
String getHitLocation(int hitIndex) |
Returns document location for a specified hit index. Location is relative to its collection directory prefixed with value of locationPrefix parameter (if specified). |
String getHitField(int hitIndex, String field) |
Returns the content of a specified stored field. |
int getHitFieldValuesCount(int hitIndex, String field) |
For the specified multi-value field returns number of values. |
String getHitFieldValue(int hitIndex, String field, int valueIndex) |
For the specified multi-value field returns value at the specified index. Index is zero-based. |
int getHitRelevance(int hitIndex) |
Returns hit relevance (score) in range 1 to 100. |
String getHitOrigin(int hitIndex) |
Returns collection ID the specified hit comes from. |
int getLogMessagesCount() |
Returns number of messages received from search engine. |
String getLogMessage(int msgIndex) |
Returns specified search log message. |
int getLogMessageType(int msg) |
Returns specified search log message type. Type values are: DEBUG = 1; INFO = 2; WARN = 3; ERROR = 4; FATAL = 5 |
boolean hasCachedResults() |
Returns true if search applet has results of the last query cached. |
Document highlighting
| Public API method | Description |
|---|---|
void setHighlightingTags(String before, String after) |
Sets HTML tags to be used for word highlighting. |
void setNavigationButtons(String prev, String next ) |
Sets HTML tags to be used as a visual identification for navigation controls (“go to the previous keyword match” and “go to the next keyword match”) used in document highlighting. |
void setNavigationLinkScheme(String openTagStart, String openTagEnd, String closeTag) |
Sets parts of link used for navigation controls. |
String highlightDocument(int hitIndex, boolean insertNavLinks) |
Highlights specified document (identified by its hit index). |
void highlightDocumentCB(int hitIndex, boolean insertNavLinks, String callbackFn) |
Highlights specified document (identified by its hit index) and delivers page to the specified JavaScript function. |
String highlightDocDirect(String file, boolean insertNavLinks) |
Highlights specified file. |
void highlightDocDirectCB(String file, boolean insertNavLinks, String callbackFn) |
Highlights specified file and delivers page to the specified JavaScript function. |
String getDocumentBase(String name) |
Returns document base for a specified document location. |
Related Search Applet Parameters
| Parameter Name | Parameter Description |
|---|---|
js.OnAppletInitialized |
Defines the name of a JavaScript function to be invoked after search applet has been initialized. |
js.OnSearchResults |
Defines the name of a JavaScript function that accepts result of a query ran in the background. Signature of callback function should be function OnSearchResults(res) where res is variable used as an integer. |
js.OnShowResource |
Specifies JavaScript callback function that supersedes applet’s handling of requests to show a document forwarding all such requests to this function. Signature of callback function is function OnShowResource( location_String, hitIndex_int, newWin_Boolean ) |
js.OnNoLCPage js.OnNoLCFrame |
Parameter js.OnNoLCPage defines HTML page that should be loaded in case that browser does not support LiveConnect. Parameter js.OnNoLCFrame defines target frame for this page. You can use these parameters to forward user to an alternative search interface (Classic Search Applet for example). |