@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; }
/** * 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; }
/** * 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; }
@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; }
final LukeRequest luke = new LukeRequest(); LukeResponse lukeResponse; luke.setShowSchema(true); try { lukeResponse = luke.process(searchServer);
try { LukeRequest lq = new LukeRequest(); lq.setShowSchema(true); LukeResponse processSchema = lq.process(solrServer); lq.setShowSchema(false); LukeResponse processField = lq.process(solrServer); Map<String, FieldInfo> fis = processField.getFieldInfo();
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()); }