@@ -15,13 +15,13 @@ import { MiUser } from '@/models/_.js';
15
15
import type { NotesRepository , UsersRepository , PollVotesRepository , PollsRepository , NoteReactionsRepository , ClipNotesRepository , NoteFavoritesRepository } from '@/models/_.js' ;
16
16
import { sqlLikeEscape } from '@/misc/sql-like-escape.js' ;
17
17
import { CacheService } from '@/core/CacheService.js' ;
18
+ import { DriveService } from '@/core/DriveService.js' ;
18
19
import { QueryService } from '@/core/QueryService.js' ;
19
20
import { IdService } from '@/core/IdService.js' ;
20
21
import { LoggerService } from '@/core/LoggerService.js' ;
21
22
import { isQuote , isRenote } from '@/misc/is-renote.js' ;
22
23
import { IdentifiableError } from '@/misc/identifiable-error.js' ;
23
24
import type Logger from '@/logger.js' ;
24
- import { DriveService } from './DriveService.js' ;
25
25
26
26
type OpenSearchHit = {
27
27
_index : string
@@ -452,10 +452,10 @@ export class AdvancedSearchService {
452
452
script : {
453
453
lang : 'painless' ,
454
454
source : 'if (ctx._source.containsKey("reactions")) {' +
455
- 'if (ctx._source.reactions.stream().anyMatch(r -> r.emoji == params.emoji))' +
456
- ' { ctx._source.reactions.stream().filter(r -> r.emoji == params.emoji && r.count < 32700).forEach(r -> r.count += 1); }' +
457
- ' else { ctx._source.reactions.add(params.record); }' +
458
- '} else { ctx._source.reactions = new ArrayList(); ctx._source.reactions.add(params.record);}' ,
455
+ 'if (ctx._source.reactions.stream().anyMatch(r -> r.emoji == params.emoji))' +
456
+ ' { ctx._source.reactions.stream().filter(r -> r.emoji == params.emoji && r.count < 32700).forEach(r -> r.count += 1); }' +
457
+ ' else { ctx._source.reactions.add(params.record); }' +
458
+ '} else { ctx._source.reactions = new ArrayList(); ctx._source.reactions.add(params.record);}' ,
459
459
params : {
460
460
emoji : opts . reaction ,
461
461
record : {
@@ -506,7 +506,7 @@ export class AdvancedSearchService {
506
506
await this . opensearch . indices . create ( {
507
507
index : this . opensearchNoteIndex as string ,
508
508
body : noteIndexBody ,
509
- } ,
509
+ } ,
510
510
) . catch ( ( error ) => {
511
511
this . logger . error ( error ) ;
512
512
throw error ;
@@ -754,13 +754,13 @@ export class AdvancedSearchService {
754
754
script : {
755
755
lang : 'painless' ,
756
756
source : 'if (ctx._source.containsKey("reactions")) {' +
757
- 'for (int i = 0; i < ctx._source.reactions.length; i++) {' +
758
- ' if (ctx._source.reactions[i].emoji == params.emoji) { ctx._source.reactions[i].count -= 1;' +
759
- //DBに格納されるノートのリアクションデータは数が0でも保持されるのでそれに合わせてデータを消さない
760
- //' if (ctx._source.reactions[i].count <= 0) { ctx._source.reactions.remove(i) }' +
761
- 'break; }' +
762
- '}' +
763
- '}' ,
757
+ 'for (int i = 0; i < ctx._source.reactions.length; i++) {' +
758
+ ' if (ctx._source.reactions[i].emoji == params.emoji) { ctx._source.reactions[i].count -= 1;' +
759
+ //DBに格納されるノートのリアクションデータは数が0でも保持されるのでそれに合わせてデータを消さない
760
+ //' if (ctx._source.reactions[i].count <= 0) { ctx._source.reactions.remove(i) }' +
761
+ 'break; }' +
762
+ '}' +
763
+ '}' ,
764
764
params : {
765
765
emoji : emoji ,
766
766
} ,
@@ -813,10 +813,10 @@ export class AdvancedSearchService {
813
813
}
814
814
815
815
/**
816
- * user削除時に使う
817
- * お気に入りとクリップの削除
818
- * ノートは個別で削除されるからそこで
819
- */
816
+ * user削除時に使う
817
+ * お気に入りとクリップの削除
818
+ * ノートは個別で削除されるからそこで
819
+ */
820
820
@bindThis
821
821
public async unindexUserFavorites ( id : string ) {
822
822
this . unindexByQuery ( this . favoriteIndex ,
@@ -829,6 +829,33 @@ export class AdvancedSearchService {
829
829
} ) ;
830
830
}
831
831
832
+ @bindThis
833
+ public async searchOrFail ( me : MiUser | null , opts : {
834
+ reactions ?: string [ ] | null ;
835
+ reactionsExclude ?: string [ ] | null ;
836
+ userId ?: MiNote [ 'userId' ] | null ;
837
+ host ?: string | null ;
838
+ origin ?: string | null ;
839
+ fileOption ?: string | null ;
840
+ visibility ?: MiNote [ 'visibility' ] | null ;
841
+ excludeCW ?: boolean ;
842
+ excludeReply ?: boolean ;
843
+ excludeQuote ?: boolean ;
844
+ sensitiveFilter ?: string | null ;
845
+ followingFilter ?: string | null ;
846
+ offset ?: number | null ;
847
+ useStrictSearch ?: boolean | null ;
848
+ wildCard ?: boolean ;
849
+ } , pagination : {
850
+ untilId ?: MiNote [ 'id' ] ;
851
+ sinceId ?: MiNote [ 'id' ] ;
852
+ limit ?: number ;
853
+ } ,
854
+ q ?: string ) : Promise < MiNote [ ] > {
855
+ if ( ! this . opensearch ) throw new Error ( 'OpenSearch is not available' ) ;
856
+ return await this . searchNote ( me , opts , pagination , q ) ;
857
+ }
858
+
832
859
/**
833
860
* エンドポイントから呼ばれるところ
834
861
*/
@@ -848,6 +875,7 @@ export class AdvancedSearchService {
848
875
followingFilter ?: string | null ;
849
876
offset ?: number | null ;
850
877
useStrictSearch ?: boolean | null ;
878
+ wildCard ?: boolean ;
851
879
} , pagination : {
852
880
untilId ?: MiNote [ 'id' ] ;
853
881
sinceId ?: MiNote [ 'id' ] ;
@@ -883,6 +911,7 @@ export class AdvancedSearchService {
883
911
} ) ;
884
912
osFilter . bool . must . push ( reactionsQuery ) ;
885
913
}
914
+
886
915
if ( opts . reactionsExclude && 0 < opts . reactionsExclude . length ) {
887
916
const reactionsExcludeQuery = {
888
917
nested : {
@@ -922,6 +951,7 @@ export class AdvancedSearchService {
922
951
}
923
952
}
924
953
}
954
+
925
955
if ( opts . origin ) {
926
956
if ( opts . origin === 'local' ) {
927
957
osFilter . bool . must_not . push ( { exists : { field : 'userHost' } } ) ;
@@ -953,13 +983,14 @@ export class AdvancedSearchService {
953
983
954
984
if ( q && q !== '' ) {
955
985
if ( opts . useStrictSearch ) {
986
+ const query = opts . wildCard ? `*${ q } *` : q ;
956
987
osFilter . bool . must . push ( {
957
988
bool : {
958
989
should : [
959
- { wildcard : { 'text.keyword' : q } } ,
960
- { wildcard : { 'cw.keyword' : q } } ,
961
- { wildcard : { 'pollChoices.keyword' : q } } ,
962
- { wildcard : { 'tags' : q } } ,
990
+ { wildcard : { 'text.keyword' : query } } ,
991
+ { wildcard : { 'cw.keyword' : query } } ,
992
+ { wildcard : { 'pollChoices.keyword' : query } } ,
993
+ { wildcard : { 'tags' : query } } ,
963
994
] ,
964
995
minimum_should_match : 1 ,
965
996
} ,
0 commit comments