Resolve #3119
This commit is contained in:
parent
772258b0b8
commit
0db54386cd
14 changed files with 147 additions and 90 deletions
|
@ -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 [];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue