📄 documentalclusterindexreader.java
字号:
package it.unimi.dsi.mg4j.index.cluster;/* * MG4J: Managing Gigabytes for Java * * Copyright (C) 2006-2007 Sebastiano Vigna * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */import it.unimi.dsi.fastutil.ints.IntArrayList;import it.unimi.dsi.mg4j.index.IndexIterator;import it.unimi.dsi.mg4j.index.IndexIterators;import it.unimi.dsi.Util;import java.io.IOException;import java.util.ArrayList;import org.apache.log4j.Logger;/** An index reader for a {@link it.unimi.dsi.mg4j.index.cluster.DocumentalCluster}. It dispatches * the correct {@link it.unimi.dsi.mg4j.index.IndexReader} depending on the concrete subclass of * {@link it.unimi.dsi.mg4j.index.cluster.DocumentalCluster}. * * @author Sebastiano Vigna */public class DocumentalClusterIndexReader extends AbstractIndexClusterIndexReader { private static final Logger LOGGER = Util.getLogger( DocumentalClusterIndexReader.class ); private static final boolean DEBUG = false; /** The index this reader refers to. */ protected final DocumentalCluster index; public DocumentalClusterIndexReader( DocumentalCluster index, int bufferSize ) throws IOException { super( index, bufferSize ); this.index = index; } public IndexIterator documents( int term ) throws IOException { if ( ! index.flat ) throw new UnsupportedOperationException( "Only flat documental clusters allow access by term number" ); final IndexIterator[] iterator = new IndexIterator[ indexReader.length ]; for ( int i = 0; i < indexReader.length; i++ ) iterator[ i ] = indexReader[ i ].documents( term ); final IndexIterator indexIterator = index.concatenated ? new DocumentalConcatenatedClusterIndexIterator( this, iterator, index.allIndices ) : new DocumentalMergedClusterIndexIterator( this, iterator, index.allIndices ) ; return indexIterator; } public IndexIterator documents( final CharSequence term ) throws IOException { final ArrayList<IndexIterator> iterators = new ArrayList<IndexIterator>( indexReader.length ); final IntArrayList usedIndices = new IntArrayList(); for ( int i = 0; i < indexReader.length; i++ ) { if ( index.termFilter == null || index.termFilter[ i ].contains( term ) ) { IndexIterator it = indexReader[ i ].documents( term ); if ( it.hasNext() ) { iterators.add( it ); usedIndices.add( i ); } } } if ( DEBUG ) LOGGER.debug( "Indices used for " + term + ": " + usedIndices ); if ( iterators.isEmpty() ) return index.emptyIndexIterator; final IndexIterator indexIterator = index.concatenated ? new DocumentalConcatenatedClusterIndexIterator( this, iterators.toArray( IndexIterators.EMPTY_ARRAY ), usedIndices.toIntArray() ) : new DocumentalMergedClusterIndexIterator( this, iterators.toArray( IndexIterators.EMPTY_ARRAY ), usedIndices.toIntArray() ) ; indexIterator.term( term ); return indexIterator; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -