Skip to content

How to use Search Engine Services

o5faruk edited this page May 2, 2021 · 20 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/search-engine/

⚠️⚠️⚠️

Buildfire Search Engine

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.

Prerequisites

This service requires you to include buildfire/services/searchEngine/searchEngine.js with your plugin.

Methods

buildfire.searchEngine.insert(options,callback)

  • options: object
    • linkedUser: boolean (optional), This will make the data linked to the current logged user, which means it will be private.
    • tag: string (required), A unique key for your data, this is important for categorizing your data.
    • title: string (required), title for your data, this will be searchable by our search engine.
    • description: string (optional), description for your data, this will be searchable by our search engine.
    • keywords: string (optional), any keywords related to your data, this will be searchable by our search engine.
    • imageUrl: image url (optional), this will be searchable by our search engine.
    • data: object (optional), you can add whatever you want here, this won't be searchable by our search engine.

Important: options.data will be passed back to the plugin when deeplinking!

  • callback(err, result): callback function. result contains an id property, which is the id of the newly saved data.

Example:

var insertData = {
    tag: 'departments',
    title: 'HR Department',
    description: 'Performs human resource management',
    keywords: 'hr, department, human resource, management'
};

buildfire.services.searchEngine.insert(insertData, function (err, response) {
    if (err) {
        console.error('Error in inserting data', err);
    } else {
        console.log('Data Inserted', 'document id: ' + response.id);
    }
});

buildfire.searchEngine.save(options,callback)

  • options: object

    • linkedUser: boolean (optional), This will make the data linked to the current logged user, which means it will be private.
    • key: string (required), A unique key for your document, this is the id for your document.
    • tag: string (required), A unique key for your data, this is important for categorizing your data.
    • title: string (required), title for your data, this will be searchable by our search engine.
    • description: string (optional), description for your data, this will be searchable by our search engine.
    • keywords: string (optional), any keywords related to your data, this will be searchable by our search engine.
    • imageUrl: image url (optional), this will be searchable by our search engine.
    • data: object (optional), you can add whatever you want here, this won't be searchable by our search engine.
  • callback(err, result): callback function. result contains an id property, which is the id of the saved data.

Example:

var saveData = {
    key: 'your_unique_key',
    tag: 'departments',
    title: 'HR Department',
    description: 'Performs human resource management',
    keywords: 'hr, department, human resource, management'
};

buildfire.services.searchEngine.save(saveData, function (err, response) {
    if (err) {
        console.error('Error in saving data', err);
    } else {
        console.log('Data Saved', 'document id: ' + response.id);
    }
});

buildfire.searchEngine.update(options, callback)

  • options: object

    • id: string (required), An id for your document to update it.
    • linkedUser: boolean (optional), This will make the data linked to the current logged user, which means it will be private.
    • tag: string (required), A unique key for your data, this is important for categorizing your data.
    • title: string (required), title for your data, this will be searchable by our search engine.
    • description: string (optional), description for your data, this will be searchable by our search engine.
    • keywords: string (optional), any keywords related to your data, this will be searchable by our search engine.
    • imageUrl: image url (optional), this will be searchable by our search engine.
    • data: object (optional), you can add whatever you want here, this won't be searchable by our search engine.
  • callback(err, result): callback function. result contains an id property, which is the id of the updated data.

Example:

var updateData = {
    id: "data_id_goes_here",
    tag: 'departments',
    title: 'HR Department',
    description: 'Performs human resource management',
    keywords: 'hr'
};

buildfire.services.searchEngine.update(updateData, function (err, response) {
    if (err) {
        console.error('Error in updating data', err);
    } else {
        console.log('Data Updated', 'document id: ' + response.id);
    }
});

buildfire.searchEngine.delete(options, callback)

  • options: object

    • id: string (required), An id for your document to delete it.
    • tag: string (required), A unique key for your data, this is important for categorizing your data.
  • callback(err, result): callback function. result returns true if the data has been deleted.

Example:

var deleteData = {
    id: "data_id_goes_here",
    tag: 'departments'
};

buildfire.services.searchEngine.delete(deleteData, function (err, response) {
    if (err) {
        console.error('Error in deleting data', err);
    } else {
        console.log('Data Deleted: ' + response);
    }
});

buildfire.searchEngine.search(options, callback)

There are many factors affect the search result:

Fuzzy query

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

  • options: object

    • searchText: string (required), Your search text.
    • linkedUser: string (optional), If true this will return all public data and the data added by the current logged user.
    • pageIndex: string (optional, default: 0), Index of returned page.
    • pageSize: string (optional, default: 50), Size of data returned per page size.
    • preHighlightTag: string (optional), Use in conjunction with post_tags to define the HTML tags to use for the highlighted text.
    • postHighlightTag: string (optional), Use in conjunction with pre_tags to define the HTML tags to use for the highlighted text.
  • callback(err, data): callback function. Data contains the result for your search.

Example:

var searchData = {
    tag: 'departments',
    searchText: 'hr',
    pageSize: 30,
    pageIndex: 0,
    preHighlightTag : "<b>",
    postHighlightTag : "</b>",
};

buildfire.services.searchEngine.search(searchData, function (err, response) {
    if (err) {
        console.error('Error in searching data', err);
    } else {
        console.log(response.hits);
    }
});

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

  • options: object

    • tag: string (required), A unique key for your data, this is important for categorizing your data.
    • title: string (required), title for your feed.
    • description: string (optional), description for your feed.
    • feedType: string (required), type for your feed, available types:
      • rss
    • feedConfig (object, required):
      • url: feed url (required)
    • feedItemConfig (object, optional):
      • uniqueKey (string, optional, default: "guid"): the unique key for each item returned from rss service.
      • titleKey (string, optional, default: "title"): the title key for each item returned from rss service.
      • descriptionKey (string, optional, default: "description"): the description key for each item returned from rss service.
      • urlKey (string, optional, default: "link"): the url key for each item returned from rss service.
      • publishDateKey (string, optional, default: "pubDate"): the publish date key for each item returned from rss service.
      • imageUrlKey (string, optional, default: "thumbnail"): the image url for each item returned from rss service.
  • callback(err, data): callback function. Data will return true if feed has been attached.

Example:

var insertFeed = {
    tag: "news",
    title : "CNN Latest News RSS",
    description: "CNN Latest News",
    feedType : "rss",
    feedConfig: {
      url: "http://rss.cnn.com/rss/cnn_latest.rss"
    },
    feedItemConfig: {
      uniqueKey: "guid",
      titleKey: "title",
      urlKey: "link",
      publishDateKey: "pubDate"
    }
};

buildfire.services.searchEngine.feeds.insert(insertFeed, function (err, response) {
    if (err) {
        console.error('Error in inserting feeds', err);
    } else {
        console.log('Feed Inserted', 'Feed id: ' + response.id);
    }
});

var insertYoutubeFeed = {
    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"
    }
};

buildfire.services.searchEngine.feeds.insert(insertYoutubeFeed, function (err, response) {
    if (err) {
        console.error('Error in inserting youtube feed data', err);
    } else {
        console.log('Feed Inserted', 'Feed id: ' + response.id);
    }
});

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

  • options: object

    • tag: string (required), A unique key for your data, this is important for categorizing your data.
    • feedType: string (required), type for your feed, available types:
      • rss
  • callback(err, data): callback function. Data will return all the attached feeds related to the specified tag & type.

Example:

var getfeeds = {
  tag: "news",
  feedType : "rss"
};

buildfire.services.searchEngine.feeds.get(getfeeds, function (err, response) {
    if (err) {
        console.error('Error in getting data', err);
    } else {
        console.log('feeds list',response);
    }
});

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

  • options: object

    • tag: string (required), A unique key for your data, this is important for categorizing your data.
    • feedId: string (required), feed id that will be returned from feeds.list method.
    • removeFeedData: boolean (optional), if true, this will remove all feed data inside the app that's related to this feed.
  • callback(err, data): callback function. Data will return true if the feed has been detached.

Delete Feed Example:

var deleteFeed = {tag : "news", feedId :"feed_id_goes_here", removeFeedData : true};

buildfire.services.searchEngine.feeds.delete(deleteFeed, function (err, response) {
    if (err) {
        console.error('Error in deleting feed', err);
        showAlert('error');
    } else {
        console.log(response);
    }
});
Clone this wiki locally