From 529d2cb15eaef19ab46d2b3aa56a471d666ae36d Mon Sep 17 00:00:00 2001 From: Victor Harbo Johnston Date: Wed, 9 Aug 2023 07:52:40 +0200 Subject: [PATCH] Fix bug when combining filters --- .../dk/kb/netarchivesuite/solrwayback/util/SolrUtils.java | 4 ++-- .../kb/netarchivesuite/solrwayback/util/SolrUtilsTest.java | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtils.java b/src/main/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtils.java index 6b253cfe..f8a357a2 100644 --- a/src/main/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtils.java +++ b/src/main/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtils.java @@ -430,8 +430,8 @@ public static String fieldValueToString(Object value) { */ public static String combineFilterQueries(String predefinedFilterField, String predefinedFilterValue, String[] filterQueries) { Stream filtersStream = Stream.of(filterQueries); - Stream fullFiltersStream =Stream.concat(Stream.of(predefinedFilterField + ":(" + predefinedFilterValue + ")"), filtersStream); + Stream fullFiltersStream =Stream.concat(Stream.of(predefinedFilterField + ":" + predefinedFilterValue), filtersStream); return fullFiltersStream - .collect(Collectors.joining(" AND ", "(", ")")); + .collect(Collectors.joining(") AND (", "(", ")")); } } diff --git a/src/test/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtilsTest.java b/src/test/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtilsTest.java index ddc16f82..3c7e41ac 100644 --- a/src/test/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtilsTest.java +++ b/src/test/java/dk/kb/netarchivesuite/solrwayback/util/SolrUtilsTest.java @@ -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); } }