當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexReader.document方法代碼示例

本文整理匯總了Java中org.apache.lucene.index.IndexReader.document方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexReader.document方法的具體用法?Java IndexReader.document怎麽用?Java IndexReader.document使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.index.IndexReader的用法示例。


在下文中一共展示了IndexReader.document方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkIndexContent

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
private void checkIndexContent(final String elementId,
		final String fieldContent, final int expectedAmount) throws IOException {
	final IndexReader reader = IndexManager.getInstance().getIndex().getIndexReader();
	final IndexSearcher searcher = new IndexSearcher(reader);
	final TopDocs topDocs = searcher.search(new TermQuery(new Term(FIELDNAME, fieldContent)), expectedAmount + 10);

	assertNotNull(topDocs);
	assertTrue(topDocs.totalHits == expectedAmount);

	if(expectedAmount > 0) {
		final ScoreDoc scoreDoc = topDocs.scoreDocs[0];
		assertNotNull(scoreDoc);

		final Document doc = reader.document(scoreDoc.doc);
		assertNotNull(doc);
		assertEquals(fieldContent, doc.get(FIELDNAME));
		assertEquals(elementId, doc.get(IIndexElement.FIELD_ID));
		assertEquals(INDEX_TYPE, doc.get(IIndexElement.FIELD_INDEX_TYPE));
	}
}
 
開發者ID:XMBomb,項目名稱:InComb,代碼行數:21,代碼來源:IndexingThreadTest.java

