Skip to content

Commit 7499780

Browse files
committed
edit: updated dependencies, compatabilities
arangojs: ~~v6.14.1~~ → 7.6.1 arangodb: ~~v3.6.5~~ → 3.8.4
1 parent c558d19 commit 7499780

File tree

16 files changed

+275
-283
lines changed

16 files changed

+275
-283
lines changed

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
4+
parserOptions: {
5+
ecmaVersion: 2020,
6+
sourceType: 'module',
7+
ecmaFeatures: {},
8+
},
9+
10+
settings: {},
11+
12+
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
13+
14+
rules: {},
15+
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
- v0.1.3
4+
- updated dependencies
5+
- arangojs: ~~v6.14.1~~ → 7.6.1
6+
- updated compatabilities
7+
- arangodb: ~~v3.6.5~~ → 3.8.4
8+
39
- v0.1.2
410
- 📓 Updated docs to properly reflect key names. Prior versions of this
511
README were not up to date with the current functionality. Package

README.md

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,50 @@
11
# AQLqueryBuilder.js
22
> a typescript query builder for [arangodb](https://www.arangodb.com)'s [ArangoSearch](https://www.arangodb.com/docs/stable/arangosearch.html)
33
4-
See working demo at [hp4k1h5.github.io](https://hp4k1h5.github.io/#search-box).
5-
6-
**!Note** AQLqueryBuilder.js does NOT contain any code for the search bar, only the
7-
query string parser and AQL builder. Unabstracted code for the searchbar is
8-
located [here](https://github.com/HP4k1h5/hp4k1h5.github.io/tree/main/demos/src/components/search).
9-
10-
![search bar demonstration with schematic query
11-
interface](./img/searchbar_demo.png)
12-
13-
- [Patch Notes](#patch-notes)
14-
- [overview](#overview)
15-
- [setup](#setup)
16-
- [installation](#installation)
17-
- [usage](#usage)
18-
- [`buildAQL()`](#buildaql())
19-
- [boolean search logic](#boolean-search-logic)
20-
- [default query syntax](#default-query-syntax)
21-
- [Example](#example)
22-
- [bugs](#bugs)
23-
- [contributing](#contributing)
4+
[![search bar demonstration with schematic query
5+
interface](./img/searchbar_demo.png)](https://hp4k1h5.github.io/#search-box)
6+
> See working demo at [hp4k1h5.github.io](https://hp4k1h5.github.io/#search-box).
7+
8+
<!-- vim-markdown-toc GFM -->
9+
10+
* [Patch Notes](#patch-notes)
11+
* [Compatabilities](#compatabilities)
12+
* [overview](#overview)
13+
* [setup](#setup)
14+
* [installation](#installation)
15+
* [usage](#usage)
16+
* [`buildAQL()`](#buildaql)
17+
* [query](#query)
18+
* [limit](#limit)
19+
* [`query` example](#query-example)
20+
* [boolean search logic](#boolean-search-logic)
21+
* [`+` AND](#-and)
22+
* [`?` OR](#-or)
23+
* [`-` NOT](#--not)
24+
* [default query syntax](#default-query-syntax)
25+
* [Example](#example)
26+
* [bugs](#bugs)
27+
* [contributing](#contributing)
28+
29+
<!-- vim-markdown-toc -->
2430

2531
## Patch Notes
26-
- v0.1.2
27-
- 📓 Updated docs to properly reflect key names. Prior versions of this
28-
README were not up to date with the current functionality. Package
29-
functionality remains the same. Current and more accurate
30-
documentation can be generated by running `yarn doc && serve docs/`.
31-
32-
- v0.1.1
33-
- ❌ Breaking change!
34-
`buildAQL()`'s `limit` parameter no longer accepts key
35-
`end`, which has been renamed, per Arango spec, to `count`. The functionality
36-
remains the same, which is why the patch bump. Please accept my apologies.
37-
- 🔑🗝 multi-key search
38-
this can be useful if you
39-
have multiple fields with textual information. Theoretically, each
40-
chapter of a book could be stored on its own key. Or a document could
41-
have be translated into several languages, each stored on its own key.
42-
- **There are two ways to provide multiple keys to relevant functions.**
43-
1) `query.key` now accepts in addition to a string value, an array of
44-
strings over which the query is to be run. All keys listed here will be
45-
run combined with all collections provided to `query.collections`
46-
**unless** a collection has a `keys` property of its own, in which case
47-
**only** those keys are searched against.
48-
2) `query.collections[].keys` is an optional array of key names that are
49-
indexed by `query.collections[].analyzer`. **Note** It is important that
50-
any key listed in `query.collections[].keys` be indexed by the analyzer
51-
as it will impact results if such a key does not exist.
5232

33+
- aqlQueryBuilder.js v0.1.3
34+
- updated compatabilities
35+
- arangodb: ~~v3.6.5~~ → 3.8.4
36+
- updated dependencies
37+
- arangojs: ~~v6.14.1~~ → 7.6.1
5338

39+
## Compatabilities
40+
41+
This package is test against the following versions:
42+
- arangojs: 7.6.1
43+
- arangodb: 3.8.4
5444

5545
## overview
5646

57-
ArangoSearch provides a low-level API for interacting with Arango Search Views
58-
through the Arango Query Language (AQL). This library aims to provide a query
59-
parser and AQL query builder to enable full boolean search operations across
60-
all available Arango Search View capabilities, including, `PHRASE` and
61-
`TOKENS` operations. With minimal syntax overhead the user can generate
62-
multi-lingual and language-specific, complex phrase, (proximity... TBD) and
63-
tokenized search terms.
47+
ArangoSearch provides a low-level API for interacting with Arango Search Views through the Arango Query Language (AQL). This library aims to provide a query parser and AQL query builder to enable full boolean search operations across all available Arango Search View capabilities, including, `PHRASE` and `TOKENS` operations. With minimal syntax overhead the user can generate multi-lingual and language-specific, complex phrase, (proximity... TBD) and tokenized search terms.
6448

6549
For example, passing a search phrase like:
6650
```txt
@@ -119,8 +103,7 @@ also accommodate multiple key searches.
119103
___
120104
## setup
121105
122-
1) running generated AQL queries will require a running ArangoDB v3.6+
123-
instance. This package is tested against v3.6.5 🥑
106+
1) running generated AQL queries will require a running ArangoDB v3.8+ instance. This package is tested against arangodb v3.8.4 🥑
124107
125108
## installation
126109
currently there is only support for server-side use.

built/filter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import { filter } from './lib/structs';
2-
export declare function buildFilters(filters: filter[]): import("arangojs/lib/cjs/aql-query").GeneratedAqlQuery;
2+
export declare function buildFilters(filters: filter[]): import("arangojs/aql").GeneratedAqlQuery;

built/filter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var arangojs_1 = require("arangojs");
99
function buildFilters(filters) {
1010
if (!filters.length)
1111
return;
12-
var _filters = filters.map(function (f) { return arangojs_1.aql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["doc.", " ", " ", ""], ["doc.", " ", " ", ""])), f.field, arangojs_1.aql.literal(f.op), f.val); });
13-
return arangojs_1.aql(templateObject_2 || (templateObject_2 = __makeTemplateObject(["FILTER ", ""], ["FILTER ", ""])), arangojs_1.aql.join(_filters, ' && '));
12+
var _filters = filters.map(function (f) { return (0, arangojs_1.aql)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["doc.", " ", " ", ""], ["doc.", " ", " ", ""])), f.field, arangojs_1.aql.literal(f.op), f.val); });
13+
return (0, arangojs_1.aql)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["FILTER ", ""], ["FILTER ", ""])), arangojs_1.aql.join(_filters, ' && '));
1414
}
1515
exports.buildFilters = buildFilters;
1616
var templateObject_1, templateObject_2;

built/index.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { query } from './lib/structs';
22
export { buildFilters } from './filter';
33
export { parseQuery } from './parse';
4-
/** @returns an AQL query object. See @param query for
5-
* details on required values. @param query.terms accepts
6-
* either a string to be parsed or an array of terms. @param limit is an object with keys `start` default 0, and `end` default 20.
7-
* */
4+
/** @returns an AQL query object. See @param query for details on required
5+
* values. @param query.terms accepts either a string to be parsed or an array
6+
* of terms.
7+
*
8+
* ! NOTE: v0.1.1 introduced a breaking change to adhere to the ArangoSearch
9+
* spec. Please refer to
10+
* <https://www.arangodb.com/docs/stable/aql/operations-limit.html> @param
11+
* limit is an object with keys `start` @default 0, and `count` @default 20 */
812
export declare function buildAQL(query: query, limit?: any): any;

built/index.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,30 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
1111
o[k2] = m[k];
1212
}));
1313
exports.__esModule = true;
14-
exports.buildAQL = void 0;
14+
exports.buildAQL = exports.parseQuery = exports.buildFilters = void 0;
1515
var arangojs_1 = require("arangojs");
1616
var search_1 = require("./search");
1717
var filter_1 = require("./filter");
1818
var filter_2 = require("./filter");
1919
__createBinding(exports, filter_2, "buildFilters");
2020
var parse_1 = require("./parse");
2121
__createBinding(exports, parse_1, "parseQuery");
22-
/** @returns an AQL query object. See @param query for
23-
* details on required values. @param query.terms accepts
24-
* either a string to be parsed or an array of terms. @param limit is an object with keys `start` default 0, and `end` default 20.
25-
* */
22+
/** @returns an AQL query object. See @param query for details on required
23+
* values. @param query.terms accepts either a string to be parsed or an array
24+
* of terms.
25+
*
26+
* ! NOTE: v0.1.1 introduced a breaking change to adhere to the ArangoSearch
27+
* spec. Please refer to
28+
* <https://www.arangodb.com/docs/stable/aql/operations-limit.html> @param
29+
* limit is an object with keys `start` @default 0, and `count` @default 20 */
2630
function buildAQL(query, limit) {
27-
if (limit === void 0) { limit = { start: 0, end: 20 }; }
31+
if (limit === void 0) { limit = { start: 0, count: 20 }; }
2832
validateQuery(query);
29-
var SEARCH = search_1.buildSearch(query);
30-
var FILTER = query.filters && filter_1.buildFilters(query.filters);
33+
collectKeys(query);
34+
var SEARCH = (0, search_1.buildSearch)(query);
35+
var FILTER = query.filters && (0, filter_1.buildFilters)(query.filters);
3136
/* FOR doc IN ${query.view} */
32-
return arangojs_1.aql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n FOR doc IN ", "\n ", "\n ", "\n LIMIT ", ", ", "\n RETURN doc"], ["\n FOR doc IN ", "\n ", "\n ", "\n LIMIT ", ", ", "\n RETURN doc"])), arangojs_1.aql.literal(query.view), SEARCH, FILTER, limit.start, limit.end);
37+
return (0, arangojs_1.aql)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n FOR doc IN ", "\n ", "\n ", "\n LIMIT ", ", ", "\n RETURN doc"], ["\n FOR doc IN ", "\n ", "\n ", "\n LIMIT ", ", ", "\n RETURN doc"])), arangojs_1.aql.literal(query.view), SEARCH, FILTER, limit.start, limit.count);
3338
}
3439
exports.buildAQL = buildAQL;
3540
function validateQuery(query) {
@@ -38,4 +43,21 @@ function validateQuery(query) {
3843
if (!query.collections.length)
3944
throw new Error('query.collections must have at least one name');
4045
}
46+
function collectKeys(query) {
47+
/* unify query.key */
48+
var _keys;
49+
if (typeof query.key == 'string') {
50+
_keys = [query.key];
51+
}
52+
else if (!query.key) {
53+
_keys = ['text'];
54+
}
55+
else
56+
_keys = query.key;
57+
query.collections = query.collections.map(function (c) {
58+
if (!c.keys)
59+
c.keys = _keys;
60+
return c;
61+
});
62+
}
4163
var templateObject_1;

built/lib/structs.d.ts

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,84 @@
11
/**
2-
* passed to buildAQL, i.e. `let generatedAQL = buildAQL(query)`. Properties
3-
* mimic or match those familiar to AQL.
4-
* */
2+
* passed to buildAQL, i.e. `let generatedAQL = buildAQL(query)`. Properties
3+
* mimic or match those familiar to AQL.
4+
* */
55
export interface query {
66
/**
7-
* the name of the ArangoSearch View the query will be run against
8-
* */
7+
* the name of the ArangoSearch View the query will be run against
8+
* */
99
view: string;
1010
/**
11-
* the names of the collections indexed by @param view to query
12-
* */
11+
* the names and analyzers of the collections indexed by @param
12+
* view to query
13+
* */
1314
collections: collection[];
1415
/**
15-
* either an array of @param term interfaces or a string to be parsed by `parseQuery()`
16-
* */
16+
* either an array of @param term interfaces or a string to be parsed by `parseQuery()`
17+
* */
1718
terms: term[] | string;
1819
/**
19-
* the name of the document key to search, currently must be the same across
20-
* all documents. @default "text"
21-
* */
22-
key?: string;
20+
* the name(s) of the document key to search. @default "text"
21+
* */
22+
key?: string[] | string;
2323
/**
24-
* a list of @filter interfaces. All filters are implicitly AND'ed together.
25-
* */
24+
* a list of @filter interfaces. All filters are implicitly AND'ed together.
25+
* */
2626
filters?: filter[];
2727
}
2828
/**
29-
* Each collection referenced by the ArangoSearch that the user wishes to
30-
* include in the query must be listed as a collection of the following shape.
31-
*
32-
* A collection can be referenced by several analyzers and each must have its
33-
* own entry in `query.collections` in order to be included in the search.
34-
*
35-
* Alternatively, a document can be stored in several collections.
36-
*
37-
* In either case all desired collection/analyzer combinations must be
38-
* specified.
39-
* */
29+
* Each collection referenced by the ArangoSearch that the user wishes to
30+
* include in the query must be listed as a collection of the following shape.
31+
*
32+
* A collection can be referenced by several analyzers and each must have its
33+
* own entry in `query.collections` in order to be included in the search. If
34+
* a collection does not have a `keys` key, the search will be performed
35+
* across ALL keys listed in `query.key`.
36+
*
37+
* Alternatively, a document can be stored in several collections.
38+
*
39+
* In either case all desired collection/analyzer combinations must be
40+
* specified.
41+
* */
4042
export interface collection {
41-
/**
42-
* the name of the collection
43-
* */
43+
/** the name of the collection */
4444
name: string;
45-
/**
46-
* the name of the text analyzer
47-
* */
45+
/** the name of the text analyzer */
4846
analyzer: string;
47+
keys?: string[];
4948
}
5049
/**
51-
* A piece of search query text. Can be a phrase or an individual word, and will
52-
* belong to one cell or other of the following grid:
53-
* ```
54-
* **ops**
55-
* | | ANDS | ORS | NOTS |
56-
* | ----- | ---- | --- | ----- |
57-
* **types** | PHRASE | | | |
58-
* | TOKENS | | | |
59-
* | PROXIM | TODO | TODO| TODO |
60-
* ```
61-
* */
50+
* A piece of search query text. Can be a phrase or an individual word, and will
51+
* belong to one cell or other of the following grid:
52+
* ```
53+
* **ops**
54+
* | | ANDS | ORS | NOTS |
55+
* | ----- | ---- | --- | ----- |
56+
* **types** | PHRASE | ✅ | ✅ | ✅ |
57+
* | TOKENS | ✅ | ✅ | ✅ |
58+
* | PROXIM | TODO | TODO| TODO |
59+
* | NGRAM | TODO | TODO| TODO |
60+
* | LEVENS | TODO | TODO| TODO |
61+
* ```
62+
* */
6263
export interface term {
6364
/**
64-
* must be one of [ 'phr', 'tok' ], corresponding to `PHRASE` and
65-
* `TOKENS` respectively.
66-
**/
65+
* must be one of [ 'phr', 'tok' ], corresponding to `PHRASE` and
66+
* `TOKENS` respectively.
67+
**/
6768
type: string;
6869
/**
69-
* the search string
70-
* */
70+
* the search string
71+
* */
7172
val: string;
7273
/**
73-
* must be one of [ '+', '?', '-' ] corresponding to `ANDS`, `ORS`, and
74-
* `NOTS`, respectively.
75-
* */
74+
* must be one of [ '+', '?', '-' ] corresponding to `ANDS`, `ORS`, and
75+
* `NOTS`, respectively.
76+
* */
7677
op: string;
7778
}
7879
/**
79-
* passed to AQL `FILTER`
80-
* */
80+
* passed to AQL `FILTER`
81+
* */
8182
export interface filter {
8283
/** the arango document field name to filter on */
8384
field: string;

0 commit comments

Comments
 (0)