An index is the main object in which searching is done. After creating an index via the search Aptitude, a Loop author can query the indexed documents or modify the indices through this interface.
search
Searches anywhere in the documents for the specified term.
import { search } from '@oliveai/ldk';
// See the main search page for opening and creating an index
// We'll be using the index created in the createIndex example
const indexName = "myIndex";
const config = {
sortBy: ['-lastName', 'firstName'],
searchSize: 10,
exactMatchThreshold: 4,
beginWithSearch: true,
};
search.openIndex(indexName, config).then( index => {
myIndex.search("geo").then( result => {
console.log(JSON.stringify(result));
});
});
/*
{
"data": [
{
"_documentName": "George Smith",
"_type": "George Smith",
"firstName": "George",
"lastName": "Smith"
},
{
"_type": "Geoffrey McPerson",
"firstName": "Geoffrey",
"lastName": "McPerson",
"_documentName": "Geoffrey McPerson"
},
{
"firstName": "George",
"lastName": "Jones",
"_documentName": "George Jones",
"_type": "George Jones"
}
],
"total": 3
}
*/
queryStringSearch
Provides the capability to do a more advance search allowing the loop author to search on specific fields (<fieldname>:<search value>) as well as regex (*.+?, etc..). You can see more of what we support here.
import { search } from '@oliveai/ldk';
// See the main search page for opening and creating an index
// We'll be using the index created in the createIndex example
const indexName = "myIndex";
const config = {
sortBy: ['-lastName', 'firstName'],
searchSize: 10,
exactMatchThreshold: 4,
beginWithSearch: true,
};
search.openIndex(indexName, config).then( index => {
myIndex.queryStringSearch("lastName:Jones").then( result => {
console.log(JSON.stringify(result));
});
});
/*
{
"data": [
{
"_documentName": "George Jones",
"_type": "George Jones",
"firstName": "George",
"lastName": "Jones"
}
],
"total": 1
}
*/
update
Updates the index to point to a new set of documents and a new configuration.
import { search } from '@oliveai/ldk';
// See the main search page for opening and creating an index
// as well as an example on documents and configuration objecs
const index = await search.openIndex(indexName, config);
const newDocuments = getUpdatedDocuments();
const newConfig = getUpdatedConfig();
index.update(newDocuments, newConfig);
delete
Deletes the specified index. Attempting to use the index after it has been deleted will result in an error being thrown.
import { search } from '@oliveai/ldk';
// See the main search page for opening and creating an index
search.openIndex(indexName, config).then( index => {
index.delete();
});