Skip to content

Commit

Permalink
Add typoTolerance + allowTyposOnNumericTokens query parameters handling
Browse files Browse the repository at this point in the history
  • Loading branch information
redox committed Jun 9, 2014
1 parent 2754c3a commit 3414a07
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/main/java/com/algolia/search/saas/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public enum QueryType
protected boolean analytics;
protected boolean synonyms;
protected boolean replaceSynonyms;
protected boolean typoTolerance;
protected boolean allowTyposOnNumericTokens;

public Query(String query) {
minWordSizeForApprox1 = 3;
Expand All @@ -75,7 +77,7 @@ public Query(String query) {
queryType = QueryType.PREFIX_LAST;
maxNumberOfFacets = -1;
advancedSyntax = false;
analytics = synonyms = replaceSynonyms = true;
analytics = synonyms = replaceSynonyms = typoTolerance = allowTyposOnNumericTokens = true;
}

public Query() {
Expand All @@ -88,7 +90,7 @@ public Query() {
queryType = QueryType.PREFIX_ALL;
maxNumberOfFacets = -1;
advancedSyntax = false;
analytics = synonyms = replaceSynonyms = true;
analytics = synonyms = replaceSynonyms = typoTolerance = allowTyposOnNumericTokens = true;
}

/**
Expand Down Expand Up @@ -173,6 +175,14 @@ public Query enableReplaceSynonymsInHighlight(boolean enabled) {
return this;
}

/**
* @param If set to false, disable typo-tolerance. Default to true.
*/
public Query enableTypoTolerance(boolean enabled) {
this.typoTolerance = enabled;
return this;
}

/**
* Specify the minimum number of characters in a query word to accept one typo in this word.
* Defaults to 3.
Expand All @@ -191,6 +201,14 @@ public Query setMinWordSizeToAllowTwoTypos(int nbChars) {
return this;
}

/**
* @param If set to false, disable typo-tolerance on numeric tokens. Default to true.
*/
public Query enableTyposOnNumericTokens(boolean enabled) {
this.allowTyposOnNumericTokens = enabled;
return this;
}

/**
* if set, the result hits will contain ranking information in _rankingInfo attribute.
*/
Expand Down Expand Up @@ -405,6 +423,16 @@ protected String getQueryString() {
first = false;
}
}
if (!typoTolerance) {
if (stringBuilder.length() > 0)
stringBuilder.append('&');
stringBuilder.append("typoTolerance=false");
}
if (!allowTyposOnNumericTokens) {
if (stringBuilder.length() > 0)
stringBuilder.append('&');
stringBuilder.append("allowTyposOnNumericTokens=false");
}
if (minWordSizeForApprox1 != 3) {
if (stringBuilder.length() > 0)
stringBuilder.append('&');
Expand Down

0 comments on commit 3414a07

Please sign in to comment.