SEARCH-154 - Changed the isInitialized method

This commit is contained in:
Keerthi Niranjan 2017-08-17 15:04:24 +05:30 committed by Keerthi Niranjan
parent 86dde3c71f
commit 9d97579e48
2 changed files with 21 additions and 22 deletions

View File

@ -132,8 +132,7 @@
buttonEl.addEventListener('click', function () {
if (!search.isLibInit()) {
alert('Library is not initiated. Init first...');
return;
search.init();
}
let out;
table.innerHTML = '';

View File

@ -59,21 +59,11 @@ class Search {
}
/**
* TO check whether SymphonySearchEngine library
* initialized or initialise it
* @returns {Promise}
* returns isInitialized boolean
* @returns {boolean}
*/
initLib() {
return new Promise((resolve) => {
if (!this.isInitialized) {
this.isInitialized = true;
}
resolve(libSymphonySearch.symSEInit());
});
}
isLibInit() {
return this.initLib();
return this.isInitialized;
}
/**
@ -103,12 +93,12 @@ class Search {
indexBatch(messages) {
return new Promise((resolve, reject) => {
if (!Array.isArray(messages)) {
reject('Messages should be an array');
reject(new Error('Messages should be an array'));
return;
}
if (!this.isInitialized) {
reject("Not initialized");
reject(new Error("Library not initialized"));
return;
}
@ -140,6 +130,11 @@ class Search {
if (!Array.isArray(message)) {
return new Error('Messages should be an array');
}
if (!this.isInitialized) {
return new Error("Library not initialized");
}
let result = libSymphonySearch.symSEIndexRealTime(this.realTimeIndex, JSON.stringify(message));
return result === 0 ? "Successful" : result
}
@ -191,20 +186,20 @@ class Search {
let _sortOrder = sortOrder;
return new Promise((resolve, reject) => {
if (!fs.existsSync(this.indexFolderName) && !fs.existsSync(this.realTimeIndex)) {
reject('Index folder does not exist.');
if (!this.isInitialized) {
reject(new Error("Library not initialized"));
return;
}
if (!this.isInitialized) {
reject("Not initialized");
if (!fs.existsSync(this.indexFolderName) || !fs.existsSync(this.realTimeIndex)) {
reject('Index folder does not exist.');
return;
}
let q = Search.constructQuery(query, senderIds, threadIds);
if (q === undefined) {
reject("Search query error");
reject(new Error("Search query error"));
return;
}
@ -251,6 +246,11 @@ class Search {
*/
getLatestMessageTimestamp() {
return new Promise((resolve, reject) => {
if (!this.isInitialized) {
reject("Not initialized");
return;
}
if (!fs.existsSync(this.indexFolderName)) {
reject('Index folder does not exist.');
return;