Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions dist/apisearch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/apisearch.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apisearch.min.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions dist/apisearch.min.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
2 changes: 1 addition & 1 deletion dist/apisearch.min.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions lib/Query/Query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export declare class Query {
private aggregationsEnabled;
private numberOfSuggestions;
private highlightsEnabled;
private autocompleteEnabled;
private searchableFields;
private scoreStrategies;
private fuzziness;
Expand Down Expand Up @@ -423,6 +424,24 @@ export declare class Query {
* @return {number}
*/
getNumberOfSuggestions(): number;
/**
* Enable autocomplete
*
* @return {Query}
*/
enableAutocomplete(): Query;
/**
* Disable autocomplete
*
* @return {Query}
*/
disableAutocomplete(): Query;
/**
* Are autocomplete enabled
*
* @return {boolean}
*/
areAutocompleteEnabled(): boolean;
/**
* Enable highlights
*
Expand Down
33 changes: 33 additions & 0 deletions lib/Query/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var Query = /** @class */ (function () {
this.aggregationsEnabled = true;
this.numberOfSuggestions = 0;
this.highlightsEnabled = false;
this.autocompleteEnabled = false;
this.searchableFields = [];
this.minScore = exports.NO_MIN_SCORE;
this.metadata = {};
Expand Down Expand Up @@ -676,6 +677,32 @@ var Query = /** @class */ (function () {
Query.prototype.getNumberOfSuggestions = function () {
return this.numberOfSuggestions;
};
/**
* Enable autocomplete
*
* @return {Query}
*/
Query.prototype.enableAutocomplete = function () {
this.autocompleteEnabled = true;
return this;
};
/**
* Disable autocomplete
*
* @return {Query}
*/
Query.prototype.disableAutocomplete = function () {
this.autocompleteEnabled = false;
return this;
};
/**
* Are autocomplete enabled
*
* @return {boolean}
*/
Query.prototype.areAutocompleteEnabled = function () {
return this.autocompleteEnabled;
};
/**
* Enable highlights
*
Expand Down Expand Up @@ -1017,6 +1044,9 @@ var Query = /** @class */ (function () {
if (this.resultsEnabled === false) {
array.results_enabled = false;
}
if (this.autocompleteEnabled === true) {
array.autocomplete_enabled = true;
}
if (this.numberOfSuggestions !== 0) {
array.number_of_suggestions = this.numberOfSuggestions;
}
Expand Down Expand Up @@ -1148,6 +1178,9 @@ var Query = /** @class */ (function () {
query.numberOfSuggestions = typeof array.number_of_suggestions === "number"
? array.number_of_suggestions
: 0;
query.autocompleteEnabled = typeof array.autocomplete_enabled === "boolean"
? array.autocomplete_enabled
: false;
query.aggregationsEnabled = typeof array.aggregations_enabled === "boolean"
? array.aggregations_enabled
: true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apisearch",
"version": "0.3.0",
"version": "0.3.1",
"description": "Javascript client for Apisearch.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
40 changes: 40 additions & 0 deletions src/Query/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class Query {
private aggregationsEnabled: boolean = true;
private numberOfSuggestions: number = 0;
private highlightsEnabled: boolean = false;
private autocompleteEnabled: boolean = false;
private searchableFields: string[] = [];
private scoreStrategies: ScoreStrategies;
private fuzziness: any;
Expand Down Expand Up @@ -935,6 +936,37 @@ export class Query {
return this.numberOfSuggestions;
}

/**
* Enable autocomplete
*
* @return {Query}
*/
public enableAutocomplete(): Query {
this.autocompleteEnabled = true;

return this;
}

/**
* Disable autocomplete
*
* @return {Query}
*/
public disableAutocomplete(): Query {
this.autocompleteEnabled = false;

return this;
}

/**
* Are autocomplete enabled
*
* @return {boolean}
*/
public areAutocompleteEnabled(): boolean {
return this.autocompleteEnabled;
}

/**
* Enable highlights
*
Expand Down Expand Up @@ -1347,6 +1379,10 @@ export class Query {
array.results_enabled = false;
}

if (this.autocompleteEnabled === true) {
array.autocomplete_enabled = true;
}

if (this.numberOfSuggestions !== 0) {
array.number_of_suggestions = this.numberOfSuggestions;
}
Expand Down Expand Up @@ -1517,6 +1553,10 @@ export class Query {
? array.number_of_suggestions
: 0;

query.autocompleteEnabled = typeof array.autocomplete_enabled === "boolean"
? array.autocomplete_enabled
: false;

query.aggregationsEnabled = typeof array.aggregations_enabled === "boolean"
? array.aggregations_enabled
: true;
Expand Down
8 changes: 8 additions & 0 deletions test/Query/Query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,14 @@ describe('Query()', () => {
query.disableHighlights();
expect(query.toArray().highlight_enabled).to.be.undefined;
});

it('should set and unset autocomplete properly', () => {
query.enableAutocomplete();
expect(query.areAutocompleteEnabled()).to.be.true;
expect(query.toArray().autocomplete_enabled).to.be.true;
query.disableAutocomplete();
expect(query.toArray().autocomplete_enabled).to.be.undefined;
});
});

describe('-> When setting/unsetting a User on query', () => {
Expand Down