Skip to main content

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.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.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.

tip

If your inserted records don't have unique keys, use insert method. However, if you do have unique keys, it's recommended to use save method.

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

console.log("Data Inserted", "Search engine record id: " + result.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.
imageUrlstringnoImage 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 successful
resultobjectObject containing id property, which is the id of the newly saved data.

result

NameTypeDescription
idstringSearch engine record id.

save()

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

Saves a new item into search engine.

tip

Use save method for both inserting and updating records. It creates a new record if it's new, and updates an existing one if it already exists.

buildfire.services.searchEngine.save(
{
tag: "departments",
key: "unique_key",
title: "HR Department",
description: "Performs human resource management",
keywords: "hr, department, human resource, management",
},
(err, result) => {
if (err) return console.error(err);

console.log("Data saved", "Search engine record id: " + result.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 record.
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.
imageUrlstringnoImage 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 successful
resultobjectObject containing id property, which is the id of the newly saved data.

result

NameTypeDescription
idstringSearch engine record id.

update()

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

Update existing item into search engine.

buildfire.services.searchEngine.update(
{
id: "Search_engine_record_id_goes_here",
tag: "departments",
title: "HR Department",
description: "Performs human resource management",
keywords: "hr, department, human resource, management",
},
(err, result) => {
if (err) return console.error(err);

console.log("Data updated", "Search engine record id: " + result.id);
}
);

options

NameTypeRequiredDescriptionDefault
idstringyesSearch engine record id returned from insert or save methods.
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.
imageUrlstringnoImage 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 successful
resultobjectObject containing id property, which is the id of the newly saved data.

result

NameTypeDescription
idstringSearch engine record id.

delete()

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

Deletes item from search engine.

note

This method supports deletion using either the search engine record's id or key, prioritizing id if both are provided.

tip

If possible, use the key field. Keep in mind that records created with insert method do not have keys, so you'll need to use search engine record id in those cases.

buildfire.services.searchEngine.delete(
{
key: "unique_key", // you can instead use (id:) with insert, save or update result id
tag: "departments"
},
(err, result) => {
if (err) return console.error(err);

console.log("Data Deleted:", result);
}
);

options

NameTypeRequiredDescriptionDefault
idstringnoSearch engine record id returned from insert or save methods. Will be required if key not provided.
keystringnoA unique key for your record. Available for records created by save method only. Will be required if id not provided.
tagstringyesA unique key for your data, this is important for categorizing your data.

callback(err, result)

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

search()

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

Searches the search engine items.

Returns records 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 successful
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 successful
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 successful
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 successful
resultbooleanIndicates if feed has been detached