Created
March 26, 2019 06:14
-
-
Save djravine/26918dd9ee6ae8aeb1c8f168ef2ae789 to your computer and use it in GitHub Desktop.
Algolite Test Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# npm i algoliasearch | |
var algoliasearch = require('algoliasearch'); | |
var connectJSON = { | |
timeout: 4000, | |
protocol: 'http:', | |
hosts: { | |
read: ['localhost:9201'], | |
write: ['localhost:9201'] | |
} | |
}; | |
var contentJSON = { | |
title: 'Algolia 2019 Test', | |
contentType: 'events' | |
}; | |
var client = algoliasearch('app-id', 'api-key', connectJSON); | |
var index = client.initIndex('test'); | |
index.addObject(contentJSON, function (err, content) { | |
if (err) console.error(err); | |
// console.log(content); | |
objectID = content.objectID.toString(); | |
// Add 2nd Object | |
index.addObject(contentJSON, function (err, content) { | |
if (err) console.error(err); | |
}); | |
setTimeout(function () { | |
console.log("LOG: Add 2 Objects..."); | |
index.search('Algolia', function (err, content) { | |
// console.log(content); | |
console.log(content.hits); | |
}); | |
}, 500); | |
setTimeout(function () { | |
index.deleteObject(objectID, function (err, content) { | |
if (err) console.error(err); | |
}); | |
}, 700); | |
setTimeout(function () { | |
console.log("LOG: Delete 1 Object..."); | |
index.search('Algolia', function (err, content) { | |
// console.log(content); | |
console.log(content.hits); | |
}); | |
}, 900); | |
setTimeout(function () { | |
index.clearIndex(function (err, content) { | |
if (err) console.error(err); | |
console.log(content); | |
}); | |
}, 1100); | |
setTimeout(function () { | |
console.log("LOG: Clear all Objects..."); | |
index.search('Algolia', function (err, content) { | |
// console.log(content); | |
console.log(content.hits); | |
}); | |
}, 1300); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
..