@Override protected String decorate(String text, MatchAlgorithmReference matchAlgorithm) { if (matchAlgorithm .getContent() .equals( StandardMatchAlgorithmReference.CONTAINS .getMatchAlgorithmReference() .getContent())) { text = QueryParser.escape(text); StringBuilder sb = new StringBuilder(); sb.append("("); for (String token : text.split("\\s+")) { sb.append("description:"); sb.append(token); sb.append("* "); } sb.append(")"); sb.append(" OR description:\"" + text + "\""); sb.append(" OR exactDescription:\"" + QueryParser.escape(text) + "\""); return sb.toString().trim(); } else if (matchAlgorithm .getContent() .equals( StandardMatchAlgorithmReference.EXACT_MATCH .getMatchAlgorithmReference() .getContent())) { return "exactDescription:\"" + QueryParser.escape(text) + "\""; } else if (matchAlgorithm.getContent().equals(LUCENE_QUERY)) { return text; } else { throw new IllegalStateException(); } }
@Override public Set<? extends MatchAlgorithmReference> getSupportedMatchAlgorithms() { Set<MatchAlgorithmReference> returnSet = new HashSet<MatchAlgorithmReference>(); returnSet.add(StandardMatchAlgorithmReference.CONTAINS.getMatchAlgorithmReference()); returnSet.add(StandardMatchAlgorithmReference.EXACT_MATCH.getMatchAlgorithmReference()); return returnSet; }
@Override public Set<MatchAlgorithmReference> getSupportedMatchAlgorithms() { Set<MatchAlgorithmReference> returnSet = new HashSet<MatchAlgorithmReference>(); MatchAlgorithmReference lucene = new MatchAlgorithmReference(); lucene.setContent(LUCENE_QUERY); returnSet.addAll( Arrays.asList( lucene, StandardMatchAlgorithmReference.CONTAINS.getMatchAlgorithmReference(), StandardMatchAlgorithmReference.EXACT_MATCH.getMatchAlgorithmReference())); return returnSet; }