Skip to content

Commit

Permalink
Add advancedSyntax query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
redox committed Mar 28, 2014
1 parent b679dcb commit f747f77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ You can use the following optional arguments:
* **setOptionalWords**: a string that contains the list of words that should be considered as optional when found in the query. The list of words is comma separated.
* **setMinWordSizeToAllowOneTypo**: the minimum number of characters in a query word to accept one typo in this word.<br/>Defaults to 3.
* **setMinWordSizeToAllowTwoTypos**: the minimum number of characters in a query word to accept two typos in this word.<br/>Defaults to 7.
* **setAdvancedSyntax**: Enable the advanced query syntax. Defaults to 0 (false).
* **Phrase query**: a phrase query defines a particular sequence of terms. A phrase query is build by Algolia's query parser for words surrounded by `"`. For example, `"search engine"` will retrieve records having `search` next to `engine` only. Typo-tolerance is _disabled_ on phrase queries.
* **Prohibit operator**: The prohibit operator excludes records that contain the term after the `-` symbol. For example `search -engine` will retrieve records containing `search` but not `engine`.

#### Pagination parameters

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/algolia/search/saas/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public enum QueryType
protected int minWordSizeForApprox2;
protected boolean getRankingInfo;
protected boolean distinct;
protected boolean advancedSyntax;
protected int page;
protected int hitsPerPage;
protected String tags;
Expand All @@ -70,6 +71,7 @@ public Query(String query) {
this.query = query;
queryType = QueryType.PREFIX_LAST;
maxNumberOfFacets = -1;
advancedSyntax = false;
}

public Query() {
Expand All @@ -81,6 +83,7 @@ public Query() {
hitsPerPage = 20;
queryType = QueryType.PREFIX_ALL;
maxNumberOfFacets = -1;
advancedSyntax = false;
}

/**
Expand Down Expand Up @@ -321,6 +324,20 @@ public Query setNumericFilters(List<String> numerics) {
return this;
}

/**
* Enable the advanced query syntax. Defaults to false.
* - Phrase query: a phrase query defines a particular sequence of terms.
* A phrase query is build by Algolia's query parser for words surrounded by ".
* For example, "search engine" will retrieve records having search next to engine only.
* Typo-tolerance is disabled on phrase queries.
* - Prohibit operator: The prohibit operator excludes records that contain the term after the - symbol.
* For example search -engine will retrieve records containing search but not engine.
*/
public Query setAvancedSyntax(boolean advancedSyntax) {
this.advancedSyntax = advancedSyntax;
return this;
}

protected String getQueryString() {
StringBuilder stringBuilder = new StringBuilder();

Expand Down Expand Up @@ -381,6 +398,11 @@ protected String getQueryString() {
stringBuilder.append('&');
stringBuilder.append("distinct=1");
}
if (advancedSyntax) {
if (stringBuilder.length() > 0)
stringBuilder.append('&');
stringBuilder.append("advancedSyntax=1");
}
if (page > 0) {
if (stringBuilder.length() > 0)
stringBuilder.append('&');
Expand Down

0 comments on commit f747f77

Please sign in to comment.