/** * Adds a term to the end of the query phrase. The relative position of the * term is the one immediately after the last term added. */ public void add(final Term term) { int position = 0; if (positions.size() > 0) { position = (positions.get(positions.size() - 1)).intValue() + 1; } this.add(term, position); }
@Override public boolean equals(final Object o) { if (!(o instanceof NodePhraseQuery)) { return false; } final NodePhraseQuery other = (NodePhraseQuery) o; return (this.getBoost() == other.getBoost()) && this.terms.equals(other.terms) && this.positions.equals(other.positions) && this.levelConstraint == other.levelConstraint && this.lowerBound == other.lowerBound && this.upperBound == other.upperBound && StringUtils.equals(this.datatype, other.datatype); }
@Override public NodeQueryBuilder setDatatype(final String datatype) { npq.setDatatype(datatype); return this; }
private NodePhraseQueryBuilder(final String fieldName, final String[] terms) { npq = new NodePhraseQuery(); for (int i = 0; i < terms.length; i++) { if (terms[i].isEmpty()) { // if empty string, skip it continue; } final Term t = new Term(fieldName, terms[i]); npq.add(t, i); } }
this.escapeDoubleQuote(buffer, s); buffer.append(ToStringUtils.boost(this.getBoost())); return this.wrapToStringWithDatatype(buffer).toString();
final DocsNodesAndPositionsEnum postingsEnum = NodePhraseQuery.this.getDocsNodesAndPositionsEnum(te.docsAndPositions(liveDocs, null));
public NodePhraseQuery build(final QueryNode queryNode) throws QueryNodeException { final TokenizedPhraseQueryNode phraseNode = (TokenizedPhraseQueryNode) queryNode; final NodePhraseQuery phraseQuery = new NodePhraseQuery(); final List<QueryNode> children = phraseNode.getChildren(); if (children != null) { for (final QueryNode child : children) { final NodeTermQuery termQuery = (NodeTermQuery) child .getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); final FieldQueryNode termNode = (FieldQueryNode) child; phraseQuery.add(termQuery.getTerm(), termNode.getPositionIncrement()); } } return phraseQuery; }
@Override public int hashCode() { return Float.floatToIntBits(this.getBoost()) ^ terms.hashCode() ^ positions.hashCode() ^ levelConstraint ^ upperBound ^ lowerBound; }
@Override public Query rewrite(final IndexReader reader) throws IOException { if (terms.isEmpty()) { final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.setBoost(this.getBoost()); return bq; } else if (terms.size() == 1) { final NodeTermQuery tq = new NodeTermQuery(terms.get(0)); tq.setBoost(this.getBoost()); return tq; } else { return super.rewrite(reader); } }
public NodePhraseWeight(final IndexSearcher searcher) throws IOException { this.similarity = searcher.getSimilarity(); final IndexReaderContext context = searcher.getTopReaderContext(); states = new TermContext[terms.size()]; final TermStatistics termStats[] = new TermStatistics[terms.size()]; for (int i = 0; i < terms.size(); i++) { final Term term = terms.get(i); states[i] = TermContext.build(context, term, true); termStats[i] = searcher.termStatistics(term, states[i]); } stats = similarity.computeWeight(NodePhraseQuery.this.getBoost(), searcher.collectionStatistics(field), termStats); }