aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Search.ts12
-rw-r--r--src/server/database.ts11
-rw-r--r--src/server/index.ts7
-rw-r--r--src/server/updateProtos.ts15
4 files changed, 33 insertions, 12 deletions
diff --git a/src/server/Search.ts b/src/server/Search.ts
index 69e327d2d..723dc101b 100644
--- a/src/server/Search.ts
+++ b/src/server/Search.ts
@@ -30,20 +30,14 @@ export class Search {
}
}
- public async search(query: string, filterQuery: string = "", start: number = 0, rows: number = 10) {
+ public async search(query: any) {
try {
const searchResults = JSON.parse(await rp.get(this.url + "dash/select", {
- qs: {
- q: query,
- fq: filterQuery,
- fl: "id",
- start,
- rows,
- }
+ qs: query
}));
const { docs, numFound } = searchResults.response;
const ids = docs.map((field: any) => field.id);
- return { ids, numFound };
+ return { ids, numFound, highlighting: searchResults.highlighting };
} catch {
return { ids: [], numFound: -1 };
}
diff --git a/src/server/database.ts b/src/server/database.ts
index 29a8ffafa..7f5331998 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -140,6 +140,17 @@ export class Database {
}
}
+ public updateMany(query: any, update: any, collectionName = "newDocuments") {
+ if (this.db) {
+ const db = this.db;
+ return new Promise<mongodb.WriteOpResult>(res => db.collection(collectionName).update(query, update, (_, result) => res(result)));
+ } else {
+ return new Promise<mongodb.WriteOpResult>(res => {
+ this.onConnect.push(() => this.updateMany(query, update, collectionName).then(res));
+ });
+ }
+ }
+
public print() {
console.log("db says hi!");
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 9c0ec13c4..d70f87bd9 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -144,12 +144,13 @@ app.get("/pull", (req, res) =>
// GETTERS
app.get("/search", async (req, res) => {
- const { query, filterQuery, start, rows } = req.query;
- if (query === undefined) {
+ const solrQuery: any = {};
+ ["q", "fq", "start", "rows", "hl", "hl.fl"].forEach(key => solrQuery[key] = req.query[key]);
+ if (solrQuery.q === undefined) {
res.send([]);
return;
}
- let results = await Search.Instance.search(query, filterQuery, start, rows);
+ let results = await Search.Instance.search(solrQuery);
res.send(results);
});
diff --git a/src/server/updateProtos.ts b/src/server/updateProtos.ts
new file mode 100644
index 000000000..90490eb45
--- /dev/null
+++ b/src/server/updateProtos.ts
@@ -0,0 +1,15 @@
+import { Database } from "./database";
+
+const protos =
+ ["text", "histogram", "image", "web", "collection", "kvp",
+ "video", "audio", "pdf", "icon", "import", "linkdoc"];
+
+(async function () {
+ await Promise.all(
+ protos.map(protoId => new Promise(res => Database.Instance.update(protoId, {
+ $set: { "fields.baseProto": true }
+ }, res)))
+ );
+
+ console.log("done");
+})(); \ No newline at end of file