mirror of
https://github.com/wassname/talk.git
synced 2026-07-25 13:30:59 +08:00
[CORL-325] Comment Search API (#2578)
* feat: added comment search support * fix: updated readme * Update README.md
This commit is contained in:
@@ -40,7 +40,7 @@ Preview Coral easily by running Coral via a Heroku App:
|
||||
|
||||
## Requirements
|
||||
|
||||
- MongoDB >=3.6
|
||||
- MongoDB >=4.2
|
||||
- Redis >=3.2
|
||||
- NodeJS >=10
|
||||
- NPM >=6.7
|
||||
@@ -84,7 +84,7 @@ services:
|
||||
- REDIS_URI=redis://redis:6379
|
||||
- SIGNING_SECRET=<replace me with something secret>
|
||||
mongo:
|
||||
image: mongo:3.6
|
||||
image: mongo:4.2
|
||||
volumes:
|
||||
- ./data/mongo:/data/db
|
||||
redis:
|
||||
@@ -121,7 +121,7 @@ This should output all the compiled application code to `./dist`.
|
||||
|
||||
Running Coral with default settings assumes that you have:
|
||||
|
||||
- MongoDB >=3.6 running on `127.0.0.1:27017`
|
||||
- MongoDB >=4.2 running on `127.0.0.1:27017`
|
||||
- Redis >=3.2 running on `127.0.0.1:6379`
|
||||
|
||||
If you don't already have these databases running, you can execute the following
|
||||
@@ -310,14 +310,14 @@ npm install
|
||||
|
||||
Running Coral with default settings assumes that you have:
|
||||
|
||||
- MongoDB >=3.6 running on `127.0.0.1:27017`
|
||||
- MongoDB >=4.2 running on `127.0.0.1:27017`
|
||||
- Redis >=3.2 running on `127.0.0.1:6379`
|
||||
|
||||
If you don't already have these databases running, you can execute the following
|
||||
assuming you have Docker installed on your local machine:
|
||||
|
||||
```bash
|
||||
docker run -d -p 27017:27017 --restart always --name mongo mongo:3.6
|
||||
docker run -d -p 27017:27017 --restart always --name mongo mongo:4.2
|
||||
docker run -d -p 6379:6379 --restart always --name redis redis:3.2
|
||||
```
|
||||
|
||||
|
||||
@@ -48,6 +48,14 @@ const tagFilter = (tag?: GQLTAG): CommentConnectionInput["filter"] => {
|
||||
return {};
|
||||
};
|
||||
|
||||
const queryFilter = (query?: string): CommentConnectionInput["filter"] => {
|
||||
if (query) {
|
||||
return { $text: { $search: `"${query}"` } };
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
/**
|
||||
* primeCommentsFromConnection will prime a given context with the comments
|
||||
* retrieved via a connection.
|
||||
@@ -123,6 +131,7 @@ export default (ctx: Context) => ({
|
||||
storyID,
|
||||
status,
|
||||
tag,
|
||||
query,
|
||||
}: QueryToCommentsArgs) =>
|
||||
retrieveCommentConnection(ctx.mongo, ctx.tenant.id, {
|
||||
first,
|
||||
@@ -130,6 +139,7 @@ export default (ctx: Context) => ({
|
||||
orderBy: GQLCOMMENT_SORT.CREATED_AT_DESC,
|
||||
filter: omitBy(
|
||||
{
|
||||
...queryFilter(query),
|
||||
...tagFilter(tag),
|
||||
storyID,
|
||||
status,
|
||||
|
||||
@@ -2523,6 +2523,7 @@ type Query {
|
||||
storyID: ID
|
||||
status: COMMENT_STATUS
|
||||
tag: TAG
|
||||
query: String
|
||||
): CommentsConnection! @auth(roles: [ADMIN, MODERATOR])
|
||||
|
||||
"""
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Db } from "mongodb";
|
||||
|
||||
import Migration from "coral-server/services/migrate/migration";
|
||||
import collections from "coral-server/services/mongodb/collections";
|
||||
|
||||
import { createConnectionOrderVariants, createIndexFactory } from "../indexing";
|
||||
|
||||
export default class extends Migration {
|
||||
public async indexes(mongo: Db) {
|
||||
const createIndex = createIndexFactory(collections.comments(mongo));
|
||||
|
||||
// Text searches.
|
||||
await createIndex(
|
||||
{
|
||||
tenantID: 1,
|
||||
"revisions.body": "text",
|
||||
},
|
||||
{ background: true }
|
||||
);
|
||||
|
||||
const variants = createConnectionOrderVariants(createIndex, [
|
||||
{ createdAt: -1 },
|
||||
{ createdAt: 1 },
|
||||
{ childCount: -1, createdAt: -1 },
|
||||
{ "actionCounts.REACTION": -1, createdAt: -1 },
|
||||
]);
|
||||
|
||||
// Story based Comment Connection pagination.
|
||||
// { storyID, ...connectionParams }
|
||||
await variants({
|
||||
tenantID: 1,
|
||||
storyID: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user