Skip to content

Commit babf155

Browse files
committed
edit: readme and export issues
1 parent 20347a5 commit babf155

File tree

6 files changed

+149
-33
lines changed

6 files changed

+149
-33
lines changed

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
# AQLqueryBuilder.js
2-
a typescript query builder for [arangodb](https://www.arangodb.com)'s [ArangoSearch](https://www.arangodb.com/docs/stable/arangosearch.html)
2+
> a typescript query builder for [arangodb](https://www.arangodb.com)'s [ArangoSearch](https://www.arangodb.com/docs/stable/arangosearch.html)
3+
4+
## overview
5+
ArangoSearch provides a high-level API for interacting with Arango Search Views
6+
through the Arango Query Language (AQL). This library aims to provide a query
7+
parser and AQL query builder to enable full boolean search operations across
8+
all available Arango Search View capabilities, including, `PHRASE` and
9+
`TOKENS` operations. With minimal syntax overhead the user can generate
10+
multi-lingual and language-specific, complex phrase, proximity and tokenized
11+
search terms.
12+
13+
For example, passing a search phrase like: `+mandatory -exclude ?"optional
14+
phrase"` to `buildAQL`, will produce the following query:
15+
```aql
16+
FOR doc IN search_view
17+
18+
SEARCH
19+
MIN_MATCH(
20+
ANALYZER(
21+
TOKENS(@value0, @value1)
22+
ALL IN doc.@value2, @value1),
23+
@value3) OR (MIN_MATCH(
24+
ANALYZER(
25+
TOKENS(@value0, @value1)
26+
ALL IN doc.@value2, @value1),
27+
@value3) AND @value4)
28+
29+
AND
30+
31+
MIN_MATCH(
32+
ANALYZER(
33+
TOKENS(@value5, @value1)
34+
NONE IN doc.@value2, @value1),
35+
@value3)
36+
37+
OPTIONS @value6
38+
SORT TFIDF(doc) DESC
39+
40+
LIMIT @value7, @value8
41+
RETURN doc
42+
```
43+
This query will retrieve all documents that __include__ the term "mandatory"
44+
AND __do not include__ the term "exclude", AND whose ranking will be boosted by the
45+
presence of the phrase "optional phrase". If no mandatory or exclude terms are
46+
provided, optional terms are considered required, so as not to retrieve all
47+
documents.
48+
49+
## setup
50+
## installation
51+
## usage
52+
### query object
53+
54+
`buildAQL` accepts an object with the following properties:
55+
Example:
56+
```json
57+
{
58+
"view": "the_arango-search_view-name",
59+
"collections": [
60+
{
61+
"name":
62+
"collection_name", "analyzer":
63+
"analyzer_name"
64+
}
65+
],
66+
"query": "either a +query ?\"string for parseQuery to parse\"",
67+
"query": [
68+
{"type": "phr", "op": "?", "val": "\"or a list of query objects\""},
69+
{"type": "tok", "op": "-", "val": "tokens"}
70+
],
71+
"limit":
72+
{
73+
"start": 0,
74+
"end": 20,
75+
}
76+
}
77+
```
78+
### default query syntax
79+
## bugs
80+
## contributing

package.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
{
2-
"name": "aql-js-andsorsnots",
2+
"name": "@hp4k1h5/aqlquerybuilder.js",
33
"version": "0.0.1",
44
"license": "MIT",
5+
"main": "./built/index.d.ts",
56
"scripts": {
67
"test": "mocha -r ts-node/register",
78
"tests": "mocha -r ts-node/register 'tests/*.ts'",
89
"doc": "typedoc src/"
910
},
11+
"homepage": "https://github.com/HP4k1h5/AQLqueryBuilder.js",
12+
"repository": {
13+
"type": "git",
14+
"url": "git@github.com:HP4k1h5/AQLqueryBuilder.js.git"
15+
},
16+
"description": "a typescript query builder for the Arango Query Language (AQL) via ArangoSearch",
17+
"keywords": [
18+
"AQL",
19+
"arangojs",
20+
"arangodb",
21+
"ArangoSearch",
22+
"nodeJs",
23+
"query-builder",
24+
"query-parser",
25+
"typescript"
26+
],
1027
"dependencies": {
1128
"arangojs": "^6.14.1"
1229
},
@@ -19,5 +36,7 @@
1936
"ts-node": "^8.10.2",
2037
"typedoc": "^0.17.7",
2138
"typescript": "^3.9.5"
22-
}
39+
},
40+
"author": "HP4k1h5",
41+
"email": "robertwalks@gmail.com"
2342
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function buildAQL(query: query, limit: any = { start: 0, end: 20 }): any
1717
LIMIT ${limit.start}, ${limit.end}
1818
RETURN doc`
1919
}
20+
exports.buildAQL = buildAQL
2021

2122
function validateQuery(query: query) {
2223
if (!query.view.length) throw Error('query.view must be a valid ArangoSearch View name')

tests/bool.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,20 @@ describe("boolean search logic", () => {
9696
expect(result).to.deep.equal({ a: 1 })
9797
})
9898
})
99+
describe('ORS', () => {
100+
it(`should exclude all results that do not match required terms`, async () => {
101+
const query = {
102+
view: view.name,
103+
collections: [{
104+
name: collectionName,
105+
analyzer: 'text_en'
106+
}],
107+
terms: '+mandatory -exclude ?"optional phrase"'
108+
}
109+
const aqlQuery = buildAQL(query)
110+
expect(aqlQuery.query).to.equal('')
111+
112+
})
113+
})
114+
99115
})

tests/search.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ import { expect } from 'chai'
22
import { buildSearch } from '../src/search'
33

44
describe('search.js', () => {
5-
it('should export a function named buildSearch', () => {
6-
expect(buildSearch).to.be.a('function')
7-
})
5+
it('should export a function named buildSearch', () => {
6+
expect(buildSearch).to.be.a('function')
7+
})
88

9-
it('should return SEARCH true when terms: is an empty string', () => {
10-
const query = { view: 'search_view', collections: [{ name: 'coll', analyzer: 'text_en' }], terms: '' }
11-
const builtSearch = buildSearch(query)
9+
it('should return SEARCH true when terms: is an empty string', () => {
10+
const query = { view: 'search_view', collections: [ { name: 'coll', analyzer: 'text_en' } ], terms: '' }
11+
const builtSearch = buildSearch(query)
1212

13-
expect(builtSearch).to.be.an('object')
14-
expect(Object.keys(builtSearch.bindVars)).to.have.length(2)
15-
expect(builtSearch.bindVars.value0).to.equal(true)
16-
expect(builtSearch.bindVars.value1).to.deep.equal({ collections: ['coll'] })
17-
})
13+
expect(builtSearch).to.be.an('object')
14+
expect(Object.keys(builtSearch.bindVars)).to.have.length(2)
15+
expect(builtSearch.bindVars.value0).to.equal(true)
16+
expect(builtSearch.bindVars.value1).to.deep.equal({ collections: [ 'coll' ] })
17+
})
1818

19-
it('should return an array of aql objects', () => {
20-
const query = { view: 'search_view', collections: [{ name: 'coll', analyzer: 'text_en' }], terms: '-a +"query string" ?token' }
21-
const builtSearch = buildSearch(query)
19+
it('should return an array of aql objects', () => {
20+
const query = { view: 'search_view', collections: [ { name: 'coll', analyzer: 'text_en' } ], terms: '-a +"query string" ?token' }
21+
const builtSearch = buildSearch(query)
2222

23-
expect(Object.keys(builtSearch.bindVars)).to.have.length(7)
24-
expect(builtSearch.bindVars.value0[0].query).to.equal('PHRASE(doc.text, @value0, @value1)')
25-
expect(builtSearch.bindVars.value1).to.deep.equal('token')
26-
expect(builtSearch.bindVars.value2).to.deep.equal('text_en')
27-
expect(builtSearch.bindVars.value3).to.deep.equal('text')
28-
expect(builtSearch.bindVars.value4).to.deep.equal(1)
29-
expect(builtSearch.bindVars.value5).to.deep.equal('a')
30-
expect(builtSearch.bindVars.value6).to.deep.equal({ collections: [query.collections[0].name] })
31-
expect(builtSearch.query).to.equal(`
23+
expect(Object.keys(builtSearch.bindVars)).to.have.length(7)
24+
expect(builtSearch.bindVars.value0[ 0 ].query).to.equal('PHRASE(doc.text, @value0, @value1)')
25+
expect(builtSearch.bindVars.value1).to.deep.equal('token')
26+
expect(builtSearch.bindVars.value2).to.deep.equal('text_en')
27+
expect(builtSearch.bindVars.value3).to.deep.equal('text')
28+
expect(builtSearch.bindVars.value4).to.deep.equal(1)
29+
expect(builtSearch.bindVars.value5).to.deep.equal('a')
30+
expect(builtSearch.bindVars.value6).to.deep.equal({ collections: [ query.collections[ 0 ].name ] })
31+
expect(builtSearch.query).to.equal(`
3232
SEARCH
3333
@value0 OR (@value0 AND MIN_MATCH(
3434
ANALYZER(
@@ -46,5 +46,11 @@ describe('search.js', () => {
4646
4747
OPTIONS @value6
4848
SORT TFIDF(doc) DESC`)
49-
})
49+
})
50+
51+
it('should return an array of aql objects', () => {
52+
const query = { view: 'search_view', collections: [ { name: 'coll', analyzer: 'text_en' } ], terms: '+mandatory -exclude ?"optional phrase"' }
53+
const builtSearch = buildSearch(query)
54+
expect(builtSearch.query).to.equal(``)
55+
}).skip()
5056
})

tsconfig.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
"compilerOptions": {
33
"outDir": "./built",
44
"allowJs": true,
5-
"target": "es5",
5+
"target": "ES2015",
6+
"module": "CommonJS",
67
"declaration": true,
78
"emitDeclarationOnly": true
89
},
910
"include": [
1011
"./src/**/*"
11-
],
12-
"exclude": [
13-
"./built/",
14-
"./node_modules/",
15-
"./tests/"
1612
]
1713
}

0 commit comments

Comments
 (0)