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();
}
}
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.");
}
}
Aggregations