public int hashCode() { return 17*item.getIndexedString().hashCode()+ 33*item.getIndexName().hashCode(); }
@Override protected void appendBodyString(StringBuilder buffer) { buffer.append(fieldName).append(':'); buffer.append('{'); for (Iterator<Item> i = getItemIterator(); i.hasNext();) { TermItem term = (TermItem) i.next(); buffer.append(term.getIndexName()).append(':').append(term.getIndexedString()); if (i.hasNext()) { buffer.append(' '); } } buffer.append('}'); }
private String matchTerms(int numberOfTerms,RuleEvaluation e) { StringBuilder b=new StringBuilder(); for (int i=0; i<numberOfTerms; i++) { e.addMatch(e.currentItem(),e.currentItem().getItem().getIndexedString()); b.append(e.currentItem().getItem().stringValue()); if (i<(numberOfTerms-1)) b.append(" "); e.next(); } return b.toString(); }
private void repeatedTermsInPhraseCheck(PhraseItem phrase) { if (phrase.getItemCount() > MAX_REPEATED_TERMS_IN_PHRASE) { Map<String, Count> repeatedCount = new HashMap<>(); for (int i = 0; i < phrase.getItemCount(); ++i) { Item item = phrase.getItem(i); if (item instanceof TermItem) { TermItem term = (TermItem) item; String current = term.getIndexedString(); Count count = repeatedCount.get(current); if (count != null) { if (count.get() >= MAX_REPEATED_TERMS_IN_PHRASE) { repeatedTermsInPhraseRejections.add(); throw new IllegalArgumentException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE + " occurrences of term '" + current + "' in phrase : " + phrase.toString()); } count.inc(); } else { repeatedCount.put(current, new Count(1)); } } } } }
/** * Creates a match * * @param item the match to add * @param replaceValue the string to replace this match by, usually the item.getIndexedString() * which is what the replace value will be if it is passed as null here */ public Match(FlattenedItem item,String replaceValue) { this.item=item.getItem(); if (replaceValue==null) this.replaceValue=item.getItem().getIndexedString(); else this.replaceValue=replaceValue; this.parent=this.item.getParent(); this.position=item.getPosition(); }
private void repeatedConsecutiveTermsInPhraseCheck(PhraseItem phrase) { if (phrase.getItemCount() > MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) { String prev = null; int repeatedCount = 0; for (int i = 0; i < phrase.getItemCount(); ++i) { Item item = phrase.getItem(i); if (item instanceof TermItem) { TermItem term = (TermItem) item; String current = term.getIndexedString(); if (prev != null) { if (prev.equals(current)) { repeatedCount++; if (repeatedCount >= MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) { repeatedConsecutiveTermsInPhraseRejections.add(); throw new IllegalArgumentException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE + " ocurrences of term '" + current + "' in a row detected in phrase : " + phrase.toString()); } } else { repeatedCount = 0; } } prev = current; } else { prev = null; repeatedCount = 0; } } } } private static final class Count {
@Override protected void adding(Item item) { super.adding(item); Validator.ensureInstanceOf("Child item", item, TermItem.class); TermItem asTerm = (TermItem) item; Validator.ensureNonEmpty("Struct fieldname", asTerm.getIndexName()); Validator.ensureNonEmpty("Query term", asTerm.getIndexedString()); }