Skip to content

Commit

Permalink
Fix bug when combining filters
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHarbo authored and tokee committed Aug 9, 2023
1 parent 0bea2c4 commit 529d2cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ public static String fieldValueToString(Object value) {
*/
public static String combineFilterQueries(String predefinedFilterField, String predefinedFilterValue, String[] filterQueries) {
Stream<String> filtersStream = Stream.of(filterQueries);
Stream<String> fullFiltersStream =Stream.concat(Stream.of(predefinedFilterField + ":(" + predefinedFilterValue + ")"), filtersStream);
Stream<String> fullFiltersStream =Stream.concat(Stream.of(predefinedFilterField + ":" + predefinedFilterValue), filtersStream);
return fullFiltersStream
.collect(Collectors.joining(" AND ", "(", ")"));
.collect(Collectors.joining(") AND (", "(", ")"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class SolrUtilsTest {

@Test
public void combineFilterQueriesTest(){
String[] filtersFromFrontend = new String[]{"filter1:value1", "filter2:value2"};
String[] filtersFromFrontend = new String[]{"filter1:value1", "filter2:value2", "foo:bar OR bar:zoo"};
String filterquery = SolrUtils.combineFilterQueries("content_type", "text/html", filtersFromFrontend);

System.out.println(filterquery);
assertEquals("(content_type:text/html) AND (filter1:value1) AND (filter2:value2) AND (foo:bar OR bar:zoo)", filterquery);
}
}

0 comments on commit 529d2cb

Please sign in to comment.