Codota Logo
QueryTree.setRoot
Code IndexAdd Codota to your IDE (free)

How to use
setRoot
method
in
com.yahoo.search.query.QueryTree

Best Java code snippets using com.yahoo.search.query.QueryTree.setRoot (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
SimpleDateFormat s =
  • Codota IconString pattern;new SimpleDateFormat(pattern)
  • Codota IconString template;Locale locale;new SimpleDateFormat(template, locale)
  • Codota Iconnew SimpleDateFormat()
  • Smart code suggestions by Codota
}
origin: com.yahoo.vespa/container-search

public QueryTree(Item root) {
  setRoot(root);
}
origin: com.yahoo.vespa/container-search

static public void andQueryItemWithRoot(QueryTree tree, Item item) {
  if (tree.isEmpty()) {
    tree.setRoot(item);
  } else {
    Item oldRoot = tree.getRoot();
    if (oldRoot.getClass() == AndItem.class) {
      ((AndItem) oldRoot).addItem(item);
    } else {
      AndItem newRoot = new AndItem();
      newRoot.addItem(oldRoot);
      newRoot.addItem(item);
      tree.setRoot(newRoot);
    }
  }
}
origin: com.yahoo.vespa/container-search

private Query normalizeBody(Query query, IndexFacts.Session indexFacts) {
  Item root = query.getModel().getQueryTree().getRoot();
  Language language = query.getModel().getParsingLanguage();
  if (root instanceof BlockItem) {
    List<Item> rootItems = new ArrayList<>(1);
    rootItems.add(root);
    ListIterator<Item> i = rootItems.listIterator();
    i.next();
    normalizeBlocks(language, indexFacts, (BlockItem) root, i);
    if ( ! rootItems.isEmpty()) // give up normalizing if the root was removed
      query.getModel().getQueryTree().setRoot(rootItems.get(0));
  } else if (root instanceof CompositeItem) {
    query.getModel().getQueryTree().setRoot(normalizeComposite(language, indexFacts, (CompositeItem) root));
  }
  return query;
}

origin: com.yahoo.vespa/container-search

/** Adds an item to the query being evaluated in a way consistent with the query type */
// TODO: Add this functionality to Query?
public void addItem(Item item, TermType termType) {
  Item root= query.getModel().getQueryTree().getRoot();
  if (root==null)
    query.getModel().getQueryTree().setRoot(item);
  else
    query.getModel().getQueryTree().setRoot(combineItems(root,item,termType));
}
origin: com.yahoo.vespa/container-search

private void insertMutableInTree(CompositeItem mutable, CompositeItem original, CompositeItem parent) {
  if (parent == null) {
    query.getModel().getQueryTree().setRoot(mutable);
  } else {
    int parentsIndex = parent.getItemIndex(original);
    parent.setItem(parentsIndex, mutable);
  }
}
origin: com.yahoo.vespa/container-search

/** Modifies this query to become the current query AND the given item */
// TODO: Make sure this is complete, unit test and make it public
private void and(Item item) {
  if (isEmpty()) {
    setRoot(item);
  }
  else if (getRoot() instanceof NotItem && item instanceof NotItem) {
    throw new IllegalArgumentException("Can't AND two NOTs"); // TODO: Complete
  }
  else if (getRoot() instanceof NotItem){
    NotItem notItem = (NotItem)getRoot();
    notItem.addPositiveItem(item);
  }
  else if (item instanceof NotItem){
    NotItem notItem = (NotItem)item;
    notItem.addPositiveItem(getRoot());
    setRoot(notItem);
  }
  else {
    AndItem andItem = new AndItem();
    andItem.addItem(getRoot());
    andItem.addItem(item);
    setRoot(andItem);
  }
}
origin: vespa-engine/sample-apps

private void addAndItem(QueryTree q, String term) {
  Item root = q.getRoot();
  CompositeItem compositeRoot;
  if (root instanceof AndItem) {
    compositeRoot = (CompositeItem) root;
  } else {
    compositeRoot = new AndItem();
    compositeRoot.addItem(root);
    q.setRoot(compositeRoot);
  }
  compositeRoot.addItem(new WordItem(term));
}
origin: com.yahoo.vespa/container-search

/**
 * Optimizes the given query tree based on its {@link Model#getRestrict()} parameter, if any.
 */
