Example usage for org.apache.lucene.index SegmentInfos iterator

List of usage examples for org.apache.lucene.index SegmentInfos iterator

Introduction

In this page you can find the example usage for org.apache.lucene.index SegmentInfos iterator.

Prototype


@Override
public Iterator<SegmentCommitInfo> iterator() 

Source Link

Document

Returns an unmodifiable Iterator of contained segments in order.

Usage

From source file:org.apache.sling.oakui.OakUIWebConsole.java

License:Apache License

private void analyseIndex(@Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response,
        @Nonnull String index) throws JSONException, IOException {
    // load the commit info and get all the files.
    // Need a directory implementation that works off the location, OakDirectory isn't exported, so will have to re-create.
    NodeStore ns = getNodeStore();//from  w  ww.  j  av a2s.  c o m
    NodeState oakIndex = ns.getRoot().getChildNode("oak:index");
    NodeStoreDirectory nsDirectory = new NodeStoreDirectory(oakIndex, index);
    JSONObject out = new JSONObject();

    int sequence = 0;
    for (String file : getSegments(nsDirectory.listAll())) {
        if (file.startsWith("segments")) {
            JSONObject segmentDetail = new JSONObject();
            //FSDirectory fsDirectory = new SimpleFSDirectory(new File("/Users/ieb/Adobe/CQ/6.2/crx-quickstart/repository/index/lucene-1476792800724/data"));
            SegmentInfos segmentCommitInfos = new SegmentInfos();
            try {
                if ("segments.gen".equals(file)) {
                    // segments.gen is actually a pre v3 segments file, to get the current commit open without specifying the segments file.
                    segmentCommitInfos.read(nsDirectory);
                } else {
                    segmentCommitInfos.read(nsDirectory, file);
                }
                Iterator<SegmentCommitInfo> sci = segmentCommitInfos.iterator();
                JSONArray commits = new JSONArray();
                while (sci.hasNext()) {
                    SegmentCommitInfo sc = sci.next();
                    JSONObject commitInfo = new JSONObject();
                    JSONArray files = new JSONArray();
                    for (String f : sc.files()) {
                        files.put(f);
                    }
                    commitInfo.put("files", files);
                    commitInfo.put("delcount", sc.getDelCount());
                    commitInfo.put("delgen", sc.getDelGen());
                    commitInfo.put("hasDeletions", sc.hasDeletions());
                    commitInfo.put("hasFieldUpdates", sc.hasFieldUpdates());
                    commitInfo.put("sizeInBytes", sc.sizeInBytes());
                    commitInfo.put("fieldInfosGen", sc.getFieldInfosGen());
                    commitInfo.put("nextDelGen", sc.getNextDelGen());
                    commitInfo.put("version", sc.info.getVersion());
                    commitInfo.put("diagnostics", sc.info.getDiagnostics());
                    commitInfo.put("doccount", sc.info.getDocCount());
                    commitInfo.put("name", sc.info.name);
                    commitInfo.put("useCompoundFile", sc.info.getUseCompoundFile());

                    commits.put(commitInfo);
                }
                segmentDetail.put("commits", commits);
                segmentDetail.put("segment_sequence", sequence);
                segmentDetail.put("segment_name", file);
            } catch (CorruptIndexException e) {
                LOGGER.info(e.getMessage(), e);
                segmentDetail.put("corruption", e.getMessage());
            }
            out.put(file, segmentDetail);
            sequence++;
        }
    }
    response.setContentType("application/json; charset=utf-8");
    response.getWriter().println(out.toString(4));
}