Search code examples
arangodbarangojs

ArangoDB query with multiple attributes and FULLTEXT search


Below is my collection structure, has 3 collection, image, category and tags

I want to filter all "images" which has keyword (FULLTEXT search) like "cow" and belongs to "animals" category and tagged with "photo"

How can I do this filter with ArangoDB, I am using nodejs / foxx . Please help.

image{
filename:"myphoto.jpg",
filepath:"/opt/data/949b3e6194bf6f0ef3eb367a615826f8"
categories:[category/6401, category/6402],
tags:[tags/1002],
keywords:"photo green cow"
}

category{
    _id:'category/6401',
   name:"animals"
}

category{
    _id:'category/6402',
   name:"living things"
}

tags{
    _id:'tags/1002',
   name:"photo"
}

tags{
    _id:'tags/1003',
   name:"colors"
}

Solution

  • Here a request :

    FOR i IN FULLTEXT(image, "keywords", "cow") // First search for fulltext
        FOR cat IN category // Then Loop on all categories
        FILTER cat.name == "animals" // Filter by name
        FILTER POSITION(i.categories, cat._id) == true // Join
        FOR tag IN tags // Then Loop on all tags
            FILTER tag.name == "photo" // Filter by name
            FILTER POSITION(i.tags, tag._id) == true // Join
            RETURN i // Return all images found
    

    You must have a fulltext index set to your image.keywords field