public static void optimizeByRestrict(Query query) {
  if (query.getModel().getRestrict().size() != 1) {
    return;
  }
  Item root = query.getModel().getQueryTree().getRoot();
  if (optimizeByRestrict(root, query.getModel().getRestrict().iterator().next()) == Recall.RECALLS_NOTHING) {
    query.getModel().getQueryTree().setRoot(new NullItem());
  }
}
origin: com.yahoo.vespa/container-search

/**
 * Collapses all single-child {@link CompositeItem}s into their parent item.
 */
public static void collapseSingleComposites(Query query) {
  Item oldRoot = query.getModel().getQueryTree().getRoot();
  Item newRoot = collapseSingleComposites(oldRoot);
  if (oldRoot != newRoot) {
    query.getModel().getQueryTree().setRoot(newRoot);
  }
}
origin: com.yahoo.vespa/container-search

/**
 * Replaces and {@link SimpleIndexedItem} searching in the {@link Hit#SDDOCNAME_FIELD} with an item
 * appropriate for the search node.
 */
public static void rewriteSddocname(Query query) {
  Item oldRoot = query.getModel().getQueryTree().getRoot();
  Item newRoot = rewriteSddocname(oldRoot);
  if (oldRoot != newRoot) {
    query.getModel().getQueryTree().setRoot(newRoot);
  }
}
origin: com.yahoo.vespa/container-search

/**
 * Optimize multiple NotItems under and or by collapsing them in to one and leaving
 * the positive ones behind in its place and moving itself with the original and as its positive item
 * and the union of all the negative items of all the original NotItems as its negative items.
 */
public static void optimizeAndNot(Query query) {
  Item root = query.getModel().getQueryTree().getRoot();
  Item possibleNewRoot = optimizeAndNot(root);
  if (root != possibleNewRoot) {
    query.getModel().getQueryTree().setRoot(possibleNewRoot);
  }
}
origin: com.yahoo.vespa/container-search

/**
 * Adds a RankItem at the root of a query, but only if there is
 * at least one rank term in the specified RankItem.
 * If the root is already a RankItem, just append the new rank terms.
 *
 * @param rankTerms the new rank item to add.
 * @param query the query to add to
 */
private void addTopLevelRankTerms(RankItem rankTerms, Query query) {
  Item root = query.getModel().getQueryTree().getRoot();
  if (root instanceof RankItem) {
    for (Iterator<Item> i = rankTerms.getItemIterator(); i.hasNext(); ) {
      ((RankItem)root).addItem(i.next());
    }
  }
  else {
    rankTerms.addItem(0, root);
    query.getModel().getQueryTree().setRoot(rankTerms);
  }
}
origin: vespa-engine/sample-apps

private Hit retrieveUserProfile(String userId, Execution execution) {
  Query query = new Query();
  query.getModel().setRestrict("user");
  query.getModel().getQueryTree().setRoot(new WordItem(userId, "user_id"));
  query.setHits(1);
  SearchChain vespaChain = execution.searchChainRegistry().getComponent("vespa");
  Result result = new Execution(vespaChain, execution.context()).search(query);
  execution.fill(result); // This is needed to get the actual summary data
  Iterator<Hit> hiterator = result.hits().deepIterator();
  return hiterator.hasNext() ? hiterator.next() : null;
}
origin: com.yahoo.vespa/container-search

@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);
}
origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  Language language = query.getModel().getParsingLanguage();
  if ( ! language.isCjk()) return execution.search(query);
  QueryTree tree = query.getModel().getQueryTree();
  tree.setRoot(transform(tree.getRoot()));
  query.trace("Rewriting for CJK behavior for implicit phrases", true, 2);
  return execution.search(query);
}
origin: com.yahoo.vespa/container-search

/**
 * Inserts an item to the query being evaluated in a way consistent with the query type
 *
 * @param item the item to insert
 * @param parent the parent of this item, or null to set the root
 * @param index the index at which to insert this into the parent
 * @param desiredParentType the desired type of the composite which contains item when this returns
 */
public void insertItem(Item item, CompositeItem parent, int index, TermType desiredParentType) {
  if (parent==null) { // TODO: Accommodate for termtype in this case too
    query.getModel().getQueryTree().setRoot(item);
    return;
  }
  if (parent.getItemCount()>0 && parent instanceof QueryTree && parent.getItem(0) instanceof CompositeItem) {
    // combine with the existing root instead
    parent=(CompositeItem)parent.getItem(0);
    if (index==1) { // that means adding it after the existing root
      index=parent.getItemCount();
    }
  }
  if (( desiredParentType==TermType.DEFAULT || desiredParentType.hasItemClass(parent.getClass()) )
     && equalIndexNameIfParentIsPhrase(item,parent)) {
    addItem(parent,index,item,desiredParentType);
  }
  else {
    insertIncompatibleItem(item,parent,query,desiredParentType);
  }
}
origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  if (query.properties().getBoolean(DISABLE)) return execution.search(query);
  IndexFacts.Session indexFacts = execution.context().getIndexFacts().newSession(query);
  Item newRoot = replaceTerms(query, indexFacts);
  query.getModel().getQueryTree().setRoot(newRoot);
  query.trace(getFunctionName(), true, 2);
  Highlight highlight = query.getPresentation().getHighlight();
  if (highlight != null) {
    Set<String> highlightFields = highlight.getHighlightItems().keySet();
    for (String field : highlightFields) {
      StemMode stemMode = indexFacts.getIndex(field).getStemMode();
      if (stemMode != StemMode.NONE) {
        StemContext context = new StemContext();
        context.language = Language.ENGLISH;
        context.indexFacts = indexFacts;
        Item newHighlight = scan(highlight.getHighlightItems().get(field), context);
        highlight.getHighlightItems().put(field, (AndItem)newHighlight);
      }
    }
  }
  return execution.search(query);
}
origin: com.yahoo.vespa/container-search

private void insertIncompatibleItem(Item item,CompositeItem parent,Query query,TermType desiredParentType) {
  // Create new parent
  CompositeItem newParent;
  if (desiredParentType==TermType.DEFAULT)
    newParent=new AndItem();
  else
    newParent=(CompositeItem)desiredParentType.createItemClass();
  // Save previous parent parent
  CompositeItem parentsParent=parent.getParent();
  // Add items to new parent
  newParent.addItem(parent);
  newParent.addItem(item);
  // Insert new parent as root or child of old parents parent
  if (parentsParent==null) {
    query.getModel().getQueryTree().setRoot(newParent);
  }
  else {
    int parentIndex=0;
    if (parentsParent!=null) {
      parentIndex=parentsParent.getItemIndex(parent);
    }
    parentsParent.setItem(parentIndex,newParent);
  }
}
origin: com.yahoo.vespa/container-search

  qTree.setRoot(phrase);
} else {
  OrItem newRoot = new OrItem();
  newRoot.addItem(oldRoot);
  newRoot.addItem(phrase);
  qTree.setRoot(newRoot);
origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  String recall = query.properties().getString(recallName);
  if (recall == null) return execution.search(query);
  AnyParser parser = new AnyParser(ParserEnvironment.fromExecutionContext(execution.context()));
  QueryTree root = parser.parse(Parsable.fromQueryModel(query.getModel()).setQuery("foo").setFilter(recall));
  String err;
  if (root.getRoot() instanceof NullItem) {
    err = "Failed to parse recall parameter.";
  } else if (!(root.getRoot() instanceof CompositeItem)) {
    err = "Expected CompositeItem root node, got " + root.getClass().getSimpleName() + ".";
  } else if (hasRankItem(root.getRoot())) {
    query.getModel().getQueryTree().setRoot(root.getRoot());
    err = "Recall contains at least one rank item.";
  } else {
    WordItem placeholder = findOrigWordItem(root.getRoot(), "foo");
    if (placeholder == null) {
      err = "Could not find placeholder workQuery root.";
    } else {
      updateFilterTerms(root);
      CompositeItem parent = placeholder.getParent();
      parent.setItem(parent.getItemIndex(placeholder), query.getModel().getQueryTree().getRoot());
      query.getModel().getQueryTree().setRoot(root.getRoot());
      query.trace("ANDed recall tree with root workQuery node.", true, 3);
      return execution.search(query);
    }
  }
  return new Result(query, ErrorMessage.createInvalidQueryParameter(err));
}
com.yahoo.search.queryQueryTreesetRoot

Popular methods of QueryTree

  • getRoot
    Returns the query root. This is null if this is a null query.
  • <init>
  • clone
    Returns a deep copy of this
  • encode
  • fixClonedConnectivityReferences
  • getItem
  • getItemCount
  • getItemIterator
  • getPositiveTerms
  • isEmpty
    Returns true if this represents the null query
  • setItem
  • toString
  • setItem,
  • toString

Popular in Java

  • Creating JSON documents from java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getContentResolver (Context)
  • orElseThrow (Optional)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Vector (java.util)
    The Vector class implements a growable array of objects. Like an array, it contains components that
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now