Engine plugins API

Engine plugin is a module which receives query, performs some action and returns the search results.

There are several subtypes of search plugin:

1. Query rewriter - changes query text before it is parsed by search engine command factory. One of the useful example of this plugin type is query syntax modification, e.q. you can change the boolean operators OR, AND, NOT to something else without the need to modify search engine query parser.

2. Simple searcher - returns single page of results, for example - result of arithmetical calculation or database information retrieval.

3. Searcher - returns the list of documents which match the query condition, for example - web metasearch.

4. Active scripter - returns an algorithm (script) which controls the search engine execution.

FAIND invokes an engine plugin when option -engine is used in command line.

Location

Usually the plugin DLLs are stored in c:\program files\integra\plugins\engines. Search engine initialization code looks up this folder for *.dll and tries to load each of them as a plugin.

API

1. Plugin instance construction and initialization

 void* Constructor(void)

This procedure is called once per search engine session. Its main purpose is to load all necessary DLL, read configuration files and so on.

It returns the pointer to plugin object which is used in all subsequent calls as This argument.

2.  Plugin instance destruction

void Destructor( void *This )

It frees resources allocated by plugin instance during Constructor call.

This procedure is call on search engine termination.

3. Plugin features and options retrieval

const wchar_t* GetSolarixPluginProperty( void *This, int iProp, int iSub )

Search engine determines the features and characteristics of the plugin using this procedure. iProp and iSub are required property id and sub-id. String value of property is returned if possible. If property is not supported just returns NULL.

There are some minimal set of required properties:

iProp iSub Meaning
0 Must be "engine_plugin" for content plugins
1 Plugin human readable name, e.q. "Wikipedia searcher"
2 Copyright string
3 Internal name for usage in command line, e.g. "websearch"
4 Plugin subtype, "QueryRewriter", "SimpleSearcher", "Searcher" or "ActiveScriptor"

Future vesions of search engine may acquire another prorerties. Return NULL if you don't know the meaning of the required property.

4. Start searching (for Searcher subtype)

void* Search( void *This, void *ISearchEnginePtr, IGrammarEngine *IGrammarEnginePtr, const wchar_t *Query, const wchar_t *Params )

Pointer to results dataset is returned. This pointer is used in Fetch calls for retrieve records.

IGrammarEngine is a pointer to Grammar Engine interface.

Argument ISearchEnginePtr is not used in current version of search engine and set to NULL.

5. Fetch the next record in result dataset (for Searcher subtype)

int Fetch(
            void *This,
            void *Results,
            wchar_t *Title, int TitleSize,
            wchar_t *Filename, int FilenameSize,
            wchar_t *Snippet, int SnippetSize,
            char *SnippetHtml, int SnippetHtmlSize,
            char *CacheUrl, int CacheUrlSize,
            double *Rank
           )

Next available record fields are loaded into Title, Filename, Snippet or SnippetHtml, CacheUrl and Rank values.

Title - document title, human readable. May be different from document filename.

Filename - document filepath or URL.

Snippet and SnippetHtml - document fragment with matched keywords

CacheUrl - optional buffer for local copy of remote document

Rand - document match rank.

6. Search operation is complete (for Searcher subtype)

void SearchComplete( PluginObject *This, Results *res )

This call frees all resources allocated in Search API call.

7. Simple search operation (for SimpleSearcher plugin subtype)

bool SimpleSearch(
                    PluginObject *This,
                    void *ISearchEngine,
                    void *IGrammarEnginePtr,
                    const Query_Data *QueryDataPtr,
                    wchar_t **Result,
                    int *ResultFormat
                    )

If successfull, this procedure must return true. Result string is returned through Result. Result format argument valid values: 0 - plain text, 1 - HTML.

Buffer for results is owned by plugin. Search engine calls Free procedure in order to free this memory.

9. Rewrite query (for QueryRewriter plugin subtype)

bool RewriteQuery( void *This, void *ISearchEngine, void *IGrammarEnginePtr, QueryData *QueryDataPtr )

Original query text and result are passed via QueryDataPtr.

Plugin returns true is it really change the query, false otherwise.

9. Free memory block

void Free( void *This, void *Ptr )

This procedure frees the memory allocated by SimpleSearch.

10. Last error code

int GetError( PluginObject *This )

0 - no error.

Samples

Source code for plugins is available as part of search engine source code.

Calculator (\lem\demo\ai\solarix\search\engine_plugin\calculator) is a Simple Searcher plugin. It tries to interpret the query pattern as arithmetic expression. If successful it return the result of calculation.

FAIND.Remote (\lem\demo\ai\solarix\search\engine_plugin\Faind) is a Searcher plugin. It sends queries to remote Integra/Faind server and parse response making it possible to perform distributed searches.

GDS (\lem\demo\ai\solarix\search\engine_plugin\gds) is another Searcher engine plugin. It sends queries to local Google desktop search engine, then parse the response and return the results to engine core.


© Mental Computing 2009  rss  email  icq free counters Πειςθνγ@Mail.ru