StringBuilder buffer = new StringBuilder(); if (shouldParenthize()) { buffer.append("("); if (isFilter()) { buffer.append("|"); appendHeadingString(buffer); appendBodyString(buffer); if (shouldParenthize()) { buffer.append(")");
/** Returns a deep copy of this item */ public CompositeItem clone() { CompositeItem copy = (CompositeItem) super.clone(); copy.subitems = new java.util.ArrayList<>(); for (Item subItem : subitems) { Item subItemCopy = subItem.clone(); copy.adding(subItemCopy); copy.subitems.add(subItemCopy); } fixConnexity(copy); return copy; }
private ItemDiscloser expose(Item item) { ItemDiscloser itemDiscloser = new ItemDiscloser(item); item.disclose(itemDiscloser); return itemDiscloser; }
private void copyAttributes(Item blockAsItem, Item replacement) { copyWeight(blockAsItem, replacement); replacement.setCreator(blockAsItem.getCreator()); replacement.setRanked(blockAsItem.isRanked()); replacement.setPositionData(blockAsItem.usePositionData()); }
/** Removes an item, prefers the one at/close to the given position if there are multiple ones */ public void removeItem(int position,Item item) { Item removeCandidate=item.getParent().getItem(position); if (removeCandidate.equals(item)) // Remove based on position item.getParent().removeItem(position); else item.getParent().removeItem(item); // Otherwise, just removeField any such item }
Preconditions.checkArgument(entry.getValue() instanceof String, "Expected String annotation value, got %s.", entry.getValue().getClass()); leaf.addAnnotation((String) entry.getKey(), entry.getValue()); leaf.setFilter(filter); leaf.setRanked(isRanked); leaf.setLabel(label); leaf.setWeight(weight);
features |= FEAT_WEIGHT; if (hasUniqueID()) { features |= FEAT_UNIQUEID; byte flags = getFlagsFeature(); if (flags != 0) { features |= FEAT_FLAGS; byte type = (byte)(((getCode() & CODE_MASK) | ((features << FEAT_SHIFT) & FEAT_MASK)) & 0xff);
/** * Marks all filter terms in the given query tree as unranked. * * @param root The root of the tree to update. */ private static void updateFilterTerms(Item root) { Stack<Item> stack = new Stack<>(); stack.push(root); while (!stack.isEmpty()) { Item item = stack.pop(); if (item.getCreator() == Item.ItemCreator.FILTER) { item.setRanked(false); } if (item instanceof CompositeItem) { CompositeItem lst = (CompositeItem)item; for (Iterator<Item> it = lst.getItemIterator(); it.hasNext();) { stack.push(it.next()); } } } } }
@Override public void encodeThis(ByteBuffer target) { super.encodeThis(target); IntegerCompressor.putCompressedPositiveNumber(alternatives.size(), target); for (Alternative a : alternatives) { Item p = new PureWeightedString(a.word, (int) (getWeight() * a.exactness + 0.5)); p.setFilter(isFilter()); p.encode(target); } }
private int encodeContent(ByteBuffer buffer, int itemCount) { for (Iterator<Item> i = getItemIterator(); i.hasNext();) { Item subitem = i.next(); itemCount += subitem.encode(buffer); } return itemCount; }
@Override public Result search(Query query, Execution execution) { QueryTree tree = query.getModel().getQueryTree(); Item root = tree.getRoot(); if (root != null) { Item newRoot = root.clone(); newRoot = simplifyPhrases(newRoot); // Sets new root instead of transforming the query tree // to make code nicer if the root is a single term phrase if (!root.equals(newRoot)) { tree.setRoot(newRoot); query.trace("Collapsing single term phrases to single terms", true, 2); } } return execution.search(query); }
/** * Returns whether this item is of the same class and * contains the same state as the given item */ public boolean equals(Object object) { if (!super.equals(object)) { return false; } CompositeItem other = (CompositeItem) object; // Ensured by superclass if (!this.subitems.equals(other.subitems)) { return false; } return true; }
@Override public int encode(ByteBuffer buffer) { super.encodeThis(buffer); putString(" ", buffer); // searching for space will not match return 1; }
/** * Returns the first word item contained in the given item tree that is an instance of {@link WordItem} with the * given word value. * * @param root The root of the tree to check. * @param value The word to look for. * @return The first node found. */ private static WordItem findOrigWordItem(Item root, String value) { Stack<Item> stack = new Stack<>(); stack.push(root); while (!stack.isEmpty()) { Item item = stack.pop(); if (item.getCreator() == Item.ItemCreator.ORIG && item instanceof WordItem) { WordItem word = (WordItem)item; if (word.getWord().equals(value)) { return word; } } if (item instanceof CompositeItem) { CompositeItem lst = (CompositeItem)item; for (Iterator<Item> it = lst.getItemIterator(); it.hasNext();) { stack.push(it.next()); } } } return null; }
if (itemAnnotations != null) { itemAnnotations.traverse((ObjectTraverser) (key, value) -> { leaf.addAnnotation(key, value.asString()); }); if (FILTER.equals(annotation_name)) { if (annotation_value != null) { leaf.setFilter(annotation_value.asBool()); leaf.setRanked(annotation_value.asBool()); leaf.setLabel(annotation_value.asString()); leaf.setWeight((int)annotation_value.asDouble());
public int encode(ByteBuffer buffer) { encodeThis(buffer); int itemCount = 1; for (Iterator<Item> i = getItemIterator(); i.hasNext();) { Item subitem = i.next(); itemCount += subitem.encode(buffer); } return itemCount; }
/** * Encodes just this item, not it's usual subitems, to the given buffer. */ protected void encodeThis(ByteBuffer buffer) { super.encodeThis(buffer); IntegerCompressor.putCompressedPositiveNumber(encodingArity(), buffer); }
public int encode(ByteBuffer buffer) { if (getRoot() == null) return 0; return getRoot().encode(buffer); }
oldRoot.equals(origQueryItem)) { PhraseItem phrase = convertAndToPhrase((AndItem)oldRoot);