Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/wikidata importer #178

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
merge in more recent tests
dothebart committed Oct 20, 2021
commit 746b63d0084a70a755ac4ebfa4e8656265b6fdf4
130 changes: 129 additions & 1 deletion test_data/tests/arangosearch/arangosearch-phrase-test.js
Original file line number Diff line number Diff line change
@@ -151,6 +151,64 @@ function ArangoSearch_PHRASE() {
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// variadic arguments
{
let actual = db._query(`
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, "Lord", 0, "of", 0, "The", 0, "Rings", "tokenizer")
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// variadic arguments + object notation
{
let actual = db._query(`
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, { TERM : "lord" }, 0, "of", 0, "The", 0, "Rings", "tokenizer")
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// variadic arguments + object notation
{
let actual = db._query(`
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, { TERM : ["lord"] }, 0, "of", 0, "The", 0, "Rings", "tokenizer")
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// variadic arguments + object notation, analyzer is not applied to object notation
{
let actual = db._query(`
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, { TERM : "Lord" }, 0, "of", 0, "The", 0, "Rings", "tokenizer")
SORT d._id
RETURN d`).toArray();

assertEqual(0, actual.length);
}

// variadic arguments + object notation, analyzer is not applied to object notation
{
let actual = db._query(`
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, { TERM : ["Lord"] }, 0, "of", 0, "The", 0, "Rings", "tokenizer")
SORT d._id
RETURN d`).toArray();

assertEqual(0, actual.length);
}

// arguments as bind variables
{
let actual = db._query(`
@@ -186,7 +244,7 @@ function ArangoSearch_PHRASE() {
SEARCH PHRASE(d.title, [input], analyzer)
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}
@@ -204,6 +262,44 @@ function ArangoSearch_PHRASE() {
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// arguments as an array, object notation
{
let actual = db._query(`
LET analyzer = "tokenizer"
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, [{TERM:"lord"}, 0, "of", "The", "Rings"], analyzer)
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// arguments as an array, object notation
{
let actual = db._query(`
LET analyzer = "tokenizer"
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, [{TERM:["lord"]}, 0, "of", "The", "Rings"], analyzer)
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}

// arguments as an array, object notation, analyzer isn't applied
{
let actual = db._query(`
LET analyzer = "tokenizer"
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, [{TERM:["Lord"]}, 0, "of", "The", "Rings"], analyzer)
SORT d._id
RETURN d`).toArray();

assertEqual(0, actual.length);
}

// arguments as an array
{
let actual = db._query(`
@@ -228,6 +324,38 @@ function ArangoSearch_PHRASE() {
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}
},

testProximityPhrase: function () {
let expected = db._query(`
LET input = "Lord Rings"
LET phrase = TOKENS(input, "tokenizer")
LET offsets = [ 0, 2 ]
FOR d IN wikipedia
FILTER LENGTH(d.title) >= LENGTH(input)
LET tokens = TOKENS(d.title, "tokenizer")
FILTER phrase ALL IN tokens
FILTER LENGTH(
FOR leadPos IN 0..LENGTH(tokens)-1
FILTER tokens[leadPos] == phrase[0]
FILTER LENGTH(FOR i IN 0..LENGTH(phrase)-1
FILTER phrase[i] == tokens[leadPos+offsets[i]]
RETURN 1) == LENGTH(phrase)
RETURN 1) > 0
SORT d._id
RETURN d`).toArray();
assertNotEqual(expected.length, 0);

{
let actual = db._query(`
FOR d IN v_wiki_phrase
SEARCH PHRASE(d.title, "Lord", 2, "Rings", "tokenizer")
SORT d._id
RETURN d`).toArray();

assertEqual(expected.length, actual.length);
actual.forEach((rhs, i) => assertTrue(_.isEqual(expected[i], rhs)));
}