Search in sources :

Example 11 with TermEnum

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

the class ChainedTermEnumTest method testEnum.

public void testEnum() throws Exception {
    Collection<TermEnum> enums = new ArrayList<TermEnum>();
    enums.add(createTermEnum("a", 2));
    enums.add(createTermEnum("b", 1));
    enums.add(createTermEnum("c", 0));
    enums.add(createTermEnum("d", 2));
    TermEnum terms = new IndexMigration.ChainedTermEnum(enums);
    List<String> expected = new ArrayList<String>();
    expected.addAll(Arrays.asList("a0", "a1", "b0", "d0", "d1"));
    List<String> result = new ArrayList<String>();
    do {
        Term t = terms.term();
        if (t != null) {
            result.add(t.text());
        }
    } while (terms.next());
    assertEquals(expected, result);
}
Also used : ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) TermEnum(org.apache.lucene.index.TermEnum)

Example 12 with TermEnum

use of org.apache.lucene.index.TermEnum 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

TermEnum (org.apache.lucene.index.TermEnum)12 Term (org.apache.lucene.index.Term)11 TermDocs (org.apache.lucene.index.TermDocs)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 IndexReader (org.apache.lucene.index.IndexReader)3 IndexWriter (org.apache.lucene.index.IndexWriter)3 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 TermPositions (org.apache.lucene.index.TermPositions)2 Directory (org.apache.lucene.store.Directory)2 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)1 Document (org.apache.lucene.document.Document)1