Example usage for org.apache.lucene.index IndexReader document

List of usage examples for org.apache.lucene.index IndexReader document

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexReader document.

Prototype

public final Document document(int docID, Set<String> fieldsToLoad) throws IOException 

Source Link

Document

Like #document(int) but only loads the specified fields.

Usage

From source file:org.lexevs.dao.index.lucenesupport.BaseLuceneIndexTemplate.java

License:Open Source License

@Override
public Document getDocumentById(final int id, final Set<String> fields) {
    return this.doInIndexReader(new IndexReaderCallback<Document>() {

        @Override/*from   ww w.  jav  a 2s  . co m*/
        public Document doInIndexReader(IndexReader indexReader) throws Exception {
            return indexReader.document(id, fields);
        }
    });
}

From source file:org.modeshape.jcr.query.lucene.CompareLengthQuery.java

License:Open Source License

@Override
protected Long readFromDocument(IndexReader reader, int docId) throws IOException {
    // This implementation reads the length of the field ...
    Document doc = reader.document(docId, fieldSelector);
    String valueString = doc.get(fieldName);
    String value = stringFactory.create(valueString);
    return value != null ? (long) value.length() : 0L;
}

From source file:org.modeshape.jcr.query.lucene.CompareNameQuery.java

License:Open Source License

@Override
protected Path.Segment readFromDocument(IndexReader reader, int docId) throws IOException {
    Document doc = reader.document(docId, fieldSelector);
    String localName = doc.get(fieldName);
    if (localName == null)
        return null;
    localName = caseOperation.execute(localName);
    int sns = longFactory.create(doc.get(snsIndexFieldName)).intValue();
    return pathFactory.createSegment(localName, sns);
}

From source file:org.modeshape.jcr.query.lucene.ComparePathQuery.java

License:Open Source License

@Override
protected Path readFromDocument(IndexReader reader, int docId) throws IOException {
    Document doc = reader.document(docId, fieldSelector);
    String valueString = doc.get(fieldName);
    if (valueString == null)
        return null;
    valueString = caseOperation.execute(valueString);
    return valueTypeFactory.create(valueString);
}

From source file:org.modeshape.jcr.query.lucene.CompareQuery.java

License:Open Source License

protected ValueType readFromDocument(IndexReader reader, int docId) throws IOException {
    Document doc = reader.document(docId, fieldSelector);
    String valueString = doc.get(fieldName);
    return valueTypeFactory.create(valueString);
}

From source file:org.modeshape.jcr.query.lucene.HasValueQuery.java

License:Open Source License

protected boolean hasValue(IndexReader reader, int docId) throws IOException {
    Document doc = reader.document(docId, fieldSelector);
    String valueString = doc.get(fieldName);
    return valueString != null;
}

From source file:org.modeshape.jcr.query.lucene.IdsQuery.java

License:Open Source License

protected boolean includeDocument(IndexReader reader, int docId) throws IOException {
    Document doc = reader.document(docId, fieldSelector);
    String valueString = doc.get(fieldName);
    return valueString != null && uuids.contains(valueString);
}

From source file:org.modeshape.search.lucene.LuceneSearchSession.java

License:Open Source License

protected Statistics search(String fullTextSearchExpression, List<Object[]> results, int maxRows, int offset)
        throws ParseException, IOException {
    // Parse the full-text search and search against the 'fts' field ...
    long planningNanos = System.nanoTime();
    QueryParser parser = new QueryParser(workspace.getVersion(), ContentIndex.FULL_TEXT, workspace.analyzer);
    Query query = parser.parse(fullTextSearchExpression);
    planningNanos = System.nanoTime() - planningNanos;
    if (logger.isTraceEnabled()) {
        logger.trace("search \"{0}\" workspace using {1}", workspace.getWorkspaceName(), query);
    }/*from w  ww  . ja  va2  s  .  c om*/

    // Execute the search and place the results into the supplied list ...
    TopDocs docs = getContentSearcher().search(query, maxRows + offset);
    IndexReader contentReader = getContentReader();
    ScoreDoc[] scoreDocs = docs.scoreDocs;
    int numberOfResults = scoreDocs.length;
    if (numberOfResults > offset) {
        // There are enough results to satisfy the offset ...
        for (int i = offset, num = scoreDocs.length; i != num; ++i) {
            ScoreDoc result = scoreDocs[i];
            int docId = result.doc;
            // Find the UUID of the node (this UUID might be artificial, so we have to find the path) ...
            Document doc = contentReader.document(docId, LOCATION_FIELDS_SELECTOR);
            Location location = readLocation(doc);
            // Now add the location ...
            results.add(new Object[] { location, result.score });
        }
    }
    long executionNanos = System.nanoTime() - planningNanos;
    return new Statistics(planningNanos, 0L, 0L, executionNanos);
}

From source file:org.modeshape.search.lucene.query.CompareLengthQuery.java

License:Open Source License

/**
 * {@inheritDoc}// w w w  . j a va 2  s  . c om
 * 
 * @see org.modeshape.search.lucene.query.CompareQuery#readFromDocument(org.apache.lucene.index.IndexReader, int)
 */
@Override
protected Integer readFromDocument(IndexReader reader, int docId) throws IOException {
    // This implementation reads the length of the field ...
    Document doc = reader.document(docId, fieldSelector);
    String valueString = doc.get(fieldName);
    String value = stringFactory.create(valueString);
    return value != null ? value.length() : 0;
}

From source file:org.modeshape.search.lucene.query.CompareNameQuery.java

License:Open Source License

/**
 * {@inheritDoc}//from   www.ja  va 2 s.c o m
 * 
 * @see org.modeshape.search.lucene.query.CompareQuery#readFromDocument(org.apache.lucene.index.IndexReader, int)
 */
@Override
protected Path.Segment readFromDocument(IndexReader reader, int docId) throws IOException {
    Document doc = reader.document(docId, fieldSelector);
    String localName = doc.get(fieldName);
    if (!caseSensitive)
        localName = localName.toLowerCase();
    int sns = longFactory.create(doc.get(snsIndexFieldName)).intValue();
    return pathFactory.createSegment(localName, sns);
}