mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
SEARCH-154 - changed code documentation
This commit is contained in:
committed by
Keerthi Niranjan
parent
9d97579e48
commit
a5ecb2b4d4
@@ -87,24 +87,26 @@ class Search {
|
|||||||
/**
|
/**
|
||||||
* An array of messages is passed for indexing
|
* An array of messages is passed for indexing
|
||||||
* it will be indexed in a temporary index folder
|
* it will be indexed in a temporary index folder
|
||||||
* @param messages
|
* @param {Array} messages
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
indexBatch(messages) {
|
indexBatch(messages) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!Array.isArray(messages)) {
|
if (!Array.isArray(messages)) {
|
||||||
reject(new Error('Messages should be an array'));
|
reject(new Error('Messages must be an array'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
reject(new Error("Library not initialized"));
|
reject(new Error('Library not initialized'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let indexId = randomString.generate(BATCH_RANDOM_INDEX_PATH_LENGTH);
|
const indexId = randomString.generate(BATCH_RANDOM_INDEX_PATH_LENGTH);
|
||||||
libSymphonySearch.symSECreatePartialIndexAsync(this.batchIndex, indexId, JSON.stringify(messages), (err, res) => {
|
libSymphonySearch.symSECreatePartialIndexAsync(this.batchIndex, indexId, JSON.stringify(messages), (err, res) => {
|
||||||
if (err) reject(err);
|
if (err) {
|
||||||
|
reject(new Error(err));
|
||||||
|
}
|
||||||
resolve(res);
|
resolve(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -116,7 +118,9 @@ class Search {
|
|||||||
*/
|
*/
|
||||||
mergeIndexBatches() {
|
mergeIndexBatches() {
|
||||||
libSymphonySearch.symSEMergePartialIndexAsync(this.indexFolderName, this.batchIndex, (err) => {
|
libSymphonySearch.symSEMergePartialIndexAsync(this.indexFolderName, this.batchIndex, (err) => {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
libSymphonySearch.symSERemoveFolder(this.batchIndex)
|
libSymphonySearch.symSERemoveFolder(this.batchIndex)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -132,7 +136,7 @@ class Search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
return new Error("Library not initialized");
|
return new Error('Library not initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = libSymphonySearch.symSEIndexRealTime(this.realTimeIndex, JSON.stringify(message));
|
let result = libSymphonySearch.symSEIndexRealTime(this.realTimeIndex, JSON.stringify(message));
|
||||||
@@ -142,7 +146,7 @@ class Search {
|
|||||||
/**
|
/**
|
||||||
* Reading a json file
|
* Reading a json file
|
||||||
* for the demo search app only
|
* for the demo search app only
|
||||||
* @param batch
|
* @param {String} batch
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
readJson(batch) {
|
readJson(batch) {
|
||||||
@@ -155,27 +159,31 @@ class Search {
|
|||||||
let tempPath = path.join(messageFolderPath, file);
|
let tempPath = path.join(messageFolderPath, file);
|
||||||
let data = fs.readFileSync(tempPath, "utf8");
|
let data = fs.readFileSync(tempPath, "utf8");
|
||||||
if (data) {
|
if (data) {
|
||||||
this.messageData.push(JSON.parse(data));
|
try {
|
||||||
resolve(this.messageData);
|
this.messageData.push(JSON.parse(data));
|
||||||
|
} catch (err) {
|
||||||
|
reject(new Error(err))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reject("err on reading files")
|
reject(new Error('Error reading batch'))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
resolve(this.messageData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This returns the search results
|
* This returns the search results
|
||||||
* which returns a char *
|
* which returns a char *
|
||||||
* @param query
|
* @param {String} query
|
||||||
* @param senderIds
|
* @param {Array} senderIds
|
||||||
* @param threadIds
|
* @param {Array} threadIds
|
||||||
* @param attachments
|
* @param {String} attachments
|
||||||
* @param startDate
|
* @param {String} startDate
|
||||||
* @param endDate
|
* @param {String} endDate
|
||||||
* @param limit
|
* @param {Number} limit
|
||||||
* @param offset
|
* @param {Number} offset
|
||||||
* @param sortOrder
|
* @param {Number} sortOrder
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
searchQuery(query, senderIds, threadIds, attachments, startDate,
|
searchQuery(query, senderIds, threadIds, attachments, startDate,
|
||||||
@@ -187,7 +195,7 @@ class Search {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
reject(new Error("Library not initialized"));
|
reject(new Error('Library not initialized'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +207,7 @@ class Search {
|
|||||||
let q = Search.constructQuery(query, senderIds, threadIds);
|
let q = Search.constructQuery(query, senderIds, threadIds);
|
||||||
|
|
||||||
if (q === undefined) {
|
if (q === undefined) {
|
||||||
reject(new Error("Search query error"));
|
reject(new Error('Search query error'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +255,7 @@ class Search {
|
|||||||
getLatestMessageTimestamp() {
|
getLatestMessageTimestamp() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
reject("Not initialized");
|
reject('Not initialized');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,16 +275,16 @@ class Search {
|
|||||||
} finally {
|
} finally {
|
||||||
libSymphonySearch.symSEFreeResult(returnedResult);
|
libSymphonySearch.symSEFreeResult(returnedResult);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This the query constructor
|
* This the query constructor
|
||||||
* for the search function
|
* for the search function
|
||||||
* @param searchQuery
|
* @param {String} searchQuery
|
||||||
* @param senderId
|
* @param {Array} senderId
|
||||||
* @param threadId
|
* @param {Array} threadId
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static constructQuery(searchQuery, senderId, threadId) {
|
static constructQuery(searchQuery, senderId, threadId) {
|
||||||
@@ -311,11 +319,10 @@ class Search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* appending the senderId
|
* appending the senderId and threadId for the query
|
||||||
* and threadId for the query
|
* @param {String} query
|
||||||
* @param query
|
* @param {String} fieldName
|
||||||
* @param fieldName
|
* @param {Array} valueArray
|
||||||
* @param valueArray
|
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static appendFilterQuery(query, fieldName, valueArray) {
|
static appendFilterQuery(query, fieldName, valueArray) {
|
||||||
@@ -338,13 +345,13 @@ class Search {
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
//hashtags can have any characters(before the latest release it was
|
// hashtags can have any characters(before the latest release it was
|
||||||
//not like this). So the only regex is splitting the search query based on
|
// not like this). So the only regex is splitting the search query based on
|
||||||
//whitespaces
|
// whitespaces
|
||||||
/**
|
/**
|
||||||
* return the hash cash
|
* return the hash cash
|
||||||
* tags from the query
|
* tags from the query
|
||||||
* @param query
|
* @param {String} query
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
static getHashTags(query) {
|
static getHashTags(query) {
|
||||||
@@ -363,7 +370,7 @@ class Search {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the index folder exist or not
|
* Validate the index folder exist or not
|
||||||
* @param file
|
* @param {String} file
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
static indexValidator(file) {
|
static indexValidator(file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user