Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: index unicode fields for icons for enable unicode search #65

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ module.exports = function(grunt) {
grunt.registerTask('build', ['merge-json', 'compile-handlebars']);

grunt.registerTask('index', 'Push batch.json to Algolia\'s server', function() {
// required api key

// --- Step 0: required Algolia api key

var personalApiKey = grunt.option('apikey');

if (!personalApiKey) {
grunt.log.write("Checking API key...").error();
grunt.log.write("Please provide a valid API key with option --apikey");
Expand All @@ -36,21 +39,38 @@ module.exports = function(grunt) {
// this task is async
var done = this.async();

// init Algolia API client

// --- Step 1: init Algolia API client

var init = grunt.log.write("Initialize Algolia's client...");

var Algolia = require('algolia-search');
var client = new Algolia('9JQV0RIHU0', personalApiKey);

init.ok();

// prepare index
init = grunt.log.write("Clearing index...");

// --- Step 2: prepare Algolia index

var prepare = grunt.log.write("Clearing index...");

client.deleteIndex('icons');

var index = client.initIndex('icons');
index.setSettings({ 'attributesToIndex' : ["name", "tags"], 'customRanking' : ["asc(name)"], 'queryType' : 'prefixAll' });
init.ok();

// push data
index.setSettings({
'attributesToIndex': ["name", "tags", "unicode"],
'customRanking': ["asc(name)"],
'queryType': 'prefixAll'
});

prepare.ok();


// --- Step 3: push data to Algolia

var push = grunt.log.write("Push batch.json...");

index.addObjects(require('./data/batch.json'), function(error, content) {
if (error) {
push.error();
Expand All @@ -60,5 +80,6 @@ module.exports = function(grunt) {
done();
}
});

});
};