Search in sources :

Example 86 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class LukeRequestHandler method getIndexInfo.

// This method just gets the top-most level of information. This was conflated with getting detailed info
// for *all* the fields, called from CoreAdminHandler etc.
public static SimpleOrderedMap<Object> getIndexInfo(DirectoryReader reader) throws IOException {
    Directory dir = reader.directory();
    SimpleOrderedMap<Object> indexInfo = new SimpleOrderedMap<>();
    indexInfo.add("numDocs", reader.numDocs());
    indexInfo.add("maxDoc", reader.maxDoc());
    indexInfo.add("deletedDocs", reader.maxDoc() - reader.numDocs());
    indexInfo.add("indexHeapUsageBytes", getIndexHeapUsed(reader));
    // TODO? Is this different then: IndexReader.getCurrentVersion( dir )?
    indexInfo.add("version", reader.getVersion());
    indexInfo.add("segmentCount", reader.leaves().size());
    indexInfo.add("current", closeSafe(reader::isCurrent));
    indexInfo.add("hasDeletions", reader.hasDeletions());
    indexInfo.add("directory", dir);
    IndexCommit indexCommit = reader.getIndexCommit();
    String segmentsFileName = indexCommit.getSegmentsFileName();
    indexInfo.add("segmentsFile", segmentsFileName);
    indexInfo.add("segmentsFileSizeInBytes", getFileLength(indexCommit.getDirectory(), segmentsFileName));
    Map<String, String> userData = indexCommit.getUserData();
    indexInfo.add("userData", userData);
    String s = userData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
    if (s != null) {
        indexInfo.add("lastModified", new Date(Long.parseLong(s)));
    }
    return indexInfo;
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) IndexCommit(org.apache.lucene.index.IndexCommit) Date(java.util.Date) Directory(org.apache.lucene.store.Directory)

Example 87 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class LukeRequestHandler method getDocumentFieldsInfo.

private static SimpleOrderedMap<Object> getDocumentFieldsInfo(Document doc, int docId, IndexReader reader, IndexSchema schema) throws IOException {
    final CharsRefBuilder spare = new CharsRefBuilder();
    SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>();
    for (Object o : doc.getFields()) {
        Field field = (Field) o;
        SimpleOrderedMap<Object> f = new SimpleOrderedMap<>();
        SchemaField sfield = schema.getFieldOrNull(field.name());
        FieldType ftype = (sfield == null) ? null : sfield.getType();
        f.add("type", (ftype == null) ? null : ftype.getTypeName());
        f.add("schema", getFieldFlags(sfield));
        f.add("flags", getFieldFlags(field));
        f.add("value", (ftype == null) ? null : ftype.toExternal(field));
        // TODO: this really should be "stored"
        // may be a binary number
        f.add("internal", field.stringValue());
        BytesRef bytes = field.binaryValue();
        if (bytes != null) {
            f.add("binary", Base64.byteArrayToBase64(bytes.bytes, bytes.offset, bytes.length));
        }
        if (!ftype.isPointField()) {
            Term t = new Term(field.name(), ftype != null ? ftype.storedToIndexed(field) : field.stringValue());
            // this can be 0 for non-indexed fields
            f.add("docFreq", t.text() == null ? 0 : reader.docFreq(t));
        }
        // If we have a term vector, return that
        if (field.fieldType().storeTermVectors()) {
            try {
                Terms v = reader.getTermVector(docId, field.name());
                if (v != null) {
                    SimpleOrderedMap<Integer> tfv = new SimpleOrderedMap<>();
                    final TermsEnum termsEnum = v.iterator();
                    BytesRef text;
                    while ((text = termsEnum.next()) != null) {
                        final int freq = (int) termsEnum.totalTermFreq();
                        spare.copyUTF8Bytes(text);
                        tfv.add(spare.toString(), freq);
                    }
                    f.add("termVector", tfv);
                }
            } catch (Exception ex) {
                log.warn("error writing term vector", ex);
            }
        }
        finfo.add(field.name(), f);
    }
    return finfo;
}
Also used : Terms(org.apache.lucene.index.Terms) Term(org.apache.lucene.index.Term) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) FieldType(org.apache.solr.schema.FieldType) TermsEnum(org.apache.lucene.index.TermsEnum) SchemaField(org.apache.solr.schema.SchemaField) CopyField(org.apache.solr.schema.CopyField) IndexableField(org.apache.lucene.index.IndexableField) SchemaField(org.apache.solr.schema.SchemaField) Field(org.apache.lucene.document.Field) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) BytesRef(org.apache.lucene.util.BytesRef)

