diff --git a/pages/search.tsx b/pages/search.tsx index 7948d11..c17c383 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -39,7 +39,16 @@ export default function Search(props: any) { export async function getServerSideProps(context: any) { if (context.query.q) { const tags = (context.query.q.split(',')).map((tag: string) => tag.trim()) - const images = await db_ops.image_ops.find_images_by_tags(tags) + const include_tags=[] + const exclude_tags=[] + for(const tag of tags){ + if(tag[0]==='-'){ + exclude_tags.push(tag.slice(1)) + }else{ + include_tags.push(tag) + } + } + const images = await db_ops.image_ops.find_images_by_tags(include_tags,exclude_tags) const images_on_page = 30 const photos = [] let page; diff --git a/server/helpers/db_ops.ts b/server/helpers/db_ops.ts index 08d6773..9963914 100644 --- a/server/helpers/db_ops.ts +++ b/server/helpers/db_ops.ts @@ -135,8 +135,13 @@ async function get_all_images(){ return imgs } -async function find_images_by_tags(tags:Array){ - const imgs = findDocuments("images", {tags:{$all:tags}}) +async function find_images_by_tags(include_tags:Array,exclude_tags:Array){ + console.log(include_tags) + console.log(exclude_tags) + const imgs = findDocuments("images", { $and: [ + { tags: { $all: include_tags } }, + { tags: { $not: { $all: exclude_tags }}} + ] }) return imgs } async function find_image_by_sha512(hash:string){