具有多个属性和FULLTEXT搜索的ArangoDB查询

时间:2017-05-19 12:36:13

标签: arangodb arangojs

以下是我的收藏结构,有3个收藏,图片,类别和标签

我想过滤所有"图片"它有关键字(FULLTEXT搜索),如" cow"属于"动物"类别并标记为"照片"

如何使用ArangoDB进行此过滤,我使用的是nodejs / foxx。请帮忙。

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"
}

1 个答案:

答案 0 :(得分:1)

这是一个请求:

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

您必须为image.keywords字段设置全文索引