Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

search by text content functionality

daniel31x13b1b0d98eb26e
diff --git a/components/FilterSearchDropdown.tsx b/components/FilterSearchDropdown.tsx
index 181febbb..0b32bee7 100644
--- a/components/FilterSearchDropdown.tsx
+++ b/components/FilterSearchDropdown.tsx
@@ -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}
diff --git a/hooks/useLinks.tsx b/hooks/useLinks.tsx
index 56024b0d..60f43dbd 100644
--- a/hooks/useLinks.tsx
+++ b/hooks/useLinks.tsx
@@ -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,
]);
diff --git a/lib/api/archive.ts b/lib/api/archive.ts
index 25f55142..e55d86de 100644
--- a/lib/api/archive.ts
+++ b/lib/api/archive.ts
@@ -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,
},
});
diff --git a/lib/api/controllers/links/getLinks.ts b/lib/api/controllers/links/getLinks.ts
index fd0f257b..18edf91d 100644
--- a/lib/api/controllers/links/getLinks.ts
+++ b/lib/api/controllers/links/getLinks.ts
@@ -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: {
diff --git a/pages/api/v1/links/index.ts b/pages/api/v1/links/index.ts
index c8780832..e882c156 100644
--- a/pages/api/v1/links/index.ts
+++ b/pages/api/v1/links/index.ts
@@ -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,
};
diff --git a/pages/search/index.tsx b/pages/search/index.tsx
index 01ca6ef2..35abdc76 100644
--- a/pages/search/index.tsx
+++ b/pages/search/index.tsx
@@ -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,
});
diff --git a/prisma/migrations/20231101085207_add_text_content_field/migration.sql b/prisma/migrations/20231101085207_add_text_content_field/migration.sql
new file mode 100644
index 00000000..3d03e3cf
--- /dev/null
+++ b/prisma/migrations/20231101085207_add_text_content_field/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "textContent" TEXT;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index a6bd6bb2..f5574e2f 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -103,6 +103,8 @@ model Link {
collectionId Int
tags Tag[]
+ textContent String?
+
screenshotPath String?
pdfPath String?
readabilityPath String?
diff --git a/types/global.ts b/types/global.ts
index 4af954d8..b878a849 100644
--- a/types/global.ts
+++ b/types/global.ts
@@ -66,6 +66,7 @@ export type LinkRequestQuery = {
searchByName?: boolean;
searchByUrl?: boolean;
searchByDescription?: boolean;
+ searchByTextContent?: boolean;
searchByTags?: boolean;
};