HerdSearchQueryHelper { public List<String> extractNegationTerms(final IndexSearchRequest indexSearchRequest) { final Matcher regexMatcher = getNegationTermMatcher(indexSearchRequest); final List<String> negationTerms = new ArrayList<>(); while (regexMatcher.find()) { negationTerms.add(regexMatcher.group().replaceAll("-", "").trim()); } return negationTerms; }  boolean determineNegationTermsPresent(final IndexSearchRequest indexSearchRequest); List<String> extractNegationTerms(final IndexSearchRequest indexSearchRequest); String extractSearchPhrase(final IndexSearchRequest indexSearchRequest);  }
@Test public void extractNegationTerms() throws Exception { IndexSearchRequest indexSearchRequest = new IndexSearchRequest(); indexSearchRequest.setSearchTerm("foo -foo bar -bar foobar"); Assert.assertEquals(Arrays.asList("foo", "bar"), herdSearchQueryHelper.extractNegationTerms(indexSearchRequest)); indexSearchRequest.setSearchTerm("foo -foo bar -bar foobar"); Assert.assertEquals(Arrays.asList("foo", "bar"), herdSearchQueryHelper.extractNegationTerms(indexSearchRequest)); }