private CompositeItem populate(CompositeItem parent, String fieldName, Map<String,Integer> tokens) { for (Map.Entry<String,Integer> entry : tokens.entrySet()) { WordItem wordItem = new WordItem(entry.getKey(), fieldName); wordItem.setWeight(entry.getValue()); wordItem.setStemmed(true); wordItem.setNormalizable(false); parent.addItem(wordItem); } return parent; }
@Override public void disclose(Discloser discloser) { super.disclose(discloser); discloser.addProperty("index", indexName); for (Map.Entry<Object, Integer> entry : set.entrySet()) { WordItem subitem = new WordItem(entry.getKey().toString(), indexName); subitem.setWeight(entry.getValue()); discloser.addChild(subitem); } }
private static Item collapsePhrase(PhraseItem phrase) { if (phrase.getItemCount() == 1 && phrase.getItem(0) instanceof WordItem) { // TODO: Other stuff which needs propagation? WordItem word = (WordItem) phrase.getItem(0); word.setWeight(phrase.getWeight()); return word; } else { return phrase; } }
public AndSegmentItem(PhraseSegmentItem item) { super(item.getRawWord(), item.stringValue(), item.isFromQuery(), item.isStemmed(), null); int weight = item.getWeight(); if (item.getItemCount() > 0) { for (Iterator<Item> i = item.getItemIterator(); i.hasNext();) { WordItem word = (WordItem) i.next(); word.setWeight(weight); addItem(word); } } }
/** * Splits the given item into n-grams and adds them as a CompositeItem containing WordItems searching the * index of the input term. If the result is a single gram, that single WordItem is returned rather than the AndItem * * @param term the term to split, must be an item which implement the IndexedItem and BlockItem "mixins" * @param text the text of the item, just stringValue() if the item is a TermItem * @param gramSize the gram size to split to * @param query the query in which this rewriting is done * @return the root of the query subtree produced by this, containing the split items */ protected Item splitToGrams(Item term, String text, int gramSize, Query query) { String index = ((HasIndexItem)term).getIndexName(); CompositeItem gramsItem = createGramRoot(query); gramsItem.setIndexName(index); Substring origin = ((BlockItem)term).getOrigin(); for (Iterator<GramSplitter.Gram> i = getGramSplitter().split(text,gramSize); i.hasNext(); ) { GramSplitter.Gram gram = i.next(); WordItem gramWord = new WordItem(gram.extractFrom(text), index, false, origin); gramWord.setWeight(term.getWeight()); gramWord.setProtected(true); gramsItem.addItem(gramWord); } return gramsItem.getItemCount()==1 ? gramsItem.getItem(0) : gramsItem; // return the AndItem, or just the single gram if not multiple }
public void produce(RuleEvaluation e,int offset) { WordItem newItem=new WordItem(literal,getLabel()); if (replacing) { Match matched=e.getNonreferencedMatch(0); insertMatch(e,matched,newItem,offset); } else { newItem.setWeight(getWeight()); if (e.getTraceLevel()>=6) e.trace(6,"Adding '" + newItem + "'"); e.addItem(newItem,getTermType()); } }