Package org.apache.lucene.index

Examples of org.apache.lucene.index.TermDocs


         */
        private void collectTermDocs(IndexReader reader,
                                     Term start,
                                     TermDocsCollector collector)
                throws IOException {
            TermDocs tDocs = reader.termDocs();
            try {
                TermEnum terms = reader.terms(start);
                try {
                    int count = 0;
                    do {
                        Term t = terms.term();
                        if (t != null && t.field() == start.field()) {
                            tDocs.seek(terms);
                            if (!collector.collect(t, tDocs)) {
                                // collector indicated break
                                break;
                            }
                        } else {
                            break;
                        }
                        // once in a while check if we should quit
                        if (++count % 10000 == 0) {
                            if (stopRequested) {
                                break;
                            }
                        }
                    } while (terms.next());
                } finally {
                    terms.close();
                }
            } finally {
                tDocs.close();
            }
        }
View Full Code Here


            Set<Integer> sortedDocs = new TreeSet<Integer>();
            try {
                while ((node = hits.nextScoreNode()) != null) {
                    String uuid = node.getNodeId().toString();
                    Term id = TermFactory.createUUIDTerm(uuid);
                    TermDocs tDocs = reader.termDocs(id);
                    try {
                        if (tDocs.next()) {
                            Integer doc = tDocs.doc();
                            sortedDocs.add(doc);
                            scores.put(doc, node.getScore());
                        }
                    } finally {
                        tDocs.close();
                    }
                }
            } finally {
                hits.close();
            }
View Full Code Here

                return;
            }
            TermEnum terms = new WildcardTermEnum(reader, field, tvf, pattern, transform);
            try {
                // use unpositioned TermDocs
                TermDocs docs = reader.termDocs();
                try {
                    while (terms.term() != null) {
                        docs.seek(terms);
                        while (docs.next()) {
                            hits.set(docs.doc());
                        }
                        if (!terms.next()) {
                            break;
                        }
                    }
                } finally {
                    docs.close();
                }
            } finally {
                terms.close();
            }
            hitsCalculated = true;
View Full Code Here

            }

            for (Term startTerm : startTerms) {
                TermEnum terms = reader.terms(startTerm);
                try {
                    TermDocs docs = reader.termDocs();
                    try {
                        do {
                            Term term = terms.term();
                            if (term != null && term.field() == testField && term.text().startsWith(namePrefix)) {
                                if (checkLower) {
                                    int compare = termCompare(term.text(), lowerTerm.text(), propNameLength);
                                    if (compare > 0 || compare == 0 && inclusive) {
                                        // do not check lower term anymore if no
                                        // transformation is done on the term enum
                                        checkLower = transform != TRANSFORM_NONE;
                                    } else {
                                        // continue with next term
                                        continue;
                                    }
                                }
                                if (upperTerm != null) {
                                    int compare = termCompare(term.text(), upperTerm.text(), propNameLength);
                                    // if beyond the upper term, or is exclusive and
                                    // this is equal to the upper term
                                    if ((compare > 0) || (!inclusive && compare == 0)) {
                                        // only break out if no transformation
                                        // was done on the term from the enum
                                        if (transform == TRANSFORM_NONE) {
                                            break;
                                        } else {
                                            // because of the transformation
                                            // it is possible that the next
                                            // term will be included again if
                                            // we still enumerate on the same
                                            // property name
                                            if (term.text().startsWith(namePrefix)) {
                                                continue;
                                            } else {
                                                break;
                                            }
                                        }
                                    }
                                }

                                docs.seek(terms);
                                while (docs.next()) {
                                    hits.set(docs.doc());
                                }
                            } else {
                                break;
                            }
                        } while (terms.next());
                    } finally {
                        docs.close();
                    }
                } finally {
                    terms.close();
                }
            }
View Full Code Here

        docFilter = new BitSet(reader.maxDoc());
        // we match all terms
        String namedValue = FieldNames.createNamedValue(field, "");
        TermEnum terms = reader.terms(new Term(FieldNames.PROPERTIES, namedValue));
        try {
            TermDocs docs = reader.termDocs();
            try {
                while (terms.term() != null
                        && terms.term().field() == FieldNames.PROPERTIES
                        && terms.term().text().startsWith(namedValue)) {
                    docs.seek(terms);
                    while (docs.next()) {
                        docFilter.set(docs.doc());
                    }
                    terms.next();
                }
            } finally {
                docs.close();
            }
        } finally {
            terms.close();
        }
View Full Code Here

            throws IOException {
        IndexReader reader = index.getIndexReader();
        try {
            checkRewritten(reader);
            Term idTerm = TermFactory.createUUIDTerm(id.toString());
            TermDocs tDocs = reader.termDocs(idTerm);
            int docNumber;
            Document doc;
            try {
                if (tDocs.next()) {
                    docNumber = tDocs.doc();
                    doc = reader.document(docNumber);
                } else {
                    // node not found in index
                    return null;
                }
            } finally {
                tDocs.close();
            }
            Fieldable[] fields = doc.getFieldables(FieldNames.FULLTEXT);
            if (fields.length == 0) {
                log.debug("Fulltext field not stored, using {}",
                        SimpleExcerptProvider.class.getName());
View Full Code Here

            }

            // if we get here, entry is either invalid or did not exist
            // search through readers
            for (int i = 0; i < subReaders.length; i++) {
                TermDocs docs = subReaders[i].termDocs(term);
                try {
                    if (docs.next()) {
                        return new SingleTermDocs(docs.doc() + starts[i]);
                    }
                } finally {
                    docs.close();
                }
            }
        }

        return super.termDocs(term);
View Full Code Here

    public ForeignSegmentDocId createDocId(NodeId id) throws IOException {
        Term term = TermFactory.createUUIDTerm(id.toString());
        int doc;
        long tick;
        for (ReadOnlyIndexReader subReader : subReaders) {
            TermDocs docs = subReader.termDocs(term);
            try {
                if (docs.next()) {
                    doc = docs.doc();
                    tick = subReader.getCreationTick();
                    return new ForeignSegmentDocId(doc, tick);
                }
            } finally {
                docs.close();
            }
        }
        return null;
    }
View Full Code Here

                // collect the doc ids of all target nodes. we reuse the existing
                // bitset.
                hits.clear();
                for (String uuid : uuids) {
                    TermDocs node = reader.termDocs(TermFactory.createUUIDTerm(uuid));
                    try {
                        while (node.next()) {
                            hits.set(node.doc());
                        }
                    } finally {
                        node.close();
                    }
                }
                // filter out the target nodes that do not match the name test
                // if there is any name test at all.
                if (nameTestScorer != null) {
View Full Code Here

     * @return TermDocs for <code>term</code>.
     * @throws IOException if an error occurs while reading from the index.
     */
    public TermDocs termDocs(Term term) throws IOException {
        // do not wrap for empty TermDocs
        TermDocs td = reader.termDocs(term);
        if (td != EmptyTermDocs.INSTANCE) {
            td = new FilteredTermDocs(td);
        }
        return td;
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.TermDocs

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.