From 8a61b86a3d6d5a13de21e4f1792998883f9e4f00 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Thu, 27 Jul 2017 20:20:26 +0530 Subject: [PATCH] Fixed some bugs related to build --- demo/search.html | 20 +++++++++++++++++--- js/search/search.js | 33 +++++++++++++++++++-------------- js/search/searchLibrary.js | 9 +++++++-- package.json | 6 +++++- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/demo/search.html b/demo/search.html index 809f9d6e..0680d2b5 100644 --- a/demo/search.html +++ b/demo/search.html @@ -34,7 +34,7 @@
-

Symphony Electron API Demo

+

Symphony Electron Search API Demo

Search

@@ -67,9 +67,14 @@
+
+ + +

- + +

@@ -102,10 +107,14 @@ var threadIdEl = document.getElementById('threadId'); var var1El = document.getElementById('var1'); var table = document.getElementById('table'); + var sendMessage = document.getElementById('sendMessage'); + var realTimeIndexing = document.getElementById('realTimeIndexing'); + var batchNumber = document.getElementById('batchNumber'); buttonIndex.addEventListener('click', function () { - search.readJson().then(function (res) { + let batchIndex = batchNumber.value; + search.readJson(batchIndex).then(function (res) { search.indexBatch(res).then(function () { resultsEl.innerHTML = "Index created"; }); @@ -151,6 +160,11 @@ }); }); + sendMessage.addEventListener('click', function () { + let message = JSON.parse(realTimeIndexing.value); + search.realTimeIndexing(message); + }); + merge.addEventListener('click', function () { search.mergeIndexBatches(); }) diff --git a/js/search/search.js b/js/search/search.js index f68a58d6..b20841d4 100644 --- a/js/search/search.js +++ b/js/search/search.js @@ -3,18 +3,20 @@ const fs = require('fs'); const randomString = require('randomstring'); - const electron = require('electron'); const app = electron.app; const path = require('path'); const isDevEnv = require('../utils/misc.js').isDevEnv; const isMac = require('../utils/misc.js').isMac; +let userData = path.join(app.getPath('userData')); +let execPath = path.dirname(app.getPath('exe')); + const libSymphonySearch = require('./searchLibrary'); -const TEMP_BATCH_INDEX_FOLDER = './data/temp_batch_indexes'; -const TEMP_REALTIME_INDEX = './data/temp_realtime_index'; -const INDEX_PREFIX = './data/search_index'; -const INDEX_DATA_FOLDER = './data'; +const TEMP_BATCH_INDEX_FOLDER = path.join(userData, '/data/temp_batch_indexes'); +const TEMP_REALTIME_INDEX = path.join(userData, '/data/temp_realtime_index'); +const INDEX_PREFIX = path.join(userData, '/data/search_index'); +const INDEX_DATA_FOLDER = path.join(userData, '/data'); const SEARCH_PERIOD_SUBTRACTOR = 3 * 31 * 24 * 60 * 60 * 1000;//3 months const MINIMUM_DATE = '0000000000000'; const MAXIMUM_DATE = '9999999999999'; @@ -24,9 +26,8 @@ const SORT_BY_SCORE = 0; const BATCH_RANDOM_INDEX_PATH_LENGTH = 20; -let execPath = path.dirname(app.getPath('exe')); - class Search { + /*eslint-disable class-methods-use-this */ constructor(userId) { this.isInitialized = false; @@ -71,7 +72,7 @@ class Search { let indexId = randomString.generate(BATCH_RANDOM_INDEX_PATH_LENGTH); libSymphonySearch.symSECreatePartialIndexAsync(TEMP_BATCH_INDEX_FOLDER, indexId, JSON.stringify(messages), function (err, res) { if (err) reject(err); - resolve(res) + resolve(res); }); }); } @@ -84,15 +85,19 @@ class Search { }); } - /*eslint-disable class-methods-use-this */ - readJson() { + realTimeIndexing(message) { + libSymphonySearch.symSEIndexRealTime(TEMP_REALTIME_INDEX, JSON.stringify(message)); + } + + readJson(batch) { return new Promise((resolve, reject) => { - let dirPath = path.join(execPath, isMac ? '..' : '', 'Resources/msgsjson'); - let messageFolderPath = isDevEnv ? './msgsjson/' : dirPath; + let dirPath = path.join(execPath, isMac ? '..' : '', 'Resources/msgsjson', batch); + let messageFolderPath = isDevEnv ? path.join('./msgsjson', batch ): dirPath; let files = fs.readdirSync(messageFolderPath); let messageData = []; files.forEach(function (file) { - let data = fs.readFileSync(messageFolderPath + file, "utf8"); + let tempPath = path.join(messageFolderPath, file); + let data = fs.readFileSync(tempPath, "utf8"); if (data) { messageData.push(JSON.parse(data)); resolve(messageData); @@ -145,7 +150,7 @@ class Search { let ret = JSON.parse(returnedResult); resolve(ret); if (ret.messages.length > 0) { - libSymphonySearch.symSEFreeResultAsync(returnedResult); + libSymphonySearch.symSEFreeResult(returnedResult); } }); } diff --git a/js/search/searchLibrary.js b/js/search/searchLibrary.js index b15876a4..a6a24869 100644 --- a/js/search/searchLibrary.js +++ b/js/search/searchLibrary.js @@ -11,8 +11,13 @@ const isMac = require('../utils/misc.js').isMac; var symLucyIndexer = ref.types.void; var symLucyIndexerPtr = ref.refType(symLucyIndexer); + + +let messageData = ref.types.void; +let messagePtr = ref.refType(messageData); + let execPath = path.dirname(app.getPath('exe')); -let libraryPath = isMac ? 'Resources/libsymphonysearch' : 'Resources/libsymphonysearchwin64'; +let libraryPath = isMac ? 'Resources/libsymphonysearch' : 'resources/libsymphonysearchwin64'; let fullPath = path.join(execPath, isMac ? '..' : '', libraryPath); let libPath = isDevEnv ? 'libsymphonysearch.dylib' : fullPath; @@ -37,7 +42,7 @@ var libSymphonySearch = ffi.Library(libPath, { //Index commit/optimize 'symSE_commit_index': ['int', [symLucyIndexerPtr, 'int']], //will be removed //freePointer - 'symSE_free_results': ['int', ['string']] + 'symSE_free_results': ['int', [messagePtr]] }); module.exports = { diff --git a/package.json b/package.json index a7553130..81ea29cc 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,11 @@ "!installer/*", "!tests/*" ], - "extraResources": ["msgsjson", "libsymphonysearch.dylib", "libsymphonysearchwin64.dll"], + "extraResources": [ + "msgsjson", + "libsymphonysearch.dylib", + "libsymphonysearchwin64.dll" + ], "extraFiles": "config/Symphony.config", "appId": "symphony-electron-desktop", "mac": {