protected List<Map<String, Object>> getIndexFields(String index) throws IOException, SolrServerException { List<Map<String, Object>> indexFields = new ArrayList<>(); // Get all the fields in use, including dynamic fields LukeRequest lukeRequest = new LukeRequest(); LukeResponse lukeResponse = lukeRequest.process(client, index); for (Entry<String, LukeResponse.FieldInfo> field : lukeResponse.getFieldInfo().entrySet()) { Map<String, Object> fieldData = new HashMap<>(); fieldData.put("name", field.getValue().getName()); fieldData.put("type", field.getValue().getType()); indexFields.add(fieldData); } // Get all the schema fields SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index) .getSchemaRepresentation(); indexFields.addAll(schemaRepresentation.getFields()); return indexFields; }
@SuppressWarnings("unchecked") public void read(NamedList<Object> nl) { for (Map.Entry<String, Object> entry : nl) { if ("type".equals(entry.getKey())) { type = (String) entry.getValue(); } if ("flags".equals(entry.getKey())) { flags = parseFlags((String) entry.getValue()); } else if ("schema".equals(entry.getKey())) { schema = (String) entry.getValue(); } else if ("docs".equals(entry.getKey())) { docs = (Integer) entry.getValue(); } else if ("distinct".equals(entry.getKey())) { distinct = (Integer) entry.getValue(); } else if ("cacheableFaceting".equals(entry.getKey())) { cacheableFaceting = (Boolean) entry.getValue(); } else if ("topTerms".equals(entry.getKey())) { topTerms = (NamedList<Integer>) entry.getValue(); } } }
String fieldType = entry.getValue().getType(); int index = StringUtils.lastIndexOfAny(entry.getKey(), FORMAT_SUFFIXES); String suffix = entry.getKey().substring(index);
fieldName = fieldName.substring(0, fieldName.length() - 1); final FieldInfo fieldInfo = new FieldInfo(fieldName); fieldInfo.read((NamedList<Object>) field.getValue()); if (fieldInfo.getType() == null) { throw new GeneralServiceException("No solr dynamic field info in Luke Response for field: {}", fieldName);
/** * Returns all Solr fields that have <code>indexed</code> set to <code>true</code>. This implementation uses * the <code>LukeRequestHandler</code>, as such this method will return dynamic fields as well. * * @param solrCore Solr core name * @return a list of indexed fields on success, and an empty list otherwise. */ public List<String> getIndexedFieldsFromLuke(String solrCore) { List<String> availableIndexedFields = new ArrayList<String>(); SolrClient solrClient = getQueryingSolrClient(); final LukeRequest request = new LukeRequest(); request.setShowSchema(true); LOG.info("Looking up available indexed fields using Luke"); try { LukeResponse response = request.process(solrClient, solrCore); Map<String, LukeResponse.FieldInfo> fields = response.getFieldInfo(); for (LukeResponse.FieldInfo field : fields.values()) { Set<FieldFlag> indexFlags = field.getFlags(); if (indexFlags != null && indexFlags.contains(FieldFlag.INDEXED)) { availableIndexedFields.add(field.getName()); } } } catch (SolrServerException e) { LOG.error("Error fetching indexed fields of schema '{}'. ", solrCore, e); } catch (IOException e) { LOG.error("Error fetching indexed fields of schema '{}'. ", solrCore, e); } LOG.info("Found indexed fields [{}]", availableIndexedFields); return availableIndexedFields; }
fieldInfo = new HashMap<>(); for (Map.Entry<String, Object> field : flds) { FieldInfo f = new FieldInfo(field.getKey()); f.read((NamedList<Object>) field.getValue()); fieldInfo.put(field.getKey(), f); dynamicFieldInfo = new HashMap<>(); for (Map.Entry<String, Object> dynamicField : dynamicFlds) { FieldInfo f = new FieldInfo(dynamicField.getKey()); f.read((NamedList<Object>) dynamicField.getValue()); dynamicFieldInfo.put(dynamicField.getKey(), f);
/** * Retrieves a list of all the multi valued fields in the solr core * * @return all fields tagged as multivalued * @throws SolrServerException When getting the schema information from the SOLR core fails * @throws IOException When connection to the SOLR server fails */ public Set<String> getMultivaluedFieldNames() throws SolrServerException, IOException { Set<String> multivaluedFields = new HashSet<String>(); LukeRequest lukeRequest = new LukeRequest(); lukeRequest.setShowSchema(true); LukeResponse process = lukeRequest.process(solr); Map<String, LukeResponse.FieldInfo> fields = process.getFieldInfo(); for (String fieldName : fields.keySet()) { LukeResponse.FieldInfo fieldInfo = fields.get(fieldName); EnumSet<FieldFlag> flags = fieldInfo.getFlags(); for (FieldFlag fieldFlag : flags) { if (fieldFlag.getAbbreviation() == FieldFlag.MULTI_VALUED.getAbbreviation()) { multivaluedFields.add(fieldName); } } } return multivaluedFields; }
/** * Determine the names of all multi-valued fields from the data in the index. * * @param solr the solr server to query. * @return A list containing all multi-valued fields, or an empty list if none are found / there aren't any. */ private static List<String> getMultiValuedFields(HttpSolrServer solr) { List<String> result = new ArrayList<>(); try { LukeRequest request = new LukeRequest(); // this needs to be a non-schema request, otherwise we'll miss dynamic fields LukeResponse response = request.process(solr); Map<String, LukeResponse.FieldInfo> fields = response.getFieldInfo(); for (LukeResponse.FieldInfo info : fields.values()) { if (info.getSchema().contains(FieldFlag.MULTI_VALUED.getAbbreviation() + "")) { result.add(info.getName()); } } } catch (IOException | SolrServerException e) { log.fatal("Cannot determine which fields are multi valued: " + e.getMessage(), e); } return result; }
@SuppressWarnings("unchecked") public void read(NamedList<Object> nl) { for (Map.Entry<String, Object> entry : nl) { if ("type".equals(entry.getKey())) { type = (String) entry.getValue(); } if ("flags".equals(entry.getKey())) { flags = parseFlags((String) entry.getValue()); } else if ("schema".equals(entry.getKey())) { schema = (String) entry.getValue(); } else if ("docs".equals(entry.getKey())) { docs = (Integer) entry.getValue(); } else if ("distinct".equals(entry.getKey())) { distinct = (Integer) entry.getValue(); } else if ("cacheableFaceting".equals(entry.getKey())) { cacheableFaceting = (Boolean) entry.getValue(); } else if ("topTerms".equals(entry.getKey())) { topTerms = (NamedList<Integer>) entry.getValue(); } } }
@SuppressWarnings("unchecked") public void read(NamedList<Object> nl) { for (Map.Entry<String, Object> entry : nl) { if ("type".equals(entry.getKey())) { type = (String) entry.getValue(); } if ("flags".equals(entry.getKey())) { flags = parseFlags((String) entry.getValue()); } else if ("schema".equals(entry.getKey())) { schema = (String) entry.getValue(); } else if ("docs".equals(entry.getKey())) { docs = (Integer) entry.getValue(); } else if ("distinct".equals(entry.getKey())) { distinct = (Integer) entry.getValue(); } else if ("cacheableFaceting".equals(entry.getKey())) { cacheableFaceting = (Boolean) entry.getValue(); } else if ("topTerms".equals(entry.getKey())) { topTerms = (NamedList<Integer>) entry.getValue(); } } }
/** * Creates the metadata. * * @param field the field * @param fieldInfo the field info * @return the metadata * */ private static Metadata createMetadata(final Map.Entry<String, Object> field, final FieldInfo fieldInfo) { final Metadata metadata = new MetadataImpl(); setFlagParameters(metadata, fieldInfo.getFlags()); setComplexParameters(metadata, field); return metadata; }