@Test public void testNormalizeSearchTerms() { assertTrue(Arrays.equals(searchTerms(""), normalizedSearchTerms(""))); assertTrue(Arrays.equals(searchTerms("x"), normalizedSearchTerms("x"))); assertTrue(Arrays.equals(searchTerms("x Y z"), normalizedSearchTerms("x Y z"))); assertTrue(Arrays.equals(searchTerms("xyz"), normalizedSearchTerms("x xy xyz"))); assertTrue(Arrays.equals(searchTerms("xyz"), normalizedSearchTerms("xyz xy x"))); assertTrue(Arrays.equals(searchTerms("xyz"), normalizedSearchTerms("xy xyz x"))); assertTrue(Arrays.equals(searchTerms("xyz"), normalizedSearchTerms("xyz xyz xyz"))); assertTrue(Arrays.equals(searchTerms("blackened"), normalizedSearchTerms("black blackened"))); assertTrue(Arrays.equals(searchTerms("this"), normalizedSearchTerms("this his"))); assertTrue(Arrays.equals(searchTerms("blackened this"), normalizedSearchTerms("blackened this"))); assertTrue(Arrays.equals(searchTerms("blackened this"), normalizedSearchTerms("this blackened"))); }
private static List<SearchTerm> normalizeSearchTerms(List<SearchTerm> searchTerms, boolean negated) { List<SearchTerm> result = new ArrayList<>(searchTerms); for(Iterator<SearchTerm> i = result.iterator(); i.hasNext();) { SearchTerm searchTerm = i.next(); if(searchTerm == null || searchTerm.getText().length() == 0) i.remove(); } for(int i = 0; i < result.size(); i++) { SearchTerm termI = result.get(i); for(int j = 0; j < result.size(); j++) { SearchTerm termJ = result.get(j); if(i != j && termJ.getText().indexOf(termI.getText()) != -1) { if(negated) { if(termJ.isRequired()) continue; result.remove(j); } else { if(termI.isRequired()) continue; result.remove(i); break; } } } } Collections.sort(result, negated ? GlazedLists.reverseComparator(SEARCHTERM_LENGTH_COMPARATOR) : SEARCHTERM_LENGTH_COMPARATOR); return result; }
TextMatchers { private static List<SearchTerm> normalizeSearchTerms(List<SearchTerm> searchTerms, boolean negated) { List<SearchTerm> result = new ArrayList<>(searchTerms); for(Iterator<SearchTerm> i = result.iterator(); i.hasNext();) { SearchTerm searchTerm = i.next(); if(searchTerm == null || searchTerm.getText().length() == 0) i.remove(); } for(int i = 0; i < result.size(); i++) { SearchTerm termI = result.get(i); for(int j = 0; j < result.size(); j++) { SearchTerm termJ = result.get(j); if(i != j && termJ.getText().indexOf(termI.getText()) != -1) { if(negated) { if(termJ.isRequired()) continue; result.remove(j); } else { if(termI.isRequired()) continue; result.remove(i); break; } } } } Collections.sort(result, negated ? GlazedLists.reverseComparator(SEARCHTERM_LENGTH_COMPARATOR) : SEARCHTERM_LENGTH_COMPARATOR); return result; } }
TextMatchers { private static List<SearchTerm> normalizeSearchTerms(List<SearchTerm> searchTerms, boolean negated) { List<SearchTerm> result = new ArrayList<>(searchTerms); for(Iterator<SearchTerm> i = result.iterator(); i.hasNext();) { SearchTerm searchTerm = i.next(); if(searchTerm == null || searchTerm.getText().length() == 0) i.remove(); } for(int i = 0; i < result.size(); i++) { SearchTerm termI = result.get(i); for(int j = 0; j < result.size(); j++) { SearchTerm termJ = result.get(j); if(i != j && termJ.getText().indexOf(termI.getText()) != -1) { if(negated) { if(termJ.isRequired()) continue; result.remove(j); } else { if(termI.isRequired()) continue; result.remove(i); break; } } } } Collections.sort(result, negated ? GlazedLists.reverseComparator(SEARCHTERM_LENGTH_COMPARATOR) : SEARCHTERM_LENGTH_COMPARATOR); return result; }  }
TextMatchers { private static List<SearchTerm> normalizeSearchTerms(List<SearchTerm> searchTerms, boolean negated) { List<SearchTerm> result = new ArrayList<>(searchTerms); for(Iterator<SearchTerm> i = result.iterator(); i.hasNext();) { SearchTerm searchTerm = i.next(); if(searchTerm == null || searchTerm.getText().length() == 0) i.remove(); } for(int i = 0; i < result.size(); i++) { SearchTerm termI = result.get(i); for(int j = 0; j < result.size(); j++) { SearchTerm termJ = result.get(j); if(i != j && termJ.getText().indexOf(termI.getText()) != -1) { if(negated) { if(termJ.isRequired()) continue; result.remove(j); } else { if(termI.isRequired()) continue; result.remove(i); break; } } } } Collections.sort(result, negated ? GlazedLists.reverseComparator(SEARCHTERM_LENGTH_COMPARATOR) : SEARCHTERM_LENGTH_COMPARATOR); return result; }  static boolean matches(List<String> filterStrings, TextFilterator<? super E> filterator, SearchTerm<E>[] searchTerms, TextSearchStrategy[] filterStrategies, E element); static SearchTerm[] normalizeSearchTerms(SearchTerm[] filters, TextSearchStrategy.Factory strategy); static SearchTerm<E>[] parse(String text); static SearchTerm<E>[] parse(String text, Set<SearchEngineTextMatcherEditor.Field<E>> fields); static boolean isMatcherConstrained(TextMatcher oldMatcher, TextMatcher newMatcher); static boolean isMatcherRelaxed(TextMatcher oldMatcher, TextMatcher newMatcher); }
TextMatchers { private static List<SearchTerm> normalizeSearchTerms(List<SearchTerm> searchTerms, boolean negated) { List<SearchTerm> result = new ArrayList<>(searchTerms); for(Iterator<SearchTerm> i = result.iterator(); i.hasNext();) { SearchTerm searchTerm = i.next(); if(searchTerm == null || searchTerm.getText().length() == 0) i.remove(); } for(int i = 0; i < result.size(); i++) { SearchTerm termI = result.get(i); for(int j = 0; j < result.size(); j++) { SearchTerm termJ = result.get(j); if(i != j && termJ.getText().indexOf(termI.getText()) != -1) { if(negated) { if(termJ.isRequired()) continue; result.remove(j); } else { if(termI.isRequired()) continue; result.remove(i); break; } } } } Collections.sort(result, negated ? GlazedLists.reverseComparator(SEARCHTERM_LENGTH_COMPARATOR) : SEARCHTERM_LENGTH_COMPARATOR); return result; }  static boolean matches(List<String> filterStrings, TextFilterator<? super E> filterator, SearchTerm<E>[] searchTerms, TextSearchStrategy[] filterStrategies, E element); static SearchTerm[] normalizeSearchTerms(SearchTerm[] filters, TextSearchStrategy.Factory strategy); static SearchTerm<E>[] parse(String text); static SearchTerm<E>[] parse(String text, Set<SearchEngineTextMatcherEditor.Field<E>> fields); static boolean isMatcherConstrained(TextMatcher oldMatcher, TextMatcher newMatcher); static boolean isMatcherRelaxed(TextMatcher oldMatcher, TextMatcher newMatcher);  }