@Override public long getLastTimeUsed() { long lastModifiedTime = -1; LukeRequest request = new LukeRequest(); request.setShowSchema(true); try { LukeResponse response = request.process(this._client, this._collection); if (response != null) { Date lastModified = (Date)response.getIndexInfo().get("lastModified"); if(lastModified != null){ lastModifiedTime =lastModified.getTime(); }else{ return lastModifiedTime; } } } catch ( SolrServerException | IOException ex) { LOGGER.error("Cannot get last modified time ", ex); } return lastModifiedTime; }
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 @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; }
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; }
@Override public LukeResponse metadata(LukeRequest request) throws TranslatorException { try { return request.process(this.server); } catch (SolrServerException e) { throw new TranslatorException(e); } catch (IOException e) { throw new TranslatorException(e); } }
@Deprecated public static NamedList<Object> getAllFacetFields(SolrServer solrServer) throws SolrServerException, IOException { LukeRequest qr = new LukeRequest(); NamedList<Object> qresp = solrServer.request(qr); Object fields = qresp.get("fields"); if (fields instanceof NamedList<?>) { @SuppressWarnings("unchecked") NamedList<Object> fieldsList = (NamedList<Object>) fields; return fieldsList; } else { throw new IllegalStateException( "Fields container is not a NamedList, so there is no facet information available"); } }
@Override public SolrParams getParams() { final ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); params.add("numTerms", "0"); return params; }
/** * 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; }
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; }
@Override public LukeResponse metadata(LukeRequest request) throws TranslatorException { try { return request.process(this.server); } catch (SolrServerException e) { throw new TranslatorException(e); } catch (IOException e) { throw new TranslatorException(e); } }
public static NamedList<Object> getAllFacetFields(SolrServer solrServer) throws SolrServerException, IOException { LukeRequest qr = new LukeRequest(); NamedList<Object> qresp = solrServer.request(qr); Object fields = qresp.get("fields"); if (fields instanceof NamedList<?>) { @SuppressWarnings("unchecked") NamedList<Object> fieldsList = (NamedList<Object>) fields; return fieldsList; } else { throw new IllegalStateException( "Fields container is not a NamedList, so there is no facet information available"); } }
@Override public SolrParams getParams() { final ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); params.add("numTerms", "0"); return params; }
/** * 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; }
public SchemaField getSchemaField(String propertyName, boolean isSearchedAsExactValue) { SchemaField schemaField = null; LukeRequest luke = new LukeRequest(); LukeResponse rsp; try { rsp = luke.process(solr.getClient()); Map<String, FieldInfo> fieldsInfo = rsp.getFieldInfo(); if (fieldsInfo != null && !fieldsInfo.isEmpty()) {
/** * 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; }
@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()); }
final LukeRequest luke = new LukeRequest(); LukeResponse lukeResponse; luke.setShowSchema(true); try { lukeResponse = luke.process(searchServer); } catch (final SolrException e) { LOG.warn("Schema request failed (Solr error).", e);
solrAttributes = new ArrayList<SolrAttribute>(); try { LukeRequest lq = new LukeRequest(); lq.setShowSchema(true); LukeResponse processSchema = lq.process(solrServer); lq = new LukeRequest(); lq.setShowSchema(false); LukeResponse processField = lq.process(solrServer); Map<String, FieldInfo> fis = processField.getFieldInfo(); SortedSet<String> keys = new TreeSet<String>(fis.keySet());