New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

doofinder

Package Overview
Dependencies
Maintainers
1
Versions
198
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doofinder

Javascript Library for Doofinder Search API

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
64
decreased by-55.56%
Maintainers
1
Weekly downloads
 
Created
Source

jsDoofinder

Is a library that allow you to make requests to Doofinder Search Engines and show the results in your website. You'll be able to retrieve and shape your data easily with it.

Summary

  • Installation
  • Quick Start
  • Classes

Installation

npm

npm install doofinder

bower

bower install doofinder

Downloadable minified javascript file

https://raw.githubusercontent.com/doofinder/js-doofinder/master/dist/doofinder.min.js

CSS

We offer some simple CSS. You can download it in the link https://raw.githubusercontent.com/doofinder/js-doofinder/master/dist/doofinder.css

Quick Start

In this example we'll write a view that will just show results.

Let's begin by showing a simple HTML template (myview.html):

<html lang="en">
<head>
<script type="application/javascript" src="path/to/your/js/doofinder.min.js"></script>
<script type="application/javascript" src="path/to/your/js/myview.js"></script>
</head>
<body>
  <input type="text" id="query"/>
  <div id="scroll">
    <div id="container"></div>
    </div>
  </div>
</body>

Note that we are importing two javascript files:

  • doofinder.min.js: contains doofinder namespace with its classes.
  • myview.js: contains specific info about my view and thats the place where we'll instantiate Controller.

We need to create the inner scroll via css.

#scroll{
    position: relative;
    height: 800px;
    overflow: auto;
}

Let's add some functionality to our html view:

(function(doofinder, document){
  
  var hashid = 'a3fd9dcvga0932el99ds4az';
  var zone = 'eu1';
  var queryInput = '#query';
  var scrollWrapper = '#scroll';
  var container = '#container'; // required

  $(document).ready(function(){ 
    // Instantiation
    var client = new doofinder.Client(hashid, zone);
    var queryInputWidget = new doofinder.widgets.QueryInput(queryInput);
    var resultsWidget = new doofinder.widgets.results.ScrollResults(
        scrollWrapper, 
        container
        );
    var controller = new doofinder.Controller(
        Client, 
        [queryInputWidget, resultsWidget]
        );
    

  });

})(doofinder, document);

The options we have filled in:

  • hashid: the unique hashid for your search engine.
  • zone: the zone where is your search engine (eu1, us1)
  • queryInput: the CSS selector of our query input.
  • scrollWrapper: the CSS selector for the scroll.
  • container: the CSS selector of our hits container.

At the moment, we have a search box where we can write a query and results we'll be shown since the fourth character we type and the results in a scroll who asks for the next page when last element is reached.

Classes

Controller

Controller is the class that manages client and widgets. Allows you to make different queries to your index and interact with the different widgets you will instantiate.

constructor
ArgumentCharacterTypeDescription
clientrequireddoofinder.ClientThe Search API wrapper
widgetsrequireddoofinder.Widget Array(doofinder.Widget)The widgets for interacting and painting results
initialParamsoptionalObjectAn object with params that will passed to the client for every search. You can use here all the parameters defined in Doofinder Search API.

This method make a query to the Search API and render the results.

ArgumentCharacterTypeDescription
queryrequiredStringThe query terms.
paramsoptionalObjectAn object with search parameters. You can use here all the parameters defined in Doofinder Search API.
nextPage

Ask for the next page, so increment the current and send the response to all widgets to render it.

getPage

Ask for a page. Then pass the response to all widgets to render it.

ArgumentCharacterTypeDescription
pagerequiredNumberThe page requested
addFilter

Adds a filter to the currently applied.

ArgumentCharacterTypeDescription
facetrequiredStringThe name of the facet.
valuerequiredString ObjectThe filter to add. This can be a String, if the facet is a term facet or an Object if it's a range.
removeFilter

Removes a filter from the currently applied.

