/** * Removes the numeric refinement relative to an attribute and operator for the next queries. * * @param attribute an attribute that maybe has some refinements. * @param operator an {@link NumericRefinement#OPERATOR_EQ operator}. * @return this {@link Searcher} for chaining. */ @SuppressWarnings({"WeakerAccess", "unused"}) // For library users public Searcher removeNumericRefinement(@NonNull String attribute, @NonNull Integer operator) { return removeNumericRefinement(new NumericRefinement(attribute, operator, NumericRefinement.VALUE_UNKNOWN)); }
/** * Removes any numeric refinements relative to a specific attribute for the next queries. * * @param attribute the attribute that may have a refinement. * @return this {@link Searcher} for chaining. */ @SuppressWarnings({"WeakerAccess", "unused"}) // For library users public Searcher removeNumericRefinement(@NonNull String attribute) { return removeNumericRefinement(new NumericRefinement(attribute, NumericRefinement.OPERATOR_UNKNOWN, NumericRefinement.VALUE_UNKNOWN)); }
private void onUpdate(final SeekBar seekBar) { int newProgressValue = seekBar.getProgress(); // avoid double search on ProgressChanged + StopTrackingTouch if (newProgressValue != lastProgressValue[0]) { final double actualValue = updateSeekBarText(tv, seekBar, name, minValue, maxValue, steps); if (newProgressValue == 0) { searcher.removeNumericRefinement(new NumericRefinement(attribute, NumericRefinement.OPERATOR_GT, actualValue)) .search(); } else { searcher.addNumericRefinement(new NumericRefinement(attribute, NumericRefinement.OPERATOR_GT, actualValue)) .search(); } } lastProgressValue[0] = newProgressValue; } });
final double actualValue = updateSeekBarText(tv, seekBar, name, minValue, maxValue, steps); if (newProgressValue == 0) { searcher.removeNumericRefinement(new NumericRefinement(attribute, NumericRefinement.OPERATOR_GT, actualValue)) .search(); } else { searcher.addNumericRefinement(new NumericRefinement(attribute, NumericRefinement.OPERATOR_GT, actualValue)) .search(); updateSeekBarText(tv, currentFilter != null ? currentFilter : new NumericRefinement(name, NumericRefinement.OPERATOR_GT, minValue), name, minValue); filterViews.put(description.position, seekBarLayout);
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { final Double selectedValue = values.get(position); if (currentRefinement != null) { searcher.removeNumericRefinement(currentRefinement); } if (selectedValue != null) { // don't refine if user selected the default value currentRefinement = new NumericRefinement(attribute, operator, selectedValue); searcher.addNumericRefinement(currentRefinement); } searcher.search(); //TODO: Conditional if refineNow (window) or not (dialog) }
private void updateRefinement(String attribute, int operator) { if (currentRefinement != null) { searcher.removeNumericRefinement(currentRefinement); currentRefinement = new NumericRefinement(attribute, operator, currentRefinement.value); searcher.addNumericRefinement(currentRefinement); searcher.search(); } }
@Test public void numericRefinements() { Searcher searcher = initSearcher(); final NumericRefinement r = new NumericRefinement("attribute", NumericRefinement.OPERATOR_EQ, 42); final NumericRefinement r2 = new NumericRefinement("attribute", NumericRefinement.OPERATOR_NE, 42); final String formattedValue = String.format(Locale.US, "%f", 42f); searcher.addNumericRefinement(r); Assert.assertEquals("There should be a numeric refinement for attribute", r, searcher.getNumericRefinement(r.attribute, r.operator)); Assert.assertEquals("Query numericFilters should represent the refinement", "[\"attribute=" + formattedValue + "\"]", searcher.getQuery().getNumericFilters().toString()); searcher.removeNumericRefinement(r); Assert.assertEquals("This numeric refinement should have been removed.", null, searcher.getNumericRefinement(r.attribute, r.operator)); Assert.assertEquals("Query numericFilters should be empty after removal", "[]", searcher.getQuery().getNumericFilters().toString()); searcher.addNumericRefinement(r); searcher.addNumericRefinement(r2); Assert.assertEquals("Query numericFilters should represent both refinements", "[\"attribute=" + formattedValue + "\",\"attribute!=" + formattedValue + "\"]", searcher.getQuery().getNumericFilters().toString()); searcher.removeNumericRefinement(r.attribute); Assert.assertEquals("Both numeric refinements for this attribute should have been removed", null, searcher.getNumericRefinement(r.attribute, r.operator)); Assert.assertEquals("Query numericFilters should be empty after removal", "[]", searcher.getQuery().getNumericFilters().toString()); searcher.addNumericRefinement(r); searcher.addNumericRefinement(r2); searcher.removeNumericRefinement(r.attribute, r.operator); Assert.assertEquals("The numeric refinement for this attribute/operator pair should have been removed", null, searcher.getNumericRefinement(r.attribute, r.operator)); Assert.assertEquals("The numeric refinement for this attribute but other operator should have been kept", r2, searcher.getNumericRefinement(r2.attribute, r2.operator)); }