include/exclude tags

This commit is contained in:
qwertyforce 2020-09-17 10:46:18 +03:00
parent 901fc721ca
commit d58ecadd66
2 changed files with 17 additions and 3 deletions

View File

@ -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;

View File

@ -135,8 +135,13 @@ async function get_all_images(){
return imgs
}
async function find_images_by_tags(tags:Array<string>){
const imgs = findDocuments("images", {tags:{$all:tags}})
async function find_images_by_tags(include_tags:Array<string>,exclude_tags:Array<string>){
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){