当前位置: 首页>>代码示例>>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;未经允许,请勿转载。