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,8 +679,22 @@ 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 ) {
686
+ setOptionalWords (words .toArray (new String [words .size ()]));
687
+ return this ;
688
+ }
689
+
690
+ /**
691
+ * Set the list of words that should be considered as optional when found in
692
+ * the query.
693
+ *
694
+ * @param words
695
+ * The list of optional words.
696
+ */
697
+ public Query setOptionalWords (String ... words ) {
647
698
StringBuilder builder = new StringBuilder ();
648
699
for (String word : words ) {
649
700
builder .append (word );
@@ -673,8 +724,19 @@ public Query setFilters(String filters) {
673
724
/**
674
725
* Filter the query by a list of facets. Each filter is encoded as
675
726
* `attributeName:value`.
727
+ * @deprecated use {@link #setFacetFilters(String...)}
676
728
*/
729
+ @ Deprecated
677
730
public Query setFacetFilters (List <String > facets ) {
731
+ setFacetFilters (facets .toArray (new String [facets .size ()]));
732
+ return this ;
733
+ }
734
+
735
+ /**
736
+ * Filter the query by a list of facets. Each filter is encoded as
737
+ * `attributeName:value`.
738
+ */
739
+ public Query setFacetFilters (String ... facets ) {
678
740
JSONArray obj = new JSONArray ();
679
741
for (String facet : facets ) {
680
742
obj .put (facet );
@@ -701,8 +763,21 @@ public Query setFacetFilters(String facetFilters) {
701
763
* Only attributes that have been added in **attributesForFaceting** index
702
764
* setting can be used in this parameter. You can also use `*` to perform
703
765
* faceting on all attributes specified in **attributesForFaceting**.
766
+ * @deprecated use {@link #setFacets(String...)}
704
767
*/
768
+ @ Deprecated
705
769
public Query setFacets (List <String > facets ) {
770
+ setFacets (facets .toArray (new String [facets .size ()]));
771
+ return this ;
772
+ }
773
+
774
+ /**
775
+ * List of object attributes that you want to use for faceting.
776
+ * Only attributes that have been added in **attributesForFaceting** index
777
+ * setting can be used in this parameter. You can also use `*` to perform
778
+ * faceting on all attributes specified in **attributesForFaceting**.
779
+ */
780
+ public Query setFacets (String ... facets ) {
706
781
JSONArray obj = new JSONArray ();
707
782
for (String facet : facets ) {
708
783
obj .put (facet );
@@ -749,8 +824,22 @@ public Query setNumericFilters(String numerics) {
749
824
* Supported operands are `<`, `<=`, `=`, `>` and `<=`. You can have
750
825
* multiple conditions on one attribute like for example
751
826
* `numerics=price>100,price<1000`.
827
+ * @deprecated use {@link #setNumericFilters(String...)}
752
828
*/
829
+ @ Deprecated
753
830
public Query setNumericFilters (List <String > numerics ) {
831
+ setNumericFilters (numerics .toArray (new String [numerics .size ()]));
832
+ return this ;
833
+ }
834
+
835
+ /**
836
+ * Add a list of numeric filters separated by a comma. The syntax of one
837
+ * filter is `attributeName` followed by `operand` followed by `value.
838
+ * Supported operands are `<`, `<=`, `=`, `>` and `<=`. You can have
839
+ * multiple conditions on one attribute like for example
840
+ * `numerics=price>100,price<1000`.
841
+ */
842
+ public Query setNumericFilters (String ... numerics ) {
754
843
StringBuilder builder = new StringBuilder ();
755
844
boolean first = true ;
756
845
for (String n : numerics ) {
0 commit comments