Example usage for org.apache.lucene.index SegmentCommitInfo getDelGen

List of usage examples for org.apache.lucene.index SegmentCommitInfo getDelGen

Introduction

In this page you can find the example usage for org.apache.lucene.index SegmentCommitInfo getDelGen.

Prototype

public long getDelGen() 

Source Link

Document

Returns generation number of the live docs file or -1 if there are no deletes yet.

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 a  va  2 s . 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));
}

From source file:org.eu.bitzone.Leia.java

License:Apache License

public void showSegments(final Object commitsTable) throws Exception {
    final Object segTable = find("segmentsTable");
    removeAll(segTable);//from w w  w . j a  v a 2s. co  m
    final Object[] rows = getSelectedItems(commitsTable);
    if (rows == null || rows.length == 0) {
        showStatus("No commit point selected.");
        return;
    }
    final Object row = rows[0];
    final IndexCommit commit = (IndexCommit) getProperty(row, "commit");
    if (commit == null) {
        showStatus("Can't retrieve commit point (application error)");
        return;
    }
    final Object segGen = find("segGen");
    setString(segGen, "text", commit.getSegmentsFileName() + " (gen " + commit.getGeneration() + ")");
    final String segName = commit.getSegmentsFileName();
    final SegmentInfos infos = new SegmentInfos();
    try {
        infos.read(dir, segName);
    } catch (final Exception e) {
        e.printStackTrace();
        errorMsg("Error reading segment infos for '" + segName + ": " + e.toString());
        return;
    }
    for (final SegmentCommitInfo si : infos.asList()) {
        final Object r = create("row");
        add(segTable, r);
        Object cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.name);
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", String.valueOf(si.getDelGen()));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", String.valueOf(si.getDelCount()));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", String.valueOf(si.info.getDocCount()));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.getVersion());
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.getCodec().getName());
        final long size = si.sizeInBytes();
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", Util.normalizeSize(size) + Util.normalizeUnit(size));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.getUseCompoundFile() ? "Y" : "N");

        putProperty(r, "si", si);
    }
    final Object diagsTable = find("diagsTable");
    removeAll(diagsTable);
}

From source file:org.getopt.luke.Luke.java

License:Apache License

public void showSegments(Object commitsTable) throws Exception {
    Object segTable = find("segmentsTable");
    removeAll(segTable);/*  www.  ja v a  2  s.  c om*/
    Object[] rows = getSelectedItems(commitsTable);
    if (rows == null || rows.length == 0) {
        showStatus("No commit point selected.");
        return;
    }
    Object row = rows[0];
    IndexCommit commit = (IndexCommit) getProperty(row, "commit");
    if (commit == null) {
        showStatus("Can't retrieve commit point (application error)");
        return;
    }
    Object segGen = find("segGen");
    setString(segGen, "text", commit.getSegmentsFileName() + " (gen " + commit.getGeneration() + ")");
    String segName = commit.getSegmentsFileName();
    SegmentInfos infos = new SegmentInfos();
    try {
        infos.read(dir, segName);
    } catch (Exception e) {
        e.printStackTrace();
        errorMsg("Error reading segment infos for '" + segName + ": " + e.toString());
        return;
    }
    for (SegmentCommitInfo si : infos.asList()) {
        Object r = create("row");
        add(segTable, r);
        Object cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.name);
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", String.valueOf(si.getDelGen()));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", String.valueOf(si.getDelCount()));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", String.valueOf(si.info.getDocCount()));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.getVersion().toString());
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.getCodec().getName());
        long size = si.sizeInBytes();
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", Util.normalizeSize(size) + Util.normalizeUnit(size));
        setChoice(cell, "alignment", "right");
        cell = create("cell");
        add(r, cell);
        setString(cell, "text", si.info.getUseCompoundFile() ? "Y" : "N");

        putProperty(r, "si", si);
    }
    Object diagsTable = find("diagsTable");
    removeAll(diagsTable);
}