Search in sources :

Example 1 with SliceReader

use of org.apache.lucene.util.IntBlockPool.SliceReader in project lucene-solr by apache.

the class MemoryIndex method toStringDebug.

/**
   * Returns a String representation of the index data for debugging purposes.
   * 
   * @return the string representation
   * @lucene.experimental
   */
public String toStringDebug() {
    StringBuilder result = new StringBuilder(256);
    int sumPositions = 0;
    int sumTerms = 0;
    final BytesRef spare = new BytesRef();
    final BytesRefBuilder payloadBuilder = storePayloads ? new BytesRefBuilder() : null;
    for (Map.Entry<String, Info> entry : fields.entrySet()) {
        String fieldName = entry.getKey();
        Info info = entry.getValue();
        info.sortTerms();
        result.append(fieldName + ":\n");
        SliceByteStartArray sliceArray = info.sliceArray;
        int numPositions = 0;
        SliceReader postingsReader = new SliceReader(intBlockPool);
        for (int j = 0; j < info.terms.size(); j++) {
            int ord = info.sortedTerms[j];
            info.terms.get(ord, spare);
            int freq = sliceArray.freq[ord];
            result.append("\t'" + spare + "':" + freq + ":");
            postingsReader.reset(sliceArray.start[ord], sliceArray.end[ord]);
            result.append(" [");
            final int iters = storeOffsets ? 3 : 1;
            while (!postingsReader.endOfSlice()) {
                result.append("(");
                for (int k = 0; k < iters; k++) {
                    result.append(postingsReader.readInt());
                    if (k < iters - 1) {
                        result.append(", ");
                    }
                }
                if (storePayloads) {
                    int payloadIndex = postingsReader.readInt();
                    if (payloadIndex != -1) {
                        result.append(", " + payloadsBytesRefs.get(payloadBuilder, payloadIndex));
                    }
                }
                result.append(")");
                if (!postingsReader.endOfSlice()) {
                    result.append(", ");
                }
            }
            result.append("]");
            result.append("\n");
            numPositions += freq;
        }
        result.append("\tterms=" + info.terms.size());
        result.append(", positions=" + numPositions);
        result.append("\n");
        sumPositions += numPositions;
        sumTerms += info.terms.size();
    }
    result.append("\nfields=" + fields.size());
    result.append(", terms=" + sumTerms);
    result.append(", positions=" + sumPositions);
    return result.toString();
}
Also used : BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) SliceReader(org.apache.lucene.util.IntBlockPool.SliceReader) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 BytesRef (org.apache.lucene.util.BytesRef)1 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)1 SliceReader (org.apache.lucene.util.IntBlockPool.SliceReader)1