Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Rename PhrasematchSubq as it appears in JS to PhrasematchSubqObject i…
Browse files Browse the repository at this point in the history
…n tests and docs, to avoid confusion with the C++ PhrasematchSubq struct type, which has slightly different properties
  • Loading branch information
apendleton committed Mar 13, 2018
1 parent 4041a9b commit c6d30e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
12 changes: 7 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [coalesceCallback](#coalescecallback)
- [CoalesceResult](#coalesceresult)
- [coalesce](#coalesce)
- [PhrasematchSubq](#phrasematchsubq)
- [PhrasematchSubqObject](#phrasematchsubqobject)
- [MemoryCache](#memorycache)
- [list](#list)
- [set](#set)
Expand Down Expand Up @@ -38,7 +38,7 @@ Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Sta

## CoalesceResult

The a member of the result set from a coalesce operation.
A member of the result set from a coalesce operation.

**Properties**

Expand All @@ -62,16 +62,18 @@ and exposed asynchronously to JS via a callback argument.

**Parameters**

- `phrasematches` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[PhrasematchSubq](#phrasematchsubq)>** an array of PhrasematchSubq objects, each of which describes a match candidate
- `phrasematches` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[PhrasematchSubqObject](#phrasematchsubqobject)>** an array of PhrasematchSubqObject objects, each of which describes a match candidate
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** options for how to perform the coalesce operation that aren't specific to a particular subquery
- `options.radius` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** the fall-off radius for determining how wide-reaching the effect of proximity bias is
- `options.centerzxy` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** a 3-number array representing the ZXY of the tile on which the proximity point can be found
- `options.bboxzxy` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** a 5-number array representing the zoom, minX, minY, maxX, and maxY values of the tile cover of the requested bbox, if any
- `callback` **[coalesceCallback](#coalescecallback)** the callback function

## PhrasematchSubq
## PhrasematchSubqObject

The PhrasematchSubq type describes the metadata known about possible matches to be assessed for stacking by coalesce.
The PhrasematchSubqObject type describes the metadata known about possible matches to be assessed for stacking by
coalesce as seen from Javascript. Note: it is of similar purpose to the PhrasematchSubq C++ struct type, but differs
slightly in specific field names and types.

**Properties**

Expand Down
24 changes: 14 additions & 10 deletions src/coalesce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ namespace carmen {
using namespace v8;

/**
* @typedef PhrasematchSubq
* @name PhrasematchSubq
* @description The PhrasematchSubq type describes the metadata known about possible matches to be assessed for stacking by coalesce.
* The PhrasematchSubqObject type describes the metadata known about possible matches to be assessed for stacking by
* coalesce as seen from Javascript. Note: it is of similar purpose to the PhrasematchSubq C++ struct type, but differs
* slightly in specific field names and types.
*
* @typedef PhrasematchSubqObject
* @name PhrasematchSubqObject
* @type {Object}
* @property {String} phrase - The matched string
* @property {Number} weight - A float between 0 and 1 representing how much of the query this string covers
Expand All @@ -28,9 +31,10 @@ using namespace v8;
*/

/**
* A member of the result set from a coalesce operation.
*
* @typedef CoalesceResult
* @name CoalesceResult
* @description The a member of the result set from a coalesce operation.
* @type {Object}
* @property {Number} x - the X tile coordinate of the result
* @property {Number} y - the Y tile coordinate of the result
Expand All @@ -51,7 +55,7 @@ using namespace v8;
* and exposed asynchronously to JS via a callback argument.
*
* @name coalesce
* @param {PhrasematchSubq[]} phrasematches - an array of PhrasematchSubq objects, each of which describes a match candidate
* @param {PhrasematchSubqObject[]} phrasematches - an array of PhrasematchSubqObject objects, each of which describes a match candidate
* @param {Object} options - options for how to perform the coalesce operation that aren't specific to a particular subquery
* @param {Number} [options.radius] - the fall-off radius for determining how wide-reaching the effect of proximity bias is
* @param {Number[]} [options.centerzxy] - a 3-number array representing the ZXY of the tile on which the proximity point can be found
Expand All @@ -61,17 +65,17 @@ using namespace v8;
NAN_METHOD(coalesce) {
// PhrasematchStack (js => cpp)
if (info.Length() < 3) {
return Nan::ThrowTypeError("Expects 3 arguments: a PhrasematchSubq array, an option object, and a callback");
return Nan::ThrowTypeError("Expects 3 arguments: an array of PhrasematchSubqObjects, an option object, and a callback");
}

if (!info[0]->IsArray()) {
return Nan::ThrowTypeError("Arg 1 must be a PhrasematchSubq array");
return Nan::ThrowTypeError("Arg 1 must be a PhrasematchSubqObject array");
}

Local<Array> array = Local<Array>::Cast(info[0]);
auto array_length = array->Length();
if (array_length < 1) {
return Nan::ThrowTypeError("Arg 1 must be an array with one or more PhrasematchSubq objects");
return Nan::ThrowTypeError("Arg 1 must be an array with one or more PhrasematchSubqObjects");
}

// Options object (js => cpp)
Expand All @@ -98,11 +102,11 @@ NAN_METHOD(coalesce) {
for (uint32_t i = 0; i < array_length; i++) {
Local<Value> val = array->Get(i);
if (!val->IsObject()) {
return Nan::ThrowTypeError("All items in array must be valid PhrasematchSubq objects");
return Nan::ThrowTypeError("All items in array must be valid PhrasematchSubqObjects");
}
Local<Object> jsStack = val->ToObject();
if (jsStack->IsNull() || jsStack->IsUndefined()) {
return Nan::ThrowTypeError("All items in array must be valid PhrasematchSubq objects");
return Nan::ThrowTypeError("All items in array must be valid PhrasematchSubqObjects");
}

double weight;
Expand Down
8 changes: 4 additions & 4 deletions test/coalesce.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ test('coalesce args', (t) => {

t.throws(() => {
coalesce([-1], {}, () => {} );
}, /All items in array must be valid PhrasematchSubq objects/, 'throws');
}, /All items in array must be valid PhrasematchSubqObjects/, 'throws');

t.throws(() => {
coalesce(undefined, {}, () => {} );
}, /Arg 1 must be a PhrasematchSubq array/, 'throws');
}, /Arg 1 must be a PhrasematchSubqObject array/, 'throws');

t.throws(() => {
coalesce([], {}, () => {} );
}, /Arg 1 must be an array with one or more/, 'throws');

t.throws(() => {
coalesce([undefined], {}, () => {} );
}, /All items in array must be valid PhrasematchSubq objects/, 'throws');
}, /All items in array must be valid PhrasematchSubqObjects/, 'throws');

t.throws(() => {
coalesce([null], {}, () => {} );
}, /All items in array must be valid PhrasematchSubq objects/, 'throws');
}, /All items in array must be valid PhrasematchSubqObjects/, 'throws');

const valid_subq = {
cache: new MemoryCache('a'),
Expand Down

0 comments on commit c6d30e5

Please sign in to comment.