search by text content functionality
This commit is contained in:
parent
b1c6a3faf1
commit
b1b0d98eb2
|
@ -9,6 +9,7 @@ type Props = {
|
||||||
name: boolean;
|
name: boolean;
|
||||||
url: boolean;
|
url: boolean;
|
||||||
description: boolean;
|
description: boolean;
|
||||||
|
textContent: boolean;
|
||||||
tags: 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
|
<Checkbox
|
||||||
label="Tags"
|
label="Tags"
|
||||||
state={searchFilter.tags}
|
state={searchFilter.tags}
|
||||||
|
|
|
@ -15,6 +15,7 @@ export default function useLinks(
|
||||||
searchByUrl,
|
searchByUrl,
|
||||||
searchByDescription,
|
searchByDescription,
|
||||||
searchByTags,
|
searchByTags,
|
||||||
|
searchByTextContent,
|
||||||
}: LinkRequestQuery = { sort: 0 }
|
}: LinkRequestQuery = { sort: 0 }
|
||||||
) {
|
) {
|
||||||
const { links, setLinks, resetLinks } = useLinkStore();
|
const { links, setLinks, resetLinks } = useLinkStore();
|
||||||
|
@ -34,6 +35,7 @@ export default function useLinks(
|
||||||
searchByUrl,
|
searchByUrl,
|
||||||
searchByDescription,
|
searchByDescription,
|
||||||
searchByTags,
|
searchByTags,
|
||||||
|
searchByTextContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildQueryString = (params: LinkRequestQuery) => {
|
const buildQueryString = (params: LinkRequestQuery) => {
|
||||||
|
@ -72,6 +74,7 @@ export default function useLinks(
|
||||||
searchByName,
|
searchByName,
|
||||||
searchByUrl,
|
searchByUrl,
|
||||||
searchByDescription,
|
searchByDescription,
|
||||||
|
searchByTextContent,
|
||||||
searchByTags,
|
searchByTags,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,10 @@ export default async function archive(
|
||||||
const dom = new JSDOM(cleanedUpContent, { url: url });
|
const dom = new JSDOM(cleanedUpContent, { url: url });
|
||||||
const article = new Readability(dom.window.document).parse();
|
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({
|
await createFile({
|
||||||
data: JSON.stringify(article),
|
data: JSON.stringify(article),
|
||||||
filePath: `archives/${targetLink.collectionId}/${linkId}_readability.json`,
|
filePath: `archives/${targetLink.collectionId}/${linkId}_readability.json`,
|
||||||
|
@ -54,6 +58,7 @@ export default async function archive(
|
||||||
where: { id: linkId },
|
where: { id: linkId },
|
||||||
data: {
|
data: {
|
||||||
readabilityPath: `archives/${targetLink.collectionId}/${linkId}_readability.json`,
|
readabilityPath: `archives/${targetLink.collectionId}/${linkId}_readability.json`,
|
||||||
|
textContent: articleText,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
if (query.searchByTags) {
|
||||||
searchConditions.push({
|
searchConditions.push({
|
||||||
tags: {
|
tags: {
|
||||||
|
|
|
@ -35,6 +35,8 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||||
searchByUrl: req.query.searchByUrl === "true" ? true : undefined,
|
searchByUrl: req.query.searchByUrl === "true" ? true : undefined,
|
||||||
searchByDescription:
|
searchByDescription:
|
||||||
req.query.searchByDescription === "true" ? true : undefined,
|
req.query.searchByDescription === "true" ? true : undefined,
|
||||||
|
searchByTextContent:
|
||||||
|
req.query.searchByTextContent === "true" ? true : undefined,
|
||||||
searchByTags: req.query.searchByTags === "true" ? true : undefined,
|
searchByTags: req.query.searchByTags === "true" ? true : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ export default function Search() {
|
||||||
name: true,
|
name: true,
|
||||||
url: true,
|
url: true,
|
||||||
description: true,
|
description: true,
|
||||||
|
textContent: true,
|
||||||
tags: true,
|
tags: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ export default function Search() {
|
||||||
searchByName: searchFilter.name,
|
searchByName: searchFilter.name,
|
||||||
searchByUrl: searchFilter.url,
|
searchByUrl: searchFilter.url,
|
||||||
searchByDescription: searchFilter.description,
|
searchByDescription: searchFilter.description,
|
||||||
|
searchByTextContent: searchFilter.textContent,
|
||||||
searchByTags: searchFilter.tags,
|
searchByTags: searchFilter.tags,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Link" ADD COLUMN "textContent" TEXT;
|
|
@ -103,6 +103,8 @@ model Link {
|
||||||
collectionId Int
|
collectionId Int
|
||||||
tags Tag[]
|
tags Tag[]
|
||||||
|
|
||||||
|
textContent String?
|
||||||
|
|
||||||
screenshotPath String?
|
screenshotPath String?
|
||||||
pdfPath String?
|
pdfPath String?
|
||||||
readabilityPath String?
|
readabilityPath String?
|
||||||
|
|
|
@ -66,6 +66,7 @@ export type LinkRequestQuery = {
|
||||||
searchByName?: boolean;
|
searchByName?: boolean;
|
||||||
searchByUrl?: boolean;
|
searchByUrl?: boolean;
|
||||||
searchByDescription?: boolean;
|
searchByDescription?: boolean;
|
||||||
|
searchByTextContent?: boolean;
|
||||||
searchByTags?: boolean;
|
searchByTags?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue