查询ArangoDB for Arrays

Use*_*920 6 arangodb aql

我在使用Java查询ArangoDB中的Arays值时遇到问题.我尝试过使用String []和ArrayList,两者都没有成功.

我的查询:

FOR document IN documents FILTER @categoriesArray IN document.categories[*].title RETURN document
Run Code Online (Sandbox Code Playgroud)

BindParams:

Map<String, Object> bindVars = new MapBuilder().put("categoriesArray", categoriesArray).get();
Run Code Online (Sandbox Code Playgroud)

categoriesArray包含一堆字符串.我不确定为什么它没有返回任何结果,因为如果我查询使用:

FOR document IN documents FILTER "Politics" IN document.categories[*].title RETURN document
Run Code Online (Sandbox Code Playgroud)

我得到了我正在寻找的结果.只是在使用Array或ArrayList时没有.

我也试过查询:

FOR document IN documents FILTER ["Politics","Law] IN document.categories[*].title RETURN document
Run Code Online (Sandbox Code Playgroud)

为了模拟ArrayList,但这不会返回任何结果.我会查询使用一堆单独的字符串,但是有太多的东西,当我用一个很长的字符串查询时,我从Java驱动程序中得到一个错误.因此,我必须使用Array或ArrayList进行查询.

categoriesArray的一个例子:

["Politics", "Law", "Nature"]
Run Code Online (Sandbox Code Playgroud)

数据库的示例图像:

在此输入图像描述

stj*_*stj 9

原因是IN操作员通过在右侧的阵列的每个成员中搜索其左侧的值来工作.

通过以下查询,如果"Politics"是以下成员,这将起作用document.categories[*].title:

FOR document IN documents FILTER "Politics" IN document.categories[*].title RETURN document
Run Code Online (Sandbox Code Playgroud)

但是,即使"政治"是以下成员,以下内容也不起作用document.categories[*].title:

FOR document IN documents FILTER [ "Politics", "Law" ] IN document.categories[*].title RETURN document
Run Code Online (Sandbox Code Playgroud)

这是因为它将[ "Politics", "Law" ]在右侧的每个成员中搜索确切的值,并且这将不存在.你可能正在寻找的是一个寻找"Politics""Law"分开的比较,例如:

FOR document IN documents 
LET contained = (
  FOR title IN [ "Politics", "Law" ]   /* or @categoriesArray */
    FILTER title IN document.categories[*].title 
    RETURN title
)
FILTER LENGTH(contained) > 0
RETURN document
Run Code Online (Sandbox Code Playgroud)