search by text content functionality

This commit is contained in:
daniel31x13 2023-11-01 06:01:26 -04:00
parent b1c6a3faf1
commit b1b0d98eb2
9 changed files with 37 additions and 0 deletions

View File

@ -9,6 +9,7 @@ type Props = {
name: boolean;
url: boolean;
description: boolean;
textContent: boolean;
tags: boolean;
};
};
@ -54,6 +55,16 @@ export default function FilterSearchDropdown({
})
}
/>
<Checkbox
label="Text Content"
state={searchFilter.textContent}
onClick={() =>
setSearchFilter({
...searchFilter,
textContent: !searchFilter.textContent,
})
}
/>
<Checkbox
label="Tags"
state={searchFilter.tags}

View File

@ -15,6 +15,7 @@ export default function useLinks(
searchByUrl,
searchByDescription,
searchByTags,
searchByTextContent,
}: LinkRequestQuery = { sort: 0 }
) {
const { links, setLinks, resetLinks } = useLinkStore();
@ -34,6 +35,7 @@ export default function useLinks(
searchByUrl,
searchByDescription,
searchByTags,
searchByTextContent,
};
const buildQueryString = (params: LinkRequestQuery) => {
@ -72,6 +74,7 @@ export default function useLinks(
searchByName,
searchByUrl,
searchByDescription,
searchByTextContent,
searchByTags,
]);

View File

@ -45,6 +45,10 @@ export default async function archive(
const dom = new JSDOM(cleanedUpContent, { url: url });
const article = new Readability(dom.window.document).parse();
const articleText = article?.textContent
.replace(/ +(?= )/g, "") // strip out multiple spaces
.replace(/(\r\n|\n|\r)/gm, " "); // strip out line breaks
await createFile({
data: JSON.stringify(article),
filePath: `archives/${targetLink.collectionId}/${linkId}_readability.json`,
@ -54,6 +58,7 @@ export default async function archive(
where: { id: linkId },
data: {
readabilityPath: `archives/${targetLink.collectionId}/${linkId}_readability.json`,
textContent: articleText,
},
});

View File

@ -42,6 +42,15 @@ export default async function getLink(userId: number, query: LinkRequestQuery) {
});
}
if (query.searchByTextContent) {
searchConditions.push({
textContent: {
contains: query.searchQueryString,
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined,
},
});
}
if (query.searchByTags) {
searchConditions.push({
tags: {

View File

@ -35,6 +35,8 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
searchByUrl: req.query.searchByUrl === "true" ? true : undefined,
searchByDescription:
req.query.searchByDescription === "true" ? true : undefined,
searchByTextContent:
req.query.searchByTextContent === "true" ? true : undefined,
searchByTags: req.query.searchByTags === "true" ? true : undefined,
};

View File

@ -19,6 +19,7 @@ export default function Search() {
name: true,
url: true,
description: true,
textContent: true,
tags: true,
});
@ -32,6 +33,7 @@ export default function Search() {
searchByName: searchFilter.name,
searchByUrl: searchFilter.url,
searchByDescription: searchFilter.description,
searchByTextContent: searchFilter.textContent,
searchByTags: searchFilter.tags,
});

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Link" ADD COLUMN "textContent" TEXT;

View File

@ -103,6 +103,8 @@ model Link {
collectionId Int
tags Tag[]
textContent String?
screenshotPath String?
pdfPath String?
readabilityPath String?

View File

@ -66,6 +66,7 @@ export type LinkRequestQuery = {
searchByName?: boolean;
searchByUrl?: boolean;
searchByDescription?: boolean;
searchByTextContent?: boolean;
searchByTags?: boolean;
};