In ArangoDB I need to search for a certain number of consecutive matches to an array within a document with an integer matrix.
Example document (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.:
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. 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). However, if it were 22, 26, 23, 24
it would match because there are at least four consecutive numbers are from the array. 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.
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. 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? I am not familiar with ArangoDB extensions.
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/3.11/aql/user-defined-functions/)
Would be pretty easy to do it in JS, and use it as a filter match.