Skip to content

Commit 191a014

Browse files
committed
edit: update README
1 parent ccb1b63 commit 191a014

File tree

1 file changed

+42
-73
lines changed

1 file changed

+42
-73
lines changed

README.md

Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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-
[![search bar demonstration with schematic query
5-
interface](./img/searchbar_demo.png)](https://hp4k1h5.github.io/#search-box)
4+
[![search bar demonstration with schematic query interface](./img/searchbar_demo.png)](https://hp4k1h5.github.io/#search-box)
5+
66
> See working demo at [hp4k1h5.github.io](https://hp4k1h5.github.io/#search-box).
77
88
<!-- vim-markdown-toc GFM -->
@@ -13,6 +13,7 @@ interface](./img/searchbar_demo.png)](https://hp4k1h5.github.io/#search-box)
1313
* [setup](#setup)
1414
* [installation](#installation)
1515
* [usage](#usage)
16+
* [Exported Functions](#exported-functions)
1617
* [`buildAQL()`](#buildaql)
1718
* [query](#query)
1819
* [limit](#limit)
@@ -87,26 +88,16 @@ SEARCH
8788
RETURN doc`
8889
```
8990
90-
This query will retrieve all documents that __include__ the term "mandatory"
91-
AND __do not include__ the term "exclude", AND whose ranking will be boosted
92-
by the presence of the phrase "optional phrase". If no mandatory or exclude
93-
terms are provided, optional terms are considered required, so as not to
94-
retrieve all documents.
95-
96-
See [default query syntax](#default-query-syntax) and this schematic
97-
[example](#example) for more details.
91+
See [default query syntax](#default-query-syntax) and this schematic [example](#example) for more details.
9892
99-
If multiple collections are passed, the above query is replicated across all
100-
passed collections, see examples in 'tests/cols.ts'. In the future this will
101-
also accommodate multiple key searches.
93+
If multiple collections are passed, the query is replicated across all passed collections, see examples in 'tests/cols.ts'. In the future this will also accommodate multiple key searches.
10294
10395
___
10496
## setup
10597
10698
1) running generated AQL queries will require a running ArangoDB v3.8+ instance. This package is tested against arangodb v3.8.4 🥑
10799
108100
## installation
109-
currently there is only support for server-side use.
110101
111102
1) run `yarn add @hp4k1h5/AQLqueryBuilder.js`
112103
or `npm install --save @hp4k1h5/AQLqueryBuilder.js`
@@ -116,34 +107,27 @@ currently there is only support for server-side use.
116107
inside the directory.
117108
118109
2) import/require the exported functions
110+
119111
```js
120112
// use either
121113
import {buildAQL, parseQuery} from '@hp4k1h5/AQLqueryBuilder.js'
122114
// or
123115
const {buildAQL} = require('@hp4k1h5/AQLqueryBuilder.js')
124116
```
125-
This has been tested for
126-
- ✅ node v17.3.0
127-
- ✅ typescript v4.5.4
117+
118+
This has been tested for
119+
- ✅ node v17.3.0
120+
- ✅ typescript v4.5.4
128121

129122
## usage
130-
__for up-to-date documentation, run `yarn doc && serve docs/` from the project
131-
directory root.__
132123

133-
AQLqueryBuilder aims to provide cross-collection and cross-language, multi-key
134-
boolean search capabilities to the library's user.
124+
__for up-to-date documentation, run `yarn doc && serve docs/` from the project directory root.__
135125

136-
Please ensure that the data you are trying to query against is indexed by an
137-
ArangoSearch View. The query will target all combinations of provided
138-
collections, analyzers and keys an simultaneously. This allows for granular
139-
multi-language search. This library is primarily built for academic and
140-
textual searches, and is ideally suited for documents like books, articles,
141-
and other text-heavy media.
126+
AQLqueryBuilder aims to provide cross-collection and cross-language, multi-key boolean search capabilities to the library's user.
142127

143-
AQLqueryBuilder works best as a document query tool. Leveraging ArangoSearch's
144-
built-in language stemming analyzers allows for complex search phrases to be
145-
run against any number of language-specific collections simultaneously.
128+
Please ensure that the data you are trying to query against is indexed by an ArangoSearch View. The query will target all combinations of provided collections, analyzers and keys an simultaneously. This allows for granular multi-language search. This library is primarily built for academic and textual searches, and is ideally suited for documents like books, articles, and other text-heavy media.
146129

130+
AQLqueryBuilder works best as a document query tool. Leveraging ArangoSearch's built-in language stemming analyzers allows for complex search phrases to be run against any number of language-specific collections simultaneously.
147131

148132
__Example:__
149133
```javascript
@@ -167,16 +151,20 @@ const aqlQuery = buildAQL(queryObject, limit)
167151
// ... const cursor = await db.query(buildAQL(queryObject, {start:20, count:20})
168152
```
169153

170-
Generate documenation with `yarn doc && serve docs/` or see more examples in
171-
e.g. [tests/search.ts](tests/search.ts)
154+
Generate documentation with `yarn doc && serve docs/` or see more examples in [tests/search.ts](tests/search.ts)
172155

173156
___
174157

158+
## Exported Functions
159+
175160
### `buildAQL()`
176161

177162
`buildAQL` accepts two parameters: `query` and `limit`
178163

179164
#### query
165+
166+
`query` is an object with the following keys:
167+
180168
**view**: *string* (required): the name of the ArangoSearch view the query
181169
will be run against
182170

@@ -189,12 +177,8 @@ to query. Objects have the following shape:
189177
"keys": ["text", "summary", "notes"]
190178
}
191179
```
192-
`keys` are optional, though if key names are provided to `query.key`, and
193-
not all those keys are indexed by the collection, it is advisable to
194-
explicitly list only those keys on documents in that collection that are
195-
indexed by the analyzer. If a collection is indexed by multiple analyzers
196-
please list each collection-analyzer combination along with their relevant
197-
keys, unless a unified set of keys is provided to `query.key`.
180+
181+
`keys` are optional, though if key names are provided to `query.key`, and not all those keys are indexed by the collection, it is advisable to explicitly list only those keys on documents in that collection that are indexed by the analyzer. If a collection is indexed by multiple analyzers please list each collection-analyzer combination along with their relevant keys, unless a unified set of keys is provided to `query.key`.
198182

199183
**terms** (required): either an array of `term` interfaces or a query string
200184
to be parsed by `parseQuery()`.
@@ -207,14 +191,10 @@ to be parsed by `parseQuery()`.
207191
- **type** *string* (required): **one of `"phr"`** for PHRASES **or `"tok"`**
208192
for TOKENS.
209193

210-
**key** (optional | default: "text"): the name of the Arango document key to
211-
search within.
194+
**key** (optional | default: "text"): the name of the Arango document key to search within.
195+
196+
**filters** (optional): a list of filter interfaces. See [arango FILTER operations](https://www.arangodb.com/docs/stable/aql/operations-filter.html) for more details. All [Arango operators](https://www.arangodb.com/docs/3.6/aql/operators.html ) Filters have the following shape:
212197

213-
**filters** (optional): a list of filter interfaces. See [arango FILTER
214-
operations](https://www.arangodb.com/docs/stable/aql/operations-filter.html)
215-
for more details. All [Arango
216-
operators](https://www.arangodb.com/docs/3.6/aql/operators.html ) Filters have
217-
the following shape:
218198
```json
219199
{
220200
"field": "the name of the field, i.e. Arango document key to filter on",
@@ -224,9 +204,11 @@ the following shape:
224204
```
225205

226206
#### limit
207+
227208
an object with the following keys:
209+
228210
- `start` (integer) 0-based result pagination lower bound.
229-
- `count` (integer) total number of results to return. ⚠ see CHANGELOG v0.1.1
211+
- `count` (integer) total number of results to return.
230212

231213
to bring back up to the first 10 results
232214
```json
@@ -238,6 +220,7 @@ and the next page would be
238220
```
239221

240222
#### `query` example
223+
241224
```json
242225
{
243226
"view": "the_arango-search_view-name",
@@ -271,38 +254,30 @@ and the next page would be
271254
```
272255

273256
___
257+
274258
### boolean search logic
275-
Quoting [mit's Database Search Tips](https://libguides.mit.edu/c.php?g=175963&p=1158594):
276-
> Boolean operators form the basis of mathematical sets and database logic.
277-
They connect your search words together to either narrow or broaden your
278-
set of results. The three basic boolean operators are: AND, OR, and NOT.
259+
260+
> Boolean operators form the basis of mathematical sets and database logic. They connect your search words together to either narrow or broaden your set of results. The three basic boolean operators are: AND, OR, and NOT.
261+
262+
from [mit's Database Search Tips](https://libguides.mit.edu/c.php?g=175963&p=1158594)
279263

280264
#### `+` AND
281265

282-
* Mandatory terms and phrases. All results MUST INCLUDE these terms and
283-
phrases.
266+
* Mandatory terms and phrases. All results MUST INCLUDE these terms and phrases.
284267

285268
#### `?` OR
286269

287-
* Optional terms and phrases. If there are ANDS or NOTS, these serve as match
288-
score "boosters". If there are no ANDS or NOTS, ORS become required in
289-
results.
270+
* Optional terms and phrases. If there are ANDS or NOTS, these serve as match score "boosters". If there are no ANDS or NOTS, ORS become required in results.
290271

291272
#### `-` NOT
292273

293-
* Search results MUST NOT INCLUDE these terms and phrases. If a result that
294-
would otherwise have matched, contains one or more terms or phrases, it will
295-
not be included in the result set. If there are no required or optional
296-
terms, all results that do NOT match these terms will be returned.
274+
* Search results MUST NOT INCLUDE these terms and phrases. If a result that would otherwise have matched, contains one or more terms or phrases, it will not be included in the result set. If there are no required or optional terms, all results that do NOT match these terms will be returned.
297275

298276
### default query syntax
299277

300-
for more information on boolean search logic see
301-
[above](#boolean-search-logic)
278+
for more information on boolean search logic see [above](#boolean-search-logic)
302279

303-
The default syntax accepted by `buildAQL()`'s query paramter key `terms` when
304-
passing in a string, instead of a `term` interface compatible array is as
305-
follows:
280+
The default syntax accepted by `buildAQL()`'s query paramter key `terms` when passing in a string, instead of a `term` interface compatible array is as follows:
306281

307282
1) Everything inside single or double quotes is considered a `PHRASE`
308283
2) Everything else is considered a word to be analyzed by `TOKENS`
@@ -313,24 +288,18 @@ optional and is counted as an `OR`.
313288

314289
Please see [tests/parse.ts](tests/parse.ts) for more examples.
315290

316-
317291
#### Example
318292

319-
input `one +two -"buckle my shoe"` and `parseQuery()` will interpret that
320-
query string as follows:
293+
input `one +two -"buckle my shoe"` and `parseQuery()` will interpret that query string as follows:
321294

322295
| | ANDS | ORS | NOTS |
323296
| - | - | - | - |
324297
| PHRASE | | | "buckle my shoe" |
325298
| TOKENS | two | one | |
326299

327-
The generated AQL query, when run, will bring back only results that contain
328-
"two", that do not contain the phrase "buckle my shoe", and that optionally
329-
contain "one". In this case, documents that contain "one" will be likely to
330-
score higher than those that do not.
300+
The generated AQL query, when run, will bring back only results that contain "two", that do not contain the phrase "buckle my shoe", and that optionally contain "one". In this case, documents that contain "one" will be likely to score higher than those that do not.
331301

332-
When the above phrase `one +two -"buckle my shoe"` is run against the
333-
following documents:
302+
When the above phrase `one +two -"buckle my shoe"` is run against the following documents:
334303

335304
```boxcar
336305
┏━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━┓

0 commit comments

Comments
 (0)