mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-06 04:21:55 +00:00
chore: add ability to search for everything
This commit is contained in:
@@ -20,7 +20,7 @@ const postFuse = new Fuse<ExtendedPostInfo>(
|
|||||||
includeScore: true,
|
includeScore: true,
|
||||||
ignoreFieldNorm: true,
|
ignoreFieldNorm: true,
|
||||||
},
|
},
|
||||||
postIndex
|
postIndex,
|
||||||
);
|
);
|
||||||
|
|
||||||
const collectionFuse = new Fuse(
|
const collectionFuse = new Fuse(
|
||||||
@@ -31,20 +31,38 @@ const collectionFuse = new Fuse(
|
|||||||
includeScore: true,
|
includeScore: true,
|
||||||
ignoreFieldNorm: true,
|
ignoreFieldNorm: true,
|
||||||
},
|
},
|
||||||
collectionIndex
|
collectionIndex,
|
||||||
);
|
);
|
||||||
|
|
||||||
export default async (req: VercelRequest, res: VercelResponse) => {
|
export default async (req: VercelRequest, res: VercelResponse) => {
|
||||||
// TODO: `pickdeep` only required fields
|
// TODO: `pickdeep` only required fields
|
||||||
const searchStr = req?.query?.query as string;
|
const searchStr = req?.query?.query as string;
|
||||||
if (!searchStr) return [];
|
if (!searchStr) {
|
||||||
if (Array.isArray(searchStr)) return [];
|
res.send({
|
||||||
const posts = postFuse.search(searchStr).map((item) => item.item);
|
posts: [],
|
||||||
const collections = collectionFuse.search(searchStr).map((item) => item.item);
|
totalPosts: 0,
|
||||||
|
collections: [],
|
||||||
|
totalCollections: 0,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (searchStr === "*") {
|
||||||
|
res.send({
|
||||||
|
posts,
|
||||||
|
totalPosts: posts.length,
|
||||||
|
collections,
|
||||||
|
totalCollections: collections.length,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const searchedPosts = postFuse.search(searchStr).map((item) => item.item);
|
||||||
|
const searchedCollections = collectionFuse
|
||||||
|
.search(searchStr)
|
||||||
|
.map((item) => item.item);
|
||||||
res.send({
|
res.send({
|
||||||
posts,
|
posts: searchedPosts,
|
||||||
totalPosts: posts.length,
|
totalPosts: searchedPosts.length,
|
||||||
collections,
|
collections: searchedCollections,
|
||||||
totalCollections: collections.length,
|
totalCollections: searchedCollections.length,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user