Example 88 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class PluginInfoHandler method getSolrInfoBeans.

private static SimpleOrderedMap<Object> getSolrInfoBeans(SolrCore core, boolean stats) {
    SimpleOrderedMap<Object> list = new SimpleOrderedMap<>();
    for (SolrInfoBean.Category cat : SolrInfoBean.Category.values()) {
        SimpleOrderedMap<Object> category = new SimpleOrderedMap<>();
        list.add(cat.name(), category);
        Map<String, SolrInfoBean> reg = core.getInfoRegistry();
        for (Map.Entry<String, SolrInfoBean> entry : reg.entrySet()) {
            SolrInfoBean m = entry.getValue();
            if (m.getCategory() != cat)
                continue;
            String na = "Not Declared";
            SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
            category.add(entry.getKey(), info);
            info.add(NAME, (m.getName() != null ? m.getName() : na));
            info.add("description", (m.getDescription() != null ? m.getDescription() : na));
            if (stats) {
                info.add("stats", m.getMetricsSnapshot());
            }
        }
    }
    return list;
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map)

Example 89 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SegmentsInfoRequestHandler method getSegmentInfo.

private SimpleOrderedMap<Object> getSegmentInfo(SegmentCommitInfo segmentCommitInfo) throws IOException {
    SimpleOrderedMap<Object> segmentInfoMap = new SimpleOrderedMap<>();
    segmentInfoMap.add(NAME, segmentCommitInfo.info.name);
    segmentInfoMap.add("delCount", segmentCommitInfo.getDelCount());
    segmentInfoMap.add("sizeInBytes", segmentCommitInfo.sizeInBytes());
    segmentInfoMap.add("size", segmentCommitInfo.info.maxDoc());
    Long timestamp = Long.parseLong(segmentCommitInfo.info.getDiagnostics().get("timestamp"));
    segmentInfoMap.add("age", new Date(timestamp));
    segmentInfoMap.add("source", segmentCommitInfo.info.getDiagnostics().get("source"));
    segmentInfoMap.add("version", segmentCommitInfo.info.getVersion().toString());
    return segmentInfoMap;
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Date(java.util.Date)

Example 90 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class ShowFileRequestHandler method showFromFileSystem.

// Return the file indicated (or the directory listing) from the local file system.
private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) {
    File adminFile = getAdminFileFromFileSystem(req, rsp, hiddenFiles);
    if (adminFile == null) {
        // exception already recorded
        return;
    }
    // Make sure the file exists, is readable and is not a hidden file
    if (!adminFile.exists()) {
        log.error("Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    if (!adminFile.canRead() || adminFile.isHidden()) {
        log.error("Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    // Show a directory listing
    if (adminFile.isDirectory()) {
        // it's really a directory, just go for it.
        int basePath = adminFile.getAbsolutePath().length() + 1;
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (File f : adminFile.listFiles()) {
            String path = f.getAbsolutePath().substring(basePath);
            // normalize slashes
            path = path.replace('\\', '/');
            if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) {
                continue;
            }
            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(path, fileInfo);
            if (f.isDirectory()) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
            fileInfo.add("modified", new Date(f.lastModified()));
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        //The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);
        ContentStreamBase content = new ContentStreamBase.FileStream(adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}
Also used : File(java.io.File) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrException(org.apache.solr.common.SolrException) Date(java.util.Date) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)132 NamedList (org.apache.solr.common.util.NamedList)70 ArrayList (java.util.ArrayList)37 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)28 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 List (java.util.List)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)19 SolrParams (org.apache.solr.common.params.SolrParams)16 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)16 SchemaField (org.apache.solr.schema.SchemaField)16 FieldType (org.apache.solr.schema.FieldType)14 BytesRef (org.apache.lucene.util.BytesRef)13 Test (org.junit.Test)13 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 SolrDocumentList (org.apache.solr.common.SolrDocumentList)11 HashSet (java.util.HashSet)10 SolrCore (org.apache.solr.core.SolrCore)10 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)9