ArgumentCharacterTypeDescription
facetrequiredStringThe name of the facet.
valuerequiredString ObjectThe filter to remove. This can be a String, if the facet is a term facet or an Object if it's a range.
refresh

Makes a search with the current filter status. Then, it calls to every widgets to render it.

addWidget

Adds a widget to the controller after the instantiation.

ArgumentCharacterTypeDescription
widgetrequireddoofinder.WidgetThe widget to add.

Widget

Widget is just a contract to accomplish for every widget we'll describe next. Once you have injected the wigdets to the controller.

bind

This method adds callback to an event triggered for the widget. Events are triggered for every widget when a query is going to be done or when results are received or when they are rendered in a widget.

ArgumentCharacterTypeDescription
eventrequiredStringThe query terms.
callbackrequiredFunctionThe function which receives the API Search response.

The events you can bind in widget are the described above. Note that each event sends different arguments to the callback in order to implement it properly.

Event NameCallback ArgumentsDescription
df:search
  • paramsObject: the object will be send as params to the Search API.
This event is triggered when controller.search is called.
df:next_page
  • paramsObject: the object will be send as params to the Search API.
This event is triggered when controller.nextPage is called.
df:get_page
  • paramsObject: the object will be send as params to the Search API.
This event is triggered when controller.getPage is called.
df:results_received
  • resObject: the Search API response
This event is triggered when new results are received from Search API.
df:results_rendered
  • resObject`: the Search API response
This event is triggered when the results are rendered in the widget.

widgets.QueryInput

This widget triggers searches when a user types on it.

constructor
ArgumentCharacterTypeDescription
selectorrequiredStringInput CSS selector.
optionsoptionalObjectOptions to configure the input.

The options to configure the input are:

OptionTypeDescription
waitNumbermilliseconds that the widget waits to check the input content length.
captureLengthNumbernumber of characters typed when first search is performed

widgets.results.Results

This widget shows the results in a DOM node. When a new search or filter is done or a new page is requested the new content will replace the older.

constructor
ArgumentCharacterTypeDescription
containerrequiredStringResults container CSS selector.
optionsoptionalObjectOptions to configure the input.

The options to configure the widget are:

OptionTypeDescription
templateStringTemplate to shape the results.
extraContextObjectExtra info you want to render in the template.

widgets.results.ScrollResults

This widget render the results in an DOM node with an inner scroll.

constructor
ArgumentCharacterTypeDescription
containerrequiredStringResults container CSS selector.
optionsoptionalObjectOptions to configure the input.

The options to configure the widget are:

OptionTypeDescription
templateStringTemplate to shape the results.
extraContextObjectExtra info you want to render in the template.

widgets.facets.TermFacet

This widget render a term facet in a list of terms.

constructor
ArgumentCharacterTypeDescription
containerrequiredStringResults container CSS selector.
optionsoptionalObjectOptions to configure the input.

The options to configure the widget are:

OptionTypeDescription
templateStringTemplate to shape the results.
extraContextObjectExtra info you want to render in the template.

widgets.facets.RangeFacet

This widget render a range facet in a slider. To show it properly is necessary some CSS. You can add this stylesheet:

https://raw.githubusercontent.com/doofinder/js-doofinder/master/dist/doofinder.css

constructor
ArgumentCharacterTypeDescription
containerrequiredStringResults container CSS selector.
optionsoptionalObjectOptions to configure the input.

The options to configure the widget are:

OptionTypeDescription
templateStringTemplate to shape the results.
extraContextObjectExtra info you want to render in the template.

Client

constructor
ArgumentCharacterTypeDescription
hashidrequiredStringThe unique search engine identifier.
API KeyrequiredStringThe secret key to authenticate the request.
typesoptionalArrayAn array of datatypes to restrict the queries to them.
search

This method performs a Search API call and retrieves the data. The data will be received by a callback function.

ArgumentCharacterTypeDescription
queryrequiredStringThe query terms.
paramsoptionalObjectThe query terms.
callbackrequiredFunctionThe function which receives the API Search response.

Keywords

FAQs

Package last updated on 30 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc