Java Code Examples for org.apache.lucene.index.TermsEnum#EMPTY
The following examples show how to use
org.apache.lucene.index.TermsEnum#EMPTY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompiledAutomaton.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Return a {@link TermsEnum} intersecting the provided {@link Terms} * with the terms accepted by this automaton. */ public TermsEnum getTermsEnum(Terms terms) throws IOException { switch(type) { case NONE: return TermsEnum.EMPTY; case ALL: return terms.iterator(); case SINGLE: return new SingleTermsEnum(terms.iterator(), term); case NORMAL: return terms.intersect(this, null); default: // unreachable throw new RuntimeException("unhandled case"); } }
Example 2
Source File: SimpleTextFieldsReader.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public TermsEnum iterator() throws IOException { if (fst != null) { return new SimpleTextTermsEnum(fst, fieldInfo.getIndexOptions()); } else { return TermsEnum.EMPTY; } }
Example 3
Source File: JoinDocFreqValueSource.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public FunctionValues getValues(Map<Object, Object> context, LeafReaderContext readerContext) throws IOException { final BinaryDocValues terms = DocValues.getBinary(readerContext.reader(), field); final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader(); Terms t = MultiTerms.getTerms(top, qfield); final TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.iterator(); return new IntDocValues(this) { int lastDocID = -1; @Override public int intVal(int doc) throws IOException { if (doc < lastDocID) { throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc); } lastDocID = doc; int curDocID = terms.docID(); if (doc > curDocID) { curDocID = terms.advance(doc); } if (doc == curDocID) { BytesRef term = terms.binaryValue(); if (termsEnum.seekExact(term)) { return termsEnum.docFreq(); } } return 0; } }; }
Example 4
Source File: TermsQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException { if (this.terms.size() == 0) { return TermsEnum.EMPTY; } return new SeekingTermSetTermsEnum(terms.iterator(), this.terms, ords); }
Example 5
Source File: LegacyNumericRangeQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected TermsEnum getTermsEnum(final Terms terms, AttributeSource atts) throws IOException { // very strange: java.lang.Number itself is not Comparable, but all subclasses used here are if (min != null && max != null && ((Comparable<T>) min).compareTo(max) > 0) { return TermsEnum.EMPTY; } return new NumericRangeTermsEnum(terms.iterator()); }
Example 6
Source File: GraphTermsQParserPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
private void collectTermStates(IndexReader reader, List<LeafReaderContext> leaves, TermStates[] contextArray, Term[] queryTerms) throws IOException { TermsEnum termsEnum = null; for (LeafReaderContext context : leaves) { Terms terms = context.reader().terms(this.field); if (terms == null) { // field does not exist continue; } termsEnum = terms.iterator(); if (termsEnum == TermsEnum.EMPTY) continue; for (int i = 0; i < queryTerms.length; i++) { Term term = queryTerms[i]; TermStates termStates = contextArray[i]; if (termsEnum.seekExact(term.bytes())) { if (termStates == null) { contextArray[i] = new TermStates(reader.getContext(), termsEnum.termState(), context.ord, termsEnum.docFreq(), termsEnum.totalTermFreq()); } else { termStates.register(termsEnum.termState(), context.ord, termsEnum.docFreq(), termsEnum.totalTermFreq()); } } } } }
Example 7
Source File: MtasTerms.java From mtas with Apache License 2.0 | 5 votes |
@Override public TermsEnum iterator() throws IOException { if (delegateTerms != null) { return delegateTerms.iterator(); } else { return TermsEnum.EMPTY; } }
Example 8
Source File: IGainTermsQParserPlugin.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void finish() throws IOException { NamedList<Double> analytics = new NamedList<Double>(); @SuppressWarnings({"unchecked", "rawtypes"}) NamedList<Integer> topFreq = new NamedList(); @SuppressWarnings({"unchecked", "rawtypes"}) NamedList<Integer> allFreq = new NamedList(); rb.rsp.add("featuredTerms", analytics); rb.rsp.add("docFreq", topFreq); rb.rsp.add("numDocs", count); TreeSet<TermWithScore> topTerms = new TreeSet<>(); double numDocs = count; double pc = numPositiveDocs / numDocs; double entropyC = binaryEntropy(pc); Terms terms = ((SolrIndexSearcher)searcher).getSlowAtomicReader().terms(field); TermsEnum termsEnum = terms == null ? TermsEnum.EMPTY : terms.iterator(); BytesRef term; PostingsEnum postingsEnum = null; while ((term = termsEnum.next()) != null) { postingsEnum = termsEnum.postings(postingsEnum); int xc = 0; int nc = 0; while (postingsEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { if (positiveSet.get(postingsEnum.docID())) { xc++; } else if (negativeSet.get(postingsEnum.docID())) { nc++; } } int docFreq = xc+nc; double entropyContainsTerm = binaryEntropy( (double) xc / docFreq ); double entropyNotContainsTerm = binaryEntropy( (double) (numPositiveDocs - xc) / (numDocs - docFreq + 1) ); double score = entropyC - ( (docFreq / numDocs) * entropyContainsTerm + (1.0 - docFreq / numDocs) * entropyNotContainsTerm); topFreq.add(term.utf8ToString(), docFreq); if (topTerms.size() < numTerms) { topTerms.add(new TermWithScore(term.utf8ToString(), score)); } else { if (topTerms.first().score < score) { topTerms.pollFirst(); topTerms.add(new TermWithScore(term.utf8ToString(), score)); } } } for (TermWithScore topTerm : topTerms) { analytics.add(topTerm.term, topTerm.score); topFreq.add(topTerm.term, allFreq.get(topTerm.term)); } if (this.delegate instanceof DelegatingCollector) { ((DelegatingCollector) this.delegate).finish(); } }
Example 9
Source File: TestLegacyTerms.java From lucene-solr with Apache License 2.0 | votes |
public TermsEnum iterator() { return TermsEnum.EMPTY; }