algoliasearch-helper
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "algoliasearch-helper", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Helper for implementing advanced search features with algolia", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"watch": "watchify index.js -v -s algoliasearchHelper -o dist/algoliasearch.helper.js", | ||
"build": "browserify index.js -s algoliasearchHelper -o dist/algoliasearch.helper.js", | ||
"build": "browserify index.js -s algoliasearchHelper -o dist/algoliasearch.helper.js && ccjs dist/algoliasearch.helper.js > dist/algoliasearch.helper.min.js", | ||
"minify-build": "uglifyjs dist/algoliasearch.helper.js --mangle --compress=warnings=false > dist/algoliasearch.helper.min.js", | ||
@@ -32,2 +32,3 @@ "dev": "DEBUG=zuul* zuul --no-coverage --local 8080 --ui tape test/run.js", | ||
"bulkify": "1.1.1", | ||
"closurecompiler": "1.5.1", | ||
"eslint": "0.17.1", | ||
@@ -34,0 +35,0 @@ "http-server": "0.8.0", |
@@ -41,6 +41,20 @@ # algoliasearch-helper-js | ||
## Examples in action | ||
## How to use this module | ||
http://algolia.github.io/algoliasearch-helper-js/ | ||
(See the examples in action)[http://algolia.github.io/algoliasearch-helper-js/] | ||
### Use with NPM | ||
`npm install algoliasearch-helper` | ||
### Use with bower | ||
`bower install algoliasearch-helper` | ||
### Use the CDN | ||
Include this in your page : | ||
`<script src="//cdn.jsdelivr.net/algoliasearch.helper/1.0.0/algoliasearch.helper.min.js"></script>` | ||
## How to contribute | ||
@@ -47,0 +61,0 @@ |
"use strict"; | ||
var extend = require( "./functions/extend" ); | ||
/** | ||
* Initialize a new AlgoliaSearchHelper | ||
* @param {AlgoliaSearch} client an AlgoliaSearch client | ||
* @param {string} index the index name to query | ||
* @param {hash} options an associative array defining the hitsPerPage, list of facets and list of disjunctive facets | ||
*/ | ||
function AlgoliaSearchHelper( client, index, options ) { | ||
var defaults = { | ||
// list of facets to compute | ||
facets : [], | ||
// list of disjunctive facets to compute | ||
disjunctiveFacets : [], | ||
// number of hits per page | ||
hitsPerPage : 20, | ||
// the default list of facetFilters | ||
defaultFacetFilters : [] | ||
}; | ||
var defaults = AlgoliaSearchHelper.optionsDefaults; | ||
var optionsWithDefaults = extend( {}, defaults, options ); | ||
this.init( client, index, extend( {}, defaults, options ) ); | ||
this.client = client; | ||
this.index = index; | ||
this.options = optionsWithDefaults; | ||
this.page = 0; | ||
this.refinements = {}; | ||
this.excludes = {}; | ||
this.disjunctiveRefinements = {}; | ||
this.extraQueries = []; | ||
} | ||
AlgoliaSearchHelper.optionsDefaults = { | ||
// list of facets to compute | ||
facets : [], | ||
// list of disjunctive facets to compute | ||
disjunctiveFacets : [], | ||
// number of hits per page | ||
hitsPerPage : 20, | ||
// the default list of facetFilters | ||
defaultFacetFilters : [] | ||
}; | ||
AlgoliaSearchHelper.prototype = { | ||
@@ -23,19 +40,2 @@ constructor : AlgoliaSearchHelper, | ||
/** | ||
* Initialize a new AlgoliaSearchHelper | ||
* @param {AlgoliaSearch} client an AlgoliaSearch client | ||
* @param {string} index the index name to query | ||
* @param {hash} options an associative array defining the hitsPerPage, list of facets and list of disjunctive facets | ||
*/ | ||
init : function( client, index, options ) { | ||
this.client = client; | ||
this.index = index; | ||
this.options = options; | ||
this.page = 0; | ||
this.refinements = {}; | ||
this.excludes = {}; | ||
this.disjunctiveRefinements = {}; | ||
this.extraQueries = []; | ||
}, | ||
/** | ||
* Perform a query | ||
@@ -48,2 +48,9 @@ * @param {string} q the user query | ||
search : function( q, searchCallback, searchParams ) { | ||
// handle .search( q, searchParams, searchCallback ) | ||
if ( typeof searchParams === "function" ) { | ||
var tmpCb = searchParams; | ||
searchParams = searchCallback; | ||
searchCallback = tmpCb; | ||
} | ||
this.q = q; | ||
@@ -192,9 +199,4 @@ this.searchCallback = searchCallback; | ||
var refinement = facet + ":" + value; | ||
if ( this.refinements[refinement] ) { | ||
return true; | ||
} | ||
if ( this.disjunctiveRefinements[facet] && this.disjunctiveRefinements[facet][value] ) { | ||
return true; | ||
} | ||
return false; | ||
return this.refinements[refinement] || | ||
(this.disjunctiveRefinements[facet] && this.disjunctiveRefinements[facet][value]); | ||
}, | ||
@@ -210,6 +212,3 @@ | ||
var refinement = facet + ":-" + value; | ||
if ( this.excludes[refinement] ) { | ||
return true; | ||
} | ||
return false; | ||
return !!this.excludes[refinement]; | ||
}, | ||
@@ -216,0 +215,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24909
12
490
73
14
1