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; }
@Override public LukeResponse process( SolrServer server ) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); LukeResponse res = new LukeResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } }
final NamedList<Object> response = lukeResponse.getResponse(); final Map<String, FieldInfo> fieldsInfo = lukeResponse.getFieldInfo();
lq.setShowSchema(false); LukeResponse processField = lq.process(solrServer); Map<String, FieldInfo> fis = processField.getFieldInfo(); SortedSet<String> keys = new TreeSet<String>(fis.keySet()); for (String k : keys) { String type = fieldInfo.getType(); FieldTypeInfo fty = processSchema.getFieldTypeInfo(type); if (fty != null) { String solrTypeName = fty.getClassName();
@Override protected LukeResponse createResponse(SolrClient client) { return new LukeResponse(); }
NamedList schema = (NamedList) processSchema.getResponse().get("schema"); NamedList<NamedList> flds = (NamedList<NamedList>) schema.get("fields"); for (Entry<String, NamedList> entry : flds) { flds = (NamedList<NamedList>) processField.getResponse().get("fields"); for (Entry<String, NamedList> entry : flds) { String fn = entry.getKey();
/** * Return the number of documents currently indexed. */ public int getNumberOfDocuments() throws SolrServerException, IOException { final SolrRequest request = new FastLukeRequest(); final LukeResponse response = (LukeResponse) request.process(this.getServer()); return response.getNumDocs(); }
@Override protected LukeResponse createResponse(SolrClient client) { return new LukeResponse(); }
@Override @SuppressWarnings("unchecked") public List<String> getDynamicFieldNames() throws SearchEngineException { List<String> fields = new ArrayList<>(); LukeRequest request = new LukeRequest(); request.setNumTerms(0); request.setShowSchema(false); try { LukeResponse response = request.process(getServer()); NamedList<Object> flds = (NamedList<Object>) response.getResponse().get("fields"); if (flds != null) { for (Map.Entry<String, Object> field : flds) { String name = field.getKey(); for (Entry<String, Object> prop : (NamedList<Object>)field.getValue()) { if ("dynamicBase".equals(prop.getKey())) { fields.add(name); break; } } } } } catch (SolrServerException | IOException e) { throw new SearchEngineException(e); } return fields; }
/** * Return the number of documents currently indexed. */ public int getNumberOfDocuments() throws SolrServerException, IOException { final SolrRequest request = new FastLukeRequest(); final LukeResponse response = (LukeResponse) request.process(this.getServer()); return response.getNumDocs(); }
/** * 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; }
/** * 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; }
try { rsp = luke.process(solr.getClient()); Map<String, FieldInfo> fieldsInfo = rsp.getFieldInfo(); if (fieldsInfo != null && !fieldsInfo.isEmpty()) { LOGGER.debug("got fieldsInfo for {} fields", fieldsInfo.size());
/** * 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; }
private Map<String, FieldInfo> getFieldInfos() throws SolrServerException, IOException { if (fieldInfos == null) { final LukeRequest request = new FastLukeRequest(); request.setShowSchema(true); final LukeResponse response = request.process(this.getServer()); fieldInfos = response.getFieldInfo(); } return fieldInfos; }
private Map<String, FieldInfo> getFieldInfos() throws SolrServerException, IOException { if (fieldInfos == null) { final LukeRequest request = new FastLukeRequest(); request.setShowSchema(true); final LukeResponse response = request.process(this.getServer()); fieldInfos = response.getFieldInfo(); } return fieldInfos; }
@Test public void testLukeRequest() throws IOException, SolrServerException { LukeRequest req = new LukeRequest(); req.setShowSchema(true); final LukeResponse response = req.process(this.getWrapper().getServer()); assertTrue(!response.getFieldInfo().isEmpty()); }