Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 96e7b3d

Browse files
authored
Added fuzziness (#20)
1 parent 78fd5bb commit 96e7b3d

File tree

10 files changed

+148
-7
lines changed

10 files changed

+148
-7
lines changed

dist/apisearch.js

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Query/Query.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export declare class Query {
3232
private highlightsEnabled;
3333
private filterFields;
3434
private scoreStrategy;
35+
private fuzziness;
3536
private user;
3637
/**
3738
* Constructor
@@ -460,6 +461,26 @@ export declare class Query {
460461
* @param scoreStrategy
461462
*/
462463
setScoreStrategy(scoreStrategy: ScoreStrategy): Query;
464+
/**
465+
* Get fuzziness
466+
*
467+
* @return any
468+
*/
469+
getFuzziness(): any;
470+
/**
471+
* Set fuzziness
472+
*
473+
* @param fuzziness
474+
*
475+
* @return {Query}
476+
*/
477+
setFuzziness(fuzziness: any): Query;
478+
/**
479+
* Set auto fuzziness
480+
*
481+
* @return {Query}
482+
*/
483+
setAutoFuzziness(): Query;
463484
/**
464485
* By user
465486
*

lib/Query/Query.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,34 @@ var Query = /** @class */ (function () {
739739
this.scoreStrategy = scoreStrategy;
740740
return this;
741741
};
742+
/**
743+
* Get fuzziness
744+
*
745+
* @return any
746+
*/
747+
Query.prototype.getFuzziness = function () {
748+
return this.fuzziness;
749+
};
750+
/**
751+
* Set fuzziness
752+
*
753+
* @param fuzziness
754+
*
755+
* @return {Query}
756+
*/
757+
Query.prototype.setFuzziness = function (fuzziness) {
758+
this.fuzziness = fuzziness;
759+
return this;
760+
};
761+
/**
762+
* Set auto fuzziness
763+
*
764+
* @return {Query}
765+
*/
766+
Query.prototype.setAutoFuzziness = function () {
767+
this.fuzziness = 'AUTO';
768+
return this;
769+
};
742770
/**
743771
* By user
744772
*
@@ -866,6 +894,9 @@ var Query = /** @class */ (function () {
866894
array.score_strategy = scoreStrategyAsArray;
867895
}
868896
}
897+
if (this.fuzziness !== null) {
898+
array.fuzziness = this.fuzziness;
899+
}
869900
/**
870901
* User
871902
*/
@@ -950,6 +981,7 @@ var Query = /** @class */ (function () {
950981
query.highlightsEnabled = typeof array.highlights_enabled === "boolean"
951982
? array.highlights_enabled
952983
: false;
984+
query.fuzziness = array.fuzziness;
953985
/**
954986
* Items promoted
955987
*/

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apisearch",
3-
"version": "0.2.10",
3+
"version": "0.2.11",
44
"description": "Javascript client for Apisearch.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/Query/Query.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class Query {
5252
private highlightsEnabled: boolean;
5353
private filterFields: string[] = [];
5454
private scoreStrategy: ScoreStrategy;
55+
private fuzziness: any;
5556
private user: User;
5657

5758
/**
@@ -1011,6 +1012,39 @@ export class Query {
10111012
return this;
10121013
}
10131014

1015+
/**
1016+
* Get fuzziness
1017+
*
1018+
* @return any
1019+
*/
1020+
public getFuzziness():any {
1021+
return this.fuzziness;
1022+
}
1023+
1024+
/**
1025+
* Set fuzziness
1026+
*
1027+
* @param fuzziness
1028+
*
1029+
* @return {Query}
1030+
*/
1031+
public setFuzziness(fuzziness) : Query {
1032+
this.fuzziness = fuzziness;
1033+
1034+
return this;
1035+
}
1036+
1037+
/**
1038+
* Set auto fuzziness
1039+
*
1040+
* @return {Query}
1041+
*/
1042+
public setAutoFuzziness() : Query {
1043+
this.fuzziness = 'AUTO';
1044+
1045+
return this;
1046+
}
1047+
10141048
/**
10151049
* By user
10161050
*
@@ -1164,6 +1198,10 @@ export class Query {
11641198
}
11651199
}
11661200

1201+
if (this.fuzziness !== null) {
1202+
array.fuzziness = this.fuzziness;
1203+
}
1204+
11671205
/**
11681206
* User
11691207
*/
@@ -1273,6 +1311,8 @@ export class Query {
12731311
? array.highlights_enabled
12741312
: false;
12751313

1314+
query.fuzziness = array.fuzziness;
1315+
12761316
/**
12771317
* Items promoted
12781318
*/

test/Query/Query.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,20 @@ describe('Query()', () => {
440440
expect(query.getUser()).to.be.equal(null);
441441
});
442442
});
443+
444+
describe('-> Test fuzziness', () => {
445+
it('should work properly', () => {
446+
let query = Query.createMatchAll();
447+
expect(query.getFuzziness()).to.be.undefined;
448+
expect(query.toArray().fuzziness).to.be.undefined;
449+
query.setFuzziness(1.0);
450+
expect(query.getFuzziness()).to.be.equals(1.0);
451+
expect(query.toArray().fuzziness).to.be.equals(1.0);
452+
expect(Query.createFromArray({fuzziness: 1.0}).getFuzziness()).to.be.equals(1.0);
453+
expect(Query.createFromArray({}).getFuzziness()).to.be.undefined;
454+
expect(query.setFuzziness('1..3')).to.be.instanceOf(Query);
455+
expect(Query.createMatchAll().setAutoFuzziness().getFuzziness()).to.be.equals('AUTO');
456+
expect(query.setAutoFuzziness()).to.be.instanceOf(Query);
457+
});
458+
})
443459
});

0 commit comments

Comments
 (0)