Fixed some bugs related to build

This commit is contained in:
Keerthi Niranjan 2017-07-27 20:20:26 +05:30 committed by Keerthi Niranjan
parent c76397f601
commit 8a61b86a3d
4 changed files with 48 additions and 20 deletions

View File

@ -34,7 +34,7 @@
</head>
<body>
<div style="padding: 20px;">
<h1>Symphony Electron API Demo</h1>
<h1>Symphony Electron Search API Demo</h1>
<div>
<p>Search</p>
</div>
@ -67,9 +67,14 @@
<div>
<label for="var1">var1:</label><input id="var1" value="0" size=5>
</div>
<div>
<label for="realTimeIndexing">Real Time Indexing:</label><input placeholder="Pass array of messages:" id="realTimeIndexing">
<button id='sendMessage'>Send</button>
</div>
<br>
<div>
<button id='index'>IndexMessages</button>
<label for="batchNumber">Batch Number: </label><input placeholder="Ex: batch1, batch2" id="batchNumber">
<button id='index'>Index Messages</button>
<button id='merge'>Merge</button>
</div>
<br>
@ -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();
})

View File

@ -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);
}
});
}

View File

@ -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 = {

View File

@ -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": {