2
2
3
3
import android .util .Pair ;
4
4
5
+ import org .json .JSONArray ;
6
+
5
7
import java .io .UnsupportedEncodingException ;
6
8
import java .net .URLEncoder ;
7
9
import java .util .ArrayList ;
10
+ import java .util .Arrays ;
8
11
import java .util .List ;
9
12
10
- import org .json .JSONArray ;
11
-
12
13
/*
13
14
* Copyright (c) 2015 Algolia
14
15
* http://www.algolia.com/
15
- *
16
+ *
16
17
* Permission is hereby granted, free of charge, to any person obtaining a copy
17
18
* of this software and associated documentation files (the "Software"), to deal
18
19
* in the Software without restriction, including without limitation the rights
19
20
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
21
* copies of the Software, and to permit persons to whom the Software is
21
22
* furnished to do so, subject to the following conditions:
22
- *
23
+ *
23
24
* The above copyright notice and this permission notice shall be included in
24
25
* all copies or substantial portions of the Software.
25
- *
26
+ *
26
27
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
28
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
29
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -248,31 +249,67 @@ public Query setSimilarQueryString(String query) {
248
249
/**
249
250
* Specify the list of attribute names to retrieve. By default all
250
251
* attributes are retrieved.
252
+ * @deprecated use {@code setAttributesToRetrieve(String... attributes)}
251
253
*/
254
+ @ Deprecated
252
255
public Query setAttributesToRetrieve (List <String > attributes ) {
253
256
this .attributes = attributes ;
254
257
return this ;
255
258
}
256
259
260
+ /**
261
+ * Specify the list of attribute names to retrieve. By default all
262
+ * attributes are retrieved.
263
+ *
264
+ */
265
+ public Query setAttributesToRetrieve (String ... attributes ) {
266
+ this .attributes = Arrays .asList (attributes );
267
+ return this ;
268
+ }
269
+
257
270
/**
258
271
* Specify the list of attribute names to highlight. By default indexed
259
272
* attributes are highlighted.
273
+ * @deprecated use {@link #setAttributesToHighlight(String...)}
260
274
*/
275
+ @ Deprecated
261
276
public Query setAttributesToHighlight (List <String > attributes ) {
262
277
this .attributesToHighlight = attributes ;
263
278
return this ;
264
279
}
265
280
281
+
282
+ /**
283
+ * Specify the list of attribute names to highlight. By default indexed
284
+ * attributes are highlighted.
285
+ */
286
+ public Query setAttributesToHighlight (String ... attributes ) {
287
+ this .attributesToHighlight = Arrays .asList (attributes );
288
+ return this ;
289
+ }
290
+
266
291
/**
267
292
* Specify the list of attribute names to Snippet alongside the number of
268
293
* words to return (syntax is 'attributeName:nbWords'). By default no
269
294
* snippet is computed.
295
+ * @deprecated use {@link #setFacets(String...)}
270
296
*/
297
+ @ Deprecated
271
298
public Query setAttributesToSnippet (List <String > attributes ) {
272
299
this .attributesToSnippet = attributes ;
273
300
return this ;
274
301
}
275
302
303
+ /**
304
+ * Specify the list of attribute names to Snippet alongside the number of
305
+ * words to return (syntax is 'attributeName:nbWords'). By default no
306
+ * snippet is computed.
307
+ */
308
+ public Query setAttributesToSnippet (String ... attributes ) {
309
+ this .attributesToSnippet = Arrays .asList (attributes );
310
+ return this ;
311
+ }
312
+
276
313
/**
277
314
*
278
315
* @param distinct
@@ -490,7 +527,7 @@ public Query setAroundPrecision(int precision) {
490
527
/**
491
528
* Set the number of hits per page. Defaults to 10.
492
529
*
493
- * @deprecated Use {@code setHitsPerPage}
530
+ * @deprecated Use {@link # setHitsPerPage(int) }
494
531
*/
495
532
@ Deprecated
496
533
public Query setNbHitsPerPage (int nbHitsPerPage ) {
@@ -642,7 +679,9 @@ public Query setOptionalWords(String words) {
642
679
*
643
680
* @param words
644
681
* The list of optional words.
682
+ * @deprecated use {@link #setOptionalWords(String...)}
645
683
*/
684
+ @ Deprecated
646
685
public Query setOptionalWords (List <String > words ) {
647
686
StringBuilder builder = new StringBuilder ();
648
687
for (String word : words ) {
@@ -653,6 +692,23 @@ public Query setOptionalWords(List<String> words) {
653
692
return this ;
654
693
}
655
694
695
+ /**
696
+ * Set the list of words that should be considered as optional when found in
697
+ * the query.
698
+ *
699
+ * @param words
700
+ * The list of optional words.
701
+ */
702
+ public Query setOptionalWords (String ... words ) {
703
+ StringBuilder builder = new StringBuilder ();
704
+ for (String word : words ) {
705
+ builder .append (word );
706
+ builder .append ("," );
707
+ }
708
+ this .optionalWords = builder .toString ();
709
+ return this ;
710
+ }
711
+
656
712
/**
657
713
* Filter the query with numeric, facet or/and tag filters.
658
714
* The syntax is a SQL like syntax, you can use the OR and AND keywords.
@@ -673,7 +729,9 @@ public Query setFilters(String filters) {
673
729
/**
674
730
* Filter the query by a list of facets. Each filter is encoded as
675
731
* `attributeName:value`.
732
+ * @deprecated use {@link #setFacetFilters(String...)}
676
733
*/
734
+ @ Deprecated
677
735
public Query setFacetFilters (List <String > facets ) {
678
736
JSONArray obj = new JSONArray ();
679
737
for (String facet : facets ) {
@@ -683,6 +741,19 @@ public Query setFacetFilters(List<String> facets) {
683
741
return this ;
684
742
}
685
743
744
+ /**
745
+ * Filter the query by a list of facets. Each filter is encoded as
746
+ * `attributeName:value`.
747
+ */
748
+ public Query setFacetFilters (String ... facets ) {
749
+ JSONArray obj = new JSONArray ();
750
+ for (String facet : facets ) {
751
+ obj .put (facet );
752
+ }
753
+ this .facetFilters = obj .toString ();
754
+ return this ;
755
+ }
756
+
686
757
/**
687
758
* Filter the query by a list of facets. Filters are separated by commas and
688
759
* each facet is encoded as `attributeName:value`. To OR facets, you must
@@ -701,7 +772,9 @@ public Query setFacetFilters(String facetFilters) {
701
772
* Only attributes that have been added in **attributesForFaceting** index
702
773
* setting can be used in this parameter. You can also use `*` to perform
703
774
* faceting on all attributes specified in **attributesForFaceting**.
775
+ * @deprecated use {@link #setFacets(String...)}
704
776
*/
777
+ @ Deprecated
705
778
public Query setFacets (List <String > facets ) {
706
779
JSONArray obj = new JSONArray ();
707
780
for (String facet : facets ) {
@@ -711,6 +784,21 @@ public Query setFacets(List<String> facets) {
711
784
return this ;
712
785
}
713
786
787
+ /**
788
+ * List of object attributes that you want to use for faceting.
789
+ * Only attributes that have been added in **attributesForFaceting** index
790
+ * setting can be used in this parameter. You can also use `*` to perform
791
+ * faceting on all attributes specified in **attributesForFaceting**.
792
+ */
793
+ public Query setFacets (String ... facets ) {
794
+ JSONArray obj = new JSONArray ();
795
+ for (String facet : facets ) {
796
+ obj .put (facet );
797
+ }
798
+ this .facets = obj .toString ();
799
+ return this ;
800
+ }
801
+
714
802
/**
715
803
* Limit the number of facet values returned for each facet.
716
804
*/
@@ -749,7 +837,9 @@ public Query setNumericFilters(String numerics) {
749
837
* Supported operands are `<`, `<=`, `=`, `>` and `<=`. You can have
750
838
* multiple conditions on one attribute like for example
751
839
* `numerics=price>100,price<1000`.
840
+ * @deprecated use {@link #setNumericFilters(String...)}
752
841
*/
842
+ @ Deprecated
753
843
public Query setNumericFilters (List <String > numerics ) {
754
844
StringBuilder builder = new StringBuilder ();
755
845
boolean first = true ;
@@ -763,6 +853,26 @@ public Query setNumericFilters(List<String> numerics) {
763
853
return this ;
764
854
}
765
855
856
+ /**
857
+ * Add a list of numeric filters separated by a comma. The syntax of one
858
+ * filter is `attributeName` followed by `operand` followed by `value.
859
+ * Supported operands are `<`, `<=`, `=`, `>` and `<=`. You can have
860
+ * multiple conditions on one attribute like for example
861
+ * `numerics=price>100,price<1000`.
862
+ */
863
+ public Query setNumericFilters (String ... numerics ) {
864
+ StringBuilder builder = new StringBuilder ();
865
+ boolean first = true ;
866
+ for (String n : numerics ) {
867
+ if (!first )
868
+ builder .append ("," );
869
+ builder .append (n );
870
+ first = false ;
871
+ }
872
+ this .numerics = builder .toString ();
873
+ return this ;
874
+ }
875
+
766
876
/**
767
877
* Enable the advanced query syntax. Defaults to false. - Phrase query: a
768
878
* phrase query defines a particular sequence of terms. A phrase query is
0 commit comments