示例2: locateContainer

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
protected boolean locateContainer(String nodeRef, IndexReader reader)
{
    boolean found = false;
    try
    {
        TermDocs td = reader.termDocs(new Term("ID", nodeRef));
        while (td.next())
        {
            int doc = td.doc();
            Document document = reader.document(doc);
            if (document.getField("ISCONTAINER") != null)
            {
                found = true;
                break;
            }
        }
        td.close();
    }
    catch (IOException e)
    {
        throw new LuceneIndexException("Failed to delete container and below for " + nodeRef, e);
    }
    return found;        
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:25,代碼來源:AbstractLuceneIndexerImpl.java

示例3: getIdsForBitset

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
private List<ItemIdKey> getIdsForBitset(OpenBitSet docBits, IndexReader reader)
{
	int docid = 0;
	List<ItemIdKey> keys = new ArrayList<ItemIdKey>();
	while( true )
	{
		docid = docBits.nextSetBit(docid);
		if( docid == -1 )
		{
			break;
		}
		Document doc;
		try
		{
			doc = reader.document(docid);
		}
		catch( IOException e )
		{
			throw new RuntimeException(e);
		}
		ItemIdKey key = getKeyForDocument(doc);
		keys.add(key);
		docid++;
	}
	return keys;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:27,代碼來源:ItemIndex.java

示例4: search

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
/**
 * Executes the given {@link Query} and returns a {@link DocumentsSearchResult} with
 * the found documents and meta information about them.
 *
 * @param query the query to execute
 * @param options the additional options to execute the query.
 * @return {@link DocumentsSearchResult} with the found {@link Document}.
 */
public DocumentsSearchResult search(final Query query, final SearchOptions options) {
	final DocumentsSearchResult result = new DocumentsSearchResult();

	final TopDocs topDocs = getTopDocs(query, options);
	if(topDocs != null) {
		result.setTotalHits(topDocs.totalHits);

		final Index index = IndexManager.getInstance().getIndex();
		final IndexReader reader = index.getIndexReader();

		try {
			LOGGER.debug("Found these documents (total = {}) for query '{}':", topDocs.totalHits, query);

			int counter = 0;
			for (final ScoreDoc scoreDoc : topDocs.scoreDocs) {
				final Document document = reader.document(scoreDoc.doc);
				if(document != null) {
					LOGGER.debug("- Score: " + StringUtils.rightPad(Float.toString(scoreDoc.score), 8) +
							" Doc: " + document.get(IIndexElement.FIELD_ID));
					result.addDocument(document, scoreDoc.score);
				}

				// if it's the last document -> set ScoreDoc to result
				if(++counter == topDocs.scoreDocs.length) {
					result.setLastScoreDoc(scoreDoc);
				}
			}
		}
		catch(final IOException e) {
			LOGGER.error("Can't get documents for topdocs.", e);
		}
	}

	return result;
}
 
開發者ID:XMBomb,項目名稱:InComb,代碼行數:44,代碼來源:IndexSearch.java

示例5: deletePrimary

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
protected static Set<String> deletePrimary(Collection<String> nodeRefs, IndexReader reader, boolean delete)
        throws LuceneIndexException
{

    Set<String> refs = new LinkedHashSet<String>();

    for (String nodeRef : nodeRefs)
    {

        try
        {
            TermDocs td = reader.termDocs(new Term("PRIMARYPARENT", nodeRef));
            while (td.next())
            {
                int doc = td.doc();
                Document document = reader.document(doc);
                String[] ids = document.getValues("ID");
                refs.add(ids[ids.length - 1]);
                if (delete)
                {
                    reader.deleteDocument(doc);
                }
            }
            td.close();
        }
        catch (IOException e)
        {
            throw new LuceneIndexException("Failed to delete node by primary parent for " + nodeRef, e);
        }
    }

    return refs;

}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:35,代碼來源:AbstractLuceneIndexerImpl.java

示例6: deleteReference

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
protected static Set<String> deleteReference(Collection<String> nodeRefs, IndexReader reader, boolean delete)
        throws LuceneIndexException
{

    Set<String> refs = new LinkedHashSet<String>();

    for (String nodeRef : nodeRefs)
    {

        try
        {
            TermDocs td = reader.termDocs(new Term("PARENT", nodeRef));
            while (td.next())
            {
                int doc = td.doc();
                Document document = reader.document(doc);
                String[] ids = document.getValues("ID");
                refs.add(ids[ids.length - 1]);
                if (delete)
                {
                    reader.deleteDocument(doc);
                }
            }
            td.close();
        }
        catch (IOException e)
        {
            throw new LuceneIndexException("Failed to delete node by parent for " + nodeRef, e);
        }
    }

    return refs;

}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:35,代碼來源:AbstractLuceneIndexerImpl.java

示例7: deleteContainerAndBelow

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
protected static Set<String> deleteContainerAndBelow(String nodeRef, IndexReader reader, boolean delete,
        boolean cascade) throws LuceneIndexException
{
    Set<String> refs = new LinkedHashSet<String>();

    try
    {
        if (delete)
        {
            reader.deleteDocuments(new Term("ID", nodeRef));
        }
        refs.add(nodeRef);
        if (cascade)
        {
            TermDocs td = reader.termDocs(new Term("ANCESTOR", nodeRef));
            while (td.next())
            {
                int doc = td.doc();
                Document document = reader.document(doc);
                String[] ids = document.getValues("ID");
                refs.add(ids[ids.length - 1]);
                if (delete)
                {
                    reader.deleteDocument(doc);
                }
            }
            td.close();
        }
    }
    catch (IOException e)
    {
        throw new LuceneIndexException("Failed to delete container and below for " + nodeRef, e);
    }
    return refs;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:36,代碼來源:AbstractLuceneIndexerImpl.java

示例8: getImagesOf

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
private List<Image> getImagesOf(Collection collection) {

        List<Image> results = new ArrayList<>();

        try {
            Path path = indexPath(collection);
            if(!Files.exists(path)) return results;

            IndexReader ir = DirectoryReader.open(FSDirectory.open(path));

            int num = ir.numDocs();
            for ( int i = 0; i < num; i++)
            {
                Document d = ir.document(i);
                String imagePath = d.getField(DocumentBuilder.FIELD_NAME_IDENTIFIER).stringValue();
                String thumbnailPath = collectionUtils.getThumbnailPathFromImagePath(collection, imagePath);
                Image image = new Image(imagePath, thumbnailPath);
                image.setDocId(i);
                results.add(image);
            }
            ir.close();

        } catch (IOException e) {
            throw new LireLabException("Could not read index", e);
        }

        return results;
    }
 
開發者ID:AntonioGabrielAndrade,項目名稱:LIRE-Lab,代碼行數:29,代碼來源:CollectionAssembler.java

示例9: query

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
@Override
public <T> void query(
        @NonNull Collection<? super T> result,
        @NonNull Convertor<? super Document, T> convertor,
        @NullAllowed FieldSelector selector,
        @NullAllowed AtomicBoolean cancel,
        @NonNull Query... queries) throws IOException, InterruptedException {
    Parameters.notNull("queries", queries);   //NOI18N
    Parameters.notNull("convertor", convertor); //NOI18N
    Parameters.notNull("result", result);       //NOI18N   
    
    if (selector == null) {
        selector = AllFieldsSelector.INSTANCE;
    }
    
    lock.readLock().lock();
    try {
        final IndexReader in = getReader();
        if (in == null) {
            return;
        }
        final BitSet bs = new BitSet(in.maxDoc());
        final Collector c = new BitSetCollector(bs);
        final Searcher searcher = new IndexSearcher(in);
        try {
            for (Query q : queries) {
                if (cancel != null && cancel.get()) {
                    throw new InterruptedException ();
                }
                searcher.search(q, c);
            }
        } finally {
            searcher.close();
        }        
        for (int docNum = bs.nextSetBit(0); docNum >= 0; docNum = bs.nextSetBit(docNum+1)) {
            if (cancel != null && cancel.get()) {
                throw new InterruptedException ();
            }
            final Document doc = in.document(docNum, selector);
            final T value = convertor.convert(doc);
            if (value != null) {
                result.add (value);
            }
        }
    } finally {
        lock.readLock().unlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:49,代碼來源:MemoryIndex.java

示例10: queryDocTerms

import org.apache.lucene.index.IndexReader; //導入方法依賴的package包/類
@Override
public <S, T> void queryDocTerms(
        @NonNull Map<? super T, Set<S>> result,
        @NonNull Convertor<? super Document, T> convertor,
        @NonNull Convertor<? super Term, S> termConvertor,
        @NullAllowed FieldSelector selector,
        @NullAllowed AtomicBoolean cancel,
        @NonNull Query... queries) throws IOException, InterruptedException {
    Parameters.notNull("result", result);   //NOI18N
    Parameters.notNull("convertor", convertor);   //NOI18N
    Parameters.notNull("termConvertor", termConvertor); //NOI18N
    Parameters.notNull("queries", queries);   //NOI18N
    
    
    if (selector == null) {
        selector = AllFieldsSelector.INSTANCE;
    }

    lock.readLock().lock();
    try {
        final IndexReader in = getReader();
        if (in == null) {
            return;
        }
        final BitSet bs = new BitSet(in.maxDoc());
        final Collector c = new BitSetCollector(bs);
        final Searcher searcher = new IndexSearcher(in);
        final TermCollector termCollector = new TermCollector(c);
        try {
            for (Query q : queries) {
                if (cancel != null && cancel.get()) {
                    throw new InterruptedException ();
                }
                if (q instanceof TermCollector.TermCollecting) {
                    ((TermCollector.TermCollecting)q).attach(termCollector);
                } else {
                    throw new IllegalArgumentException (
                            String.format("Query: %s does not implement TermCollecting",    //NOI18N
                            q.getClass().getName()));
                }
                searcher.search(q, termCollector);
            }
        } finally {
            searcher.close();
        }

        for (int docNum = bs.nextSetBit(0); docNum >= 0; docNum = bs.nextSetBit(docNum+1)) {
            if (cancel != null && cancel.get()) {
                throw new InterruptedException ();
            }
            final Document doc = in.document(docNum, selector);
            final T value = convertor.convert(doc);
            if (value != null) {
                final Set<Term> terms = termCollector.get(docNum);
                if (terms != null) {
                    result.put (value, convertTerms(termConvertor, terms));
                }
            }
        }
    } finally {
        lock.readLock().unlock();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:64,代碼來源:MemoryIndex.java


注:本文中的org.apache.lucene.index.IndexReader.document方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。