aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts1
-rw-r--r--src/server/Search.ts28
-rw-r--r--src/server/index.ts55
3 files changed, 46 insertions, 38 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index a770ccc93..00233a989 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -175,6 +175,7 @@ export namespace Docs {
if (!("creationDate" in protoProps)) {
protoProps.creationDate = new DateField;
}
+ protoProps.isPrototype = true;
return SetDelegateOptions(SetInstanceOptions(proto, protoProps, data), delegateProps);
}
diff --git a/src/server/Search.ts b/src/server/Search.ts
index 6e7883bc9..59bdd4803 100644
--- a/src/server/Search.ts
+++ b/src/server/Search.ts
@@ -5,34 +5,8 @@ import { thisExpression } from 'babel-types';
export class Search {
public static Instance = new Search();
private url = 'http://localhost:8983/solr/';
- private client: any;
-
- constructor() {
- console.log("Search Instantiated!");
- var SolrNode = require('solr-node');
- this.client = new SolrNode({
- host: 'localhost',
- port: '8983',
- core: 'dash',
- protocol: 'http'
- });
- var strQuery = this.client.query().q('text:test');
-
- console.log(strQuery);
-
- // Search documents using strQuery
- // client.search(strQuery, (err: any, result: any) => {
- // if (err) {
- // console.log(err);
- // return;
- // }
- // console.log('Response:', result.response);
- // });
- }
-
public async updateDocument(document: any) {
- console.log("UPDATE: ", JSON.stringify(document));
return rp.post(this.url + "dash/update", {
headers: { 'content-type': 'application/json' },
body: JSON.stringify([document])
@@ -40,8 +14,6 @@ export class Search {
}
public async search(query: string) {
- console.log("____________________________");
- console.log(query);
const searchResults = JSON.parse(await rp.get(this.url + "dash/select", {
qs: {
q: query
diff --git a/src/server/index.ts b/src/server/index.ts
index 6b92e8e8e..93e4cafbf 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -128,7 +128,6 @@ app.get("/pull", (req, res) =>
app.get("/search", async (req, res) => {
let query = req.query.query || "hello";
let results = await Search.Instance.search(query);
- console.log(results);
res.send(results);
});
@@ -296,10 +295,48 @@ function GetRefFields([ids, callback]: [string[], (result?: Transferable[]) => v
}
-const suffixMap: { [type: string]: string } = {
+const suffixMap: { [type: string]: (string | [string, string | ((json: any) => any)]) } = {
"number": "_n",
- "string": "_t"
+ "string": "_t",
+ "image": ["_t", "url"],
+ "video": ["_t", "url"],
+ "pdf": ["_t", "url"],
+ "audio": ["_t", "url"],
+ "web": ["_t", "url"],
+ "date": ["_d", value => new Date(value.date).toISOString()],
+ "proxy": ["_i", "fieldId"],
+ "list": ["_l", list => {
+ const results = [];
+ for (const value of list.fields) {
+ const term = ToSearchTerm(value);
+ if (term) {
+ results.push(term.value);
+ }
+ }
+ return results.length ? results : null;
+ }]
};
+
+function ToSearchTerm(val: any): { suffix: string, value: any } | undefined {
+ const type = val.__type || typeof val;
+ let suffix = suffixMap[type];
+ if (!suffix) {
+ return;
+ }
+
+ if (Array.isArray(suffix)) {
+ const accessor = suffix[1];
+ if (typeof accessor === "function") {
+ val = accessor(val);
+ } else {
+ val = val[accessor];
+ }
+ suffix = suffix[0];
+ }
+
+ return { suffix, value: val }
+}
+
function UpdateField(socket: Socket, diff: Diff) {
Database.Instance.update(diff.id, diff.diff,
() => socket.broadcast.emit(MessageStore.UpdateField.Message, diff), false, "newDocuments");
@@ -308,28 +345,26 @@ function UpdateField(socket: Socket, diff: Diff) {
return;
}
const update: any = { id: diff.id };
- console.log("FIELD: ", docfield);
let dynfield = false;
for (let key in docfield) {
if (!key.startsWith("fields.")) continue;
- const val = docfield[key];
- const suffix = suffixMap[typeof val];
- if (suffix !== undefined) {
+ let val = docfield[key];
+ let term = ToSearchTerm(val);
+ if (term !== undefined) {
+ let { suffix, value } = term;
key = key.substring(7);
Object.values(suffixMap).forEach(suf => update[key + suf] = null);
- update[key + suffix] = { set: val };
+ update[key + suffix] = { set: value };
dynfield = true;
}
}
if (dynfield) {
- console.log("dynamic field detected!");
Search.Instance.updateDocument(update);
}
}
function CreateField(newValue: any) {
Database.Instance.insert(newValue, "newDocuments");
- console.log("created field");
}
server.listen(serverPort);