Septima.Search.ClientSearcher
Extends Septima.Search.Searcher
Enables a client to add a custom searcher to Septima Search
Options
Name | Type | Mandatory | Default value | Description |
---|---|---|---|---|
singular | string | Yes | The singular form of the object type returned by the searcher, eg "Photo" | |
plural | string | Yes | The plural form of the object type returned by the searcher, eg "Photos" | |
provider | Object | Yes | searcher The provider or the global name of the provider object (provider = window[provider]) Must implement query(query, limit) |
Examples
Usage
Example
//Create a provider object, which MUST have a query method (see signature) and MAY have a get method. If results have an id attribute the get method MUST be implemented
// async provider.query(query, limit) must return
// {
// status: "ok|error",
// hits: nnn,
// results: results
// }, where
// results is an array of
// {
// title: "title",
// description: "description",
// [id: "id",]
// [geometry: null|geojsonobject]
// }
// async provider.get(id) must return
// {
// title: "title",
// description: "description",
// id: "id",
// [geometry: null|geojsonobject,]
// [data: object]
// }
var provider = {
"query": async function(query, limit){
var results = [];
for (var i = 0;i<limit;i++){
results.push({
title: "title " + i,
description: "description " + i,
geometry: null,
id: i
});
}
var result = {status: "ok", hits: 9999, results: results};
return result;
},
"get" async function(id){
return {
title: "title " + id,
description: "description " + id,
geometry: null,
id: id,
data: {"a": 1}
}
}
};
// Create a clientSearcher
var clientSearcher = new Septima.Search.ClientSearcher({
singular: "objekt",
plural: "objekter",
provider: provider
});
// Add the searcher to septima search
controller.addSearcher(clientSearcher);