Search in sources :

Example 16 with TermDocs

use of org.apache.lucene.index.TermDocs in project jackrabbit by apache.

the class SimilarityQuery method rewrite.

/**
     * {@inheritDoc}
     */
public Query rewrite(IndexReader reader) throws IOException {
    MoreLikeThis more = new MoreLikeThis(reader);
    more.setAnalyzer(analyzer);
    more.setFieldNames(new String[] { FieldNames.FULLTEXT });
    more.setMinWordLen(4);
    Query similarityQuery = null;
    TermDocs td = reader.termDocs(TermFactory.createUUIDTerm(uuid));
    try {
        if (td.next()) {
            similarityQuery = more.like(td.doc());
        }
    } finally {
        td.close();
    }
    if (similarityQuery != null) {
        return similarityQuery.rewrite(reader);
    } else {
        // return dummy query that never matches
        return new BooleanQuery();
    }
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermDocs(org.apache.lucene.index.TermDocs)

Example 17 with TermDocs

use of org.apache.lucene.index.TermDocs in project jackrabbit-oak by apache.

the class RepositoryUpgrade method assertNoLongNames.

void assertNoLongNames() throws RepositoryException {
    Session session = source.getRepository().login(null, null);
    boolean longNameFound = false;
    try {
        IndexReader reader = IndexAccessor.getReader(source);
        if (reader == null) {
            return;
        }
        TermEnum terms = reader.terms(new Term(FieldNames.LOCAL_NAME));
        while (terms.next()) {
            Term t = terms.term();
            if (!FieldNames.LOCAL_NAME.equals(t.field())) {
                continue;
            }
            String name = t.text();
            if (NameFilteringNodeState.isNameTooLong(name)) {
                TermDocs docs = reader.termDocs(t);
                if (docs.next()) {
                    int docId = docs.doc();
                    String uuid = reader.document(docId).get(FieldNames.UUID);
                    Node n = session.getNodeByIdentifier(uuid);
                    logger.warn("Name too long: {}", n.getPath());
                    longNameFound = true;
                }
            }
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } finally {
        session.logout();
    }
    if (longNameFound) {
        logger.error("Node with a long name has been found. Please fix the content or rerun the migration with {} option.", SKIP_NAME_CHECK);
        throw new RepositoryException("Node with a long name has been found.");
    }
}
Also used : TermDocs(org.apache.lucene.index.TermDocs) Node(javax.jcr.Node) IndexReader(org.apache.lucene.index.IndexReader) RepositoryException(javax.jcr.RepositoryException) Term(org.apache.lucene.index.Term) IOException(java.io.IOException) TermEnum(org.apache.lucene.index.TermEnum) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Session(javax.jcr.Session)

Aggregations

TermDocs (org.apache.lucene.index.TermDocs)17 Term (org.apache.lucene.index.Term)13 TermEnum (org.apache.lucene.index.TermEnum)5 Document (org.apache.lucene.document.Document)4 BitSet (java.util.BitSet)3 RepositoryException (javax.jcr.RepositoryException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 IndexReader (org.apache.lucene.index.IndexReader)2 FixedBitSet (org.apache.lucene.util.FixedBitSet)2 MalformedURLException (java.net.MalformedURLException)1 LinkedHashMap (java.util.LinkedHashMap)1 WeakHashMap (java.util.WeakHashMap)1 Node (javax.jcr.Node)1 Session (javax.jcr.Session)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1