Skip to content

Commit

Permalink
Api: Search for partial matches by default, unless the query is surro…
Browse files Browse the repository at this point in the history
…unded by quotes
  • Loading branch information
laurent22 committed Nov 19, 2023
1 parent 8a533b2 commit 401d551
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/lib/services/rest/routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ErrorBadRequest, ErrorMethodNotAllowed } from '../utils/errors';
import requestFields from '../utils/requestFields';
import collectionToPaginatedResults from '../utils/collectionToPaginatedResults';
import BaseItem from '../../../models/BaseItem';
import SearchEngineUtils from '../../searchengine/SearchEngineUtils';
import SearchEngineUtils, { NotesForQueryOptions } from '../../searchengine/SearchEngineUtils';

export default async function(request: Request) {
if (request.method !== 'GET') throw new ErrorMethodNotAllowed();
Expand All @@ -28,7 +28,11 @@ export default async function(request: Request) {
options.caseInsensitive = true;
results = await ModelClass.all(options);
} else {
results = await SearchEngineUtils.notesForQuery(query, false, defaultLoadOptions(request, ModelType.Note));
const options: NotesForQueryOptions = {
...defaultLoadOptions(request, ModelType.Note),
appendWildCards: true,
};
results = await SearchEngineUtils.notesForQuery(query, false, options);
}

return collectionToPaginatedResults(modelType, results, request);
Expand Down

0 comments on commit 401d551

Please sign in to comment.