summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:46:39 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:46:39 +0900
commit0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d (patch)
tree38d3d6b2112326bb1a03a8732cd8969e24d693de /src/server/api/endpoints/notes
parentFix #4793 (diff)
downloadsharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.gz
sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.bz2
sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.zip
Resolve #3119
Diffstat (limited to 'src/server/api/endpoints/notes')
-rw-r--r--src/server/api/endpoints/notes/search.ts64
1 files changed, 48 insertions, 16 deletions
diff --git a/src/server/api/endpoints/notes/search.ts b/src/server/api/endpoints/notes/search.ts
index daf992b639..65ce20074a 100644
--- a/src/server/api/endpoints/notes/search.ts
+++ b/src/server/api/endpoints/notes/search.ts
@@ -5,6 +5,7 @@ import { ApiError } from '../../error';
import { Notes } from '../../../../models';
import { In } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
+import { ID } from '../../../../misc/cafy-id';
export const meta = {
desc: {
@@ -29,7 +30,17 @@ export const meta = {
offset: {
validator: $.optional.num.min(0),
default: 0
- }
+ },
+
+ host: {
+ validator: $.optional.nullable.str,
+ default: undefined
+ },
+
+ userId: {
+ validator: $.optional.nullable.type(ID),
+ default: null
+ },
},
res: {
@@ -54,30 +65,51 @@ export const meta = {
export default define(meta, async (ps, me) => {
if (es == null) throw new ApiError(meta.errors.searchingNotAvailable);
- const response = await es.search({
- index: 'misskey',
- type: 'note',
+ const userQuery = ps.userId != null ? [{
+ term: {
+ userId: ps.userId
+ }
+ }] : [];
+
+ const hostQuery = ps.userId == null ?
+ ps.host === null ? [{
+ bool: {
+ must_not: {
+ exists: {
+ field: 'userHost'
+ }
+ }
+ }
+ }] : ps.host !== undefined ? [{
+ term: {
+ userHost: ps.host
+ }
+ }] : []
+ : [];
+
+ const result = await es.search({
+ index: 'misskey_note',
body: {
size: ps.limit!,
from: ps.offset,
query: {
- simple_query_string: {
- fields: ['text'],
- query: ps.query,
- default_operator: 'and'
+ bool: {
+ must: [{
+ simple_query_string: {
+ fields: ['text'],
+ query: ps.query.toLowerCase(),
+ default_operator: 'and'
+ },
+ }, ...hostQuery, ...userQuery]
}
},
- sort: [
- { _doc: 'desc' }
- ]
+ sort: [{
+ _doc: 'desc'
+ }]
}
});
- if (response.hits.total === 0) {
- return [];
- }
-
- const hits = response.hits.hits.map((hit: any) => hit.id);
+ const hits = result.body.hits.hits.map((hit: any) => hit._id);
if (hits.length === 0) return [];