Hello, I needed an easy way to see the index size (the actual size on disk, not 
just the number of documents indexed) and as i didn't found anything for doing 
that on the documentation or on the list, I coded a fast solution.

I added the Index size as a statistic of the searcher, that way the value can 
be seen on the statistics page of the Solr admin. To do this I modified the 
method 

public NamedList getStatistics() {... 

on the class 

org.apache.solr.search.SolrIndexSearcher

by adding the line

lst.add("indexSize", this.calculateIndexSize(reader.directory()).toString() + " 
MB");

and added the methods: 

 private BigDecimal calculateIndexSize(Directory directory) {
      long size = 0L;
      try {
        for(String filePath:directory.listAll()) {
            size+=directory.fileLength(filePath);
          }
    } catch (IOException e) {
        return new BigDecimal(-1);
    }
    return getSizeInMB(size, 2);
  }

    private BigDecimal getSizeInMB(long size, int scale) {
        BigDecimal divisor = new BigDecimal(1024);
        BigDecimal sizeKb = new BigDecimal(size).divide(divisor, scale + 1, 
BigDecimal.ROUND_HALF_UP);
        return sizeKb.divide(divisor, scale, BigDecimal.ROUND_HALF_UP);
    }

I'm running Solr 1.4 on a JBoss 4.0.5 with Java 1.5 and this worked just fine. 
Does anyone see a potential problem on this?

I'm assuming that the solr index will never have directories inside (that's why 
I'm just looping on the index parent directory), is there any case when this is 
not true?

Tomás



      Yahoo! Cocina

Encontra las mejores recetas con Yahoo! Cocina.


http://ar.mujer.yahoo.com/cocina/

Reply via email to