简体   繁体   English

ArangoDB查询与数组的连续匹配

[英]ArangoDB Query for consecutive matches to an array

In ArangoDB I need to search for a certain number of consecutive matches to an array within a document with an integer matrix. 在ArangoDB中,我需要搜索具有整数矩阵的文档中某个数组的一定数量的连续匹配项。

Example document (all are int[5][5]) : 示例文档(all are int[5][5])

nums:
25, 32, 26, 27, 29
01, 22, 15, 17, 99
12, 14, 17, 19, 88
16, 14, 12, 17, 19
02, 08, 09, 18, 19

and in java I have an int[5] example.: 在Java中,我有一个int[5] example.:

22, 23, 24, 25, 26

I need to return all documents in which any of the following are true: 我需要返回所有符合以下任何条件的文档:

At least 4 numbers from the java array match at least 4 consecutive numbers in any matrix row. java数组中的至少4个数字与任何矩阵行中的至少4个连续数字匹配。 Eg. 例如。 If a matrix row has 22, 23, **29**, 24, 25 it would not match because no set of four numbers from the array are next to eachother (it doesn't matter, however, if the order matches that of the array). 如果矩阵行具有22, 23, **29**, 24, 25则它将不匹配,因为数组中没有四个数字彼此相邻(但是,如果顺序与数组)。 However, if it were 22, 26, 23, 24 it would match because there are at least four consecutive numbers are from the array. 但是,如果它是22, 26, 23, 24则它将匹配,因为数组中至少有四个连续的数字。 Eg: 例如:

**22**, 32, 26, 27, 29
**26**, 22, 15, 17, 99
**23**, 14, 17, 19, 88
**24**, 14, 12, 17, 19
  02,   08, 09, 18, 19

The same as above but in any matrix column instead of row 与上面相同,但在任何矩阵列而不是行中

20, 01, 02,  03,  08
01,*22,*23*,*25*,*24*
12, 14, 17, 19, 88
16, 14, 12, 17, 19
02, 08, 09, 18, 19

The same as the last two but diagonally, instead of in a row or column 与最后两个相同,但对角线,而不是一行或一列

**22**, 32, 26, 27, 29            01, 02, 03,   04,   05
01, **23**, 15, 17, 99            06, 07, 08, **24**, 10
12, 14, **26**, 19, 88            11, 12, **23**, 14, 15
16, 14, 12, **25**, 19            16, **25**, 18, 19, 20
02, 08, 09,   18,   19          **22**, 22,   23, 24, 25

No two numbers in any matrix are the same. 任何矩阵中没有两个数字是相同的。 Eg, there will not be the number 1 more than once in the entire matrix. 例如,在整个矩阵中,数字1不会超过一次。

I'm not really sure about how to approach such a problem. 我不确定如何解决这个问题。 For the moment I am querying all documents that have at least 4 numbers in the matrix that match the array's numbers, but I would imagine that there is a way to query for this. 目前,我正在查询矩阵中至少有4个与数组数字匹配的数字的所有文档,但是我可以想象有一种查询此方法的方法。 All I can think of doing is generating a combination of every possible matrix to query for matching matrices, which obviously isn't realistic. 我能想到的就是生成每个可能矩阵的组合来查询匹配矩阵,这显然是不现实的。

Update : Regarding the answer that recommends using a JS extension, how would one go about doing this to solve the problem? 更新 :关于建议使用JS扩展的答案,如何解决这一问题呢? I am not familiar with ArangoDB extensions. 我对ArangoDB扩展不熟悉。

It might be a bit contrived to do this with pure AQL, I'd recommend checking out adding your own JS function to match it (see https://docs.arangodb.com/AqlExtending/index.html ) 使用纯AQL进行此操作可能有点设计不足,建议您添加自己的JS函数以匹配它(请参阅https://docs.arangodb.com/AqlExtending/index.html

Would be pretty easy to do it is JS, and use it as a filter match. 使用JS会很容易,并将其用作过滤器匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM