summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:48:29 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:48:29 +0900
commit7495206db29e0f347c4317389e77410cbb19bc83 (patch)
treeefb93e8bc11eabbe87b15a62981a5d0c23c9ce17 /src/server/api
parentMerge branch 'develop' (diff)
parent11.4.0 (diff)
downloadmisskey-7495206db29e0f347c4317389e77410cbb19bc83.tar.gz
misskey-7495206db29e0f347c4317389e77410cbb19bc83.tar.bz2
misskey-7495206db29e0f347c4317389e77410cbb19bc83.zip
Merge branch 'develop'
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/endpoints/ap/show.ts28
-rw-r--r--src/server/api/endpoints/notes/search.ts64
2 files changed, 75 insertions, 17 deletions
diff --git a/src/server/api/endpoints/ap/show.ts b/src/server/api/endpoints/ap/show.ts
index 1bb15117dd..9724a044b1 100644
--- a/src/server/api/endpoints/ap/show.ts
+++ b/src/server/api/endpoints/ap/show.ts
@@ -101,6 +101,32 @@ async function fetchAny(uri: string) {
// /@user のような正規id以外で取得できるURIが指定されていた場合、ここで初めて正規URIが確定する
// これはDBに存在する可能性があるため再度DB検索
if (uri !== object.id) {
+ if (object.id.startsWith(config.url + '/')) {
+ const parts = object.id.split('/');
+ const id = parts.pop();
+ const type = parts.pop();
+
+ if (type === 'notes') {
+ const note = await Notes.findOne(id);
+
+ if (note) {
+ return {
+ type: 'Note',
+ object: await Notes.pack(note, null, { detail: true })
+ };
+ }
+ } else if (type === 'users') {
+ const user = await Users.findOne(id);
+
+ if (user) {
+ return {
+ type: 'User',
+ object: await Users.pack(user, null, { detail: true })
+ };
+ }
+ }
+ }
+
const [user, note] = await Promise.all([
Users.findOne({ uri: object.id }),
Notes.findOne({ uri: object.id })
@@ -120,7 +146,7 @@ async function fetchAny(uri: string) {
}
if (['Note', 'Question', 'Article'].includes(object.type)) {
- const note = await createNote(object.id);
+ const note = await createNote(object.id, undefined, true);
return {
type: 'Note',
object: await Notes.pack(note!, null, { detail: true })
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 [];