aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Utils.ts2
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx2
-rw-r--r--src/fields/Document.ts15
-rw-r--r--src/server/Search.ts27
-rw-r--r--src/server/database.ts12
-rw-r--r--src/server/index.ts14
6 files changed, 60 insertions, 12 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 2e672db9a..e07d4e82d 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -48,7 +48,7 @@ export class Utils {
if (this.logFilter !== undefined && this.logFilter !== message.type) {
return;
}
- let idString = (message.id || message.id || "").padStart(36, ' ');
+ let idString = (message.id || "").padStart(36, ' ');
prefix = prefix.padEnd(16, ' ');
console.log(`${prefix}: ${idString}, ${receiving ? 'receiving' : 'sending'} ${messageName} with data ${JSON.stringify(message)}`);
}
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index d0b1e7f2c..d416c3619 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -38,7 +38,7 @@ export class CollectionFreeFormView extends CollectionSubView {
}
public addDocument = (newBox: Document, allowDuplicates: boolean) =>
- this.props.addDocument(this.bringToFront(newBox), false);
+ this.props.addDocument(this.bringToFront(newBox), false)
public selectDocuments = (docs: Document[]) => {
SelectionManager.DeselectAll;
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 7cf784f0e..62606ddba 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -28,15 +28,14 @@ export class Document extends Field {
}
static FromJson(data: any, id: string, save: boolean): Document {
let doc = new Document(id, save);
- let fields = data as [string, string][];
- fields.forEach(pair => doc._proxies.set(pair[0], pair[1]));
+ let fields = data as { key: string, field: string }[];
+ fields.forEach(pair => doc._proxies.set(pair.key, pair.field));
return doc;
}
- UpdateFromServer(data: [string, string][]) {
- for (const key in data) {
- const element = data[key];
- this._proxies.set(element[0], element[1]);
+ UpdateFromServer(data: { key: string, field: string }[]) {
+ for (const kv of data) {
+ this._proxies.set(kv.key, kv.field);
}
}
@@ -417,9 +416,9 @@ export class Document extends Field {
}
ToJson() {
- let fields: [string, string][] = [];
+ let fields: { key: string, field: string }[] = [];
this._proxies.forEach((field, key) =>
- field && fields.push([key, field]));
+ field && fields.push({ key, field }));
return {
type: Types.Document,
diff --git a/src/server/Search.ts b/src/server/Search.ts
new file mode 100644
index 000000000..f9babc433
--- /dev/null
+++ b/src/server/Search.ts
@@ -0,0 +1,27 @@
+import * as rp from 'request-promise';
+import { Database } from './database';
+
+export class Search {
+ public static Instance = new Search();
+ private url = 'http://localhost:8983/solr/';
+
+ public updateDocument(document: any): rp.RequestPromise {
+ return rp.post(this.url + "dash/update/json/docs", {
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify(document)
+ });
+ }
+
+ public async search(query: string) {
+ const searchResults = JSON.parse(await rp.get(this.url + "dash/select", {
+ qs: {
+ q: query
+ }
+ }));
+ const fields = searchResults.response.docs;
+ const ids = fields.map((field: any) => field.id);
+ const docs = await Database.Instance.searchQuery(ids);
+ const docIds = docs.map((doc: any) => doc._id);
+ return docIds;
+ }
+} \ No newline at end of file
diff --git a/src/server/database.ts b/src/server/database.ts
index 7914febf8..5c70da931 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -72,6 +72,18 @@ export class Database {
});
}
+ public searchQuery(ids: string[], collectionName = Database.DocumentsCollection): Promise<any> {
+ return new Promise<any>(resolve => {
+ this.db && this.db.collection(collectionName).find({ "data.field": { "$in": ids } }).toArray((err, docs) => {
+ if (err) {
+ console.log(err.message);
+ console.log(err.errmsg);
+ }
+ resolve(docs);
+ });
+ });
+ }
+
public print() {
console.log("db says hi!");
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 3cbe1ca76..bea84c6ed 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -22,7 +22,7 @@ import { getForgot, getLogin, getLogout, getReset, getSignup, postForgot, postLo
import { DashUserModel } from './authentication/models/user_model';
import { Client } from './Client';
import { Database } from './database';
-import { MessageStore, Transferable } from "./Message";
+import { MessageStore, Transferable, Types } from "./Message";
import { RouteStore } from './RouteStore';
const app = express();
const config = require('../../webpack.config');
@@ -32,10 +32,11 @@ const serverPort = 4321;
import expressFlash = require('express-flash');
import flash = require('connect-flash');
import c = require("crypto");
+import { Search } from './Search';
const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
-const download = (url: string, dest: fs.PathLike) => request.get(url).pipe(fs.createWriteStream(dest));;
+const download = (url: string, dest: fs.PathLike) => request.get(url).pipe(fs.createWriteStream(dest));
const mongoUrl = 'mongodb://localhost:27017/Dash';
mongoose.connect(mongoUrl);
@@ -120,6 +121,12 @@ app.get("/pull", (req, res) =>
// GETTERS
+app.get("/search", async (req, res) => {
+ let query = req.query.query || "hello";
+ let results = await Search.Instance.search(query);
+ res.send(results);
+});
+
// anyone attempting to navigate to localhost at this port will
// first have to login
addSecureRoute(
@@ -260,6 +267,9 @@ function getFields([ids, callback]: [string[], (result: Transferable[]) => void]
function setField(socket: Socket, newValue: Transferable) {
Database.Instance.update(newValue.id, newValue, () =>
socket.broadcast.emit(MessageStore.SetField.Message, newValue));
+ if (newValue.type === Types.Text) {
+ Search.Instance.updateDocument({ id: newValue.id, data: (newValue as any).data });
+ }
}
server.listen(serverPort);