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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations