Skip to main content

Search Engine

buildfire.searchEngine#

This is a built-in APIs that allows your control or widget to access highly scalable full-text search service. It allows you to store, search big volumes of data quickly and in near real-time.

Requirements#

Widget#

Include searchEngine.js file in widget header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/services/searchEngine/searchEngine.js"></script>
</head>

Control#

Include searchEngine.js file in control header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../../scripts/buildfire/services/searchEngine/searchEngine.js"></script>
</head>

Methods#

insert()
#

buildfire.services.searchEngine.insert(options, callback)

Inserts a new item into search engine

buildfire.services.searchEngine.insert(
{
tag: "departments",
title: "HR Department",
description: "Performs human resource management",
keywords: "hr, department, human resource, management",
},
(err, response) => {
if (err) return console.error(err);
console.log("Data Inserted", "document id: " + response.id);
}
);

options#

NameTypeRequiredDescriptionDefault
linkedUserbooleannoThis will make the data linked to the current logged user, which means it will be private.
tagstringyesA unique key for your data, this is important for categorizing your data.
titlestringyesTitle for your data, this will be searchable by our search engine.
descriptionstringnoDescription for your data, this will be searchable by our search engine.
keywordsstringnoAny keywords related to your data, this will be searchable by our search engine.
iamgeUrlstringnoImage url on search results
dataobjectnoYou can add whatever you want here, this won't be searchable by our search engine.

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultobjectObject containing id property, which is the id of the newly saved data.

save()
#

buildfire.services.searchEngine.save(options, callback)

Saves a new item into search engine

buildfire.services.searchEngine.save(
{
tag: "departments",
title: "HR Department",
description: "Performs human resource management",
keywords: "hr, department, human resource, management",
},
(err, response) => {
if (err) return console.error(err);
console.log("Data saved", "document id: " + response.id);
}
);

options#

NameTypeRequiredDescriptionDefault
linkedUserbooleannoThis will make the data linked to the current logged user, which means it will be private.
tagstringyesA unique key for your data, this is important for categorizing your data.
keystringyesA unique key for your document, this is the id for your document.
titlestringyesTitle for your data, this will be searchable by our search engine.
descriptionstringnoDescription for your data, this will be searchable by our search engine.
keywordsstringnoAny keywords related to your data, this will be searchable by our search engine.
iamgeUrlstringnoImage url on search results
dataobjectnoYou can add whatever you want here, this won't be searchable by our search engine.

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultobjectObject containing id property, which is the id of the newly saved data.

update()
#

buildfire.services.searchEngine.update(options, callback)

Inserts a new item into search engine

buildfire.services.searchEngine.update(
{
id: "data_id_goes_here",
tag: "departments",
title: "HR Department",
description: "Performs human resource management",
keywords: "hr, department, human resource, management",
},
(err, response) => {
if (err) return console.error(err);
console.log("Data updated", "document id: " + response.id);
}
);

options#

NameTypeRequiredDescriptionDefault
idstringyesAn id for your document to update it.
linkedUserbooleannoThis will make the data linked to the current logged user, which means it will be private.
tagstringyesA unique key for your data, this is important for categorizing your data.
titlestringyesTitle for your data, this will be searchable by our search engine.
descriptionstringnoDescription for your data, this will be searchable by our search engine.
keywordsstringnoAny keywords related to your data, this will be searchable by our search engine.
iamgeUrlstringnoImage url on search results
dataobjectnoYou can add whatever you want here, this won't be searchable by our search engine.

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultobjectObject containing id property, which is the id of the newly saved data.

delete()
#

buildfire.services.searchEngine.delete(options, callback)

Inserts a new item into search engine

buildfire.services.searchEngine.delete(
{
id: "data_id_goes_here",
tag: "departments",
},
(err, response) => {
if (err) return console.error(err);
console.log("Data Deleted:", response);
}
);

options#

NameTypeRequiredDescriptionDefault
idstringyesAn id for your document to update it.
tagstringyesA unique key for your data, this is important for categorizing your data.

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultbooleanIndicates if data has been deleted

search()
#

buildfire.services.searchEngine.search(options, callback)

Searches the search engine items.

Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.

An edit distance is the number of one-character changes needed to turn one term into another. These changes can include:

  • Changing a character (box โ†’ fox)
  • Removing a character (black โ†’ lack)
  • Inserting a character (sic โ†’ sick)
  • Transposing two adjacent characters (act โ†’ cat)

To find similar terms, the fuzzy query creates a set of all possible variations, or expansions, of the search term within a specified edit distance. The query then returns exact matches for each expansion.

The number of edits which allowed in our search APIs is (2).

buildfire.services.searchEngine.search(
{
tag: "departments",
searchText: "hr",
pageSize: 30,
pageIndex: 0,
preHighlightTag: "<b>",
postHighlightTag: "</b>",
},
(err, response) => {
if (err) return console.error("Error in searching data", err);
console.log("Search results", response.hits);
}
);

options#

NameTypeRequiredDescriptionDefault
searchTextstringyesYour search text.
linkedUserstringyesIf true this will return all public data and the data added by the current logged user.
pageIndexstringnoIndex of returned page.0
pageSizestringnoNumber of results returned per page.50
preHighlightTagstringnoUse in conjunction with post_tags to define the HTML tags to use for the highlighted text.
postHighlightTagstringnoUse in conjunction with post_tags to define the HTML tags to use for the highlighted text.

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultbooleanSearch results

feeds.insert()
#

buildfire.services.searchEngine.feeds.insert(options, callback)

Inserts a new rss feed into search engine

buildfire.services.searchEngine.feeds.insert(
{
tag: "news",
title: "CNN Youtube feed",
description: "CNN Youtube Channel",
feedType: "rss",
feedConfig: {
url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCupvZG-5ko_eiXAupbDfxWw",
},
feedItemConfig: {
uniqueKey: "id",
titleKey: "title",
urlKey: "link",
descriptionKey: "media:group.media:description",
publishDateKey: "published",
imageUrlKey: "media:group.media:thumbnail.$.url",
},
},
(err, response) => {
if (err) return console.error("Error in inserting youtube feed data", err);
console.log("Feed Inserted", "Feed id: " + response.id);
}
);

options#

NameTypeRequiredDescriptionDefault
tagstringyesA unique key for your data, this is important for categorizing your data.
titlestringyesTitle for your feed.
descriptionstringyesDescription for your feed.
feedTypestringyesFeed type. Available types: "rss"
feedConfigobjectyesFeed config.
feedItemConfigobjectyesFeed item config.
options.feedConfig#
NameTypeRequiredDescriptionDefault
urlstringyesFeed url
options.feedItemConfig#
NameTypeRequiredDescriptionDefault
uniqueKeystringnoUnique key for each item returned from rss service."guid"
titleKeystringnoThe title for each item returned from rss service."title"
descriptionKeystringnoThe description key for each item returned from rss service."description"
urlKeystringnoThe url key for each item returned from rss service."link"
publishDateKeystringnoThe publish date key for each item returned from rss service."pubDate"
imageUrlKeystringnoThe image url key for each item returned from rss service."thumbnail"

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultbooleanIndicates if rss feed has been attached

feeds.get()
#

buildfire.services.searchEngine.feeds.get(options, callback)

Fetches rss feeds from search engine

buildfire.services.searchEngine.feeds.get(
{
tag: "news",
feedType: "rss",
},
(err, response) => {
if (err) return console.error("Error fetching feed data", err);
console.log("Feeds:", response);
}
);

options#

NameTypeRequiredDescriptionDefault
tagstringyesA unique key for your data, this is important for categorizing your data.
feedTypestringyesFeed type. Available types: "rss"

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultbooleanAll the attached feeds related to the specified tag & feedType.

feeds.delete()
#

buildfire.services.searchEngine.feeds.delete(options, callback)

Deletes rss feed from search engine

buildfire.services.searchEngine.feeds.delete(
{
tag: "news",
feedId: "feed_id_goes_here",
removeFeedData: true,
},
(err, response) => {
if (err) return console.error("Error in deleting feed", err);
console.log("Feed deleted", response);
}
);

options#

NameTypeRequiredDescriptionDefault
tagstringyesA unique key for your data, this is important for categorizing your data.
feedIdstringyesFeed id that will be returned from feeds.get method.
removeFeedDatabooleannoIf true, this will remove all feed data inside the app that's related to this feed.

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
resultbooleanIndicates if feed has been detached