Example usage for org.apache.solr.client.solrj.request LukeRequest setShowSchema

List of usage examples for org.apache.solr.client.solrj.request LukeRequest setShowSchema

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.request LukeRequest setShowSchema.

Prototype

public void setShowSchema(boolean showSchema) 

Source Link

Usage

From source file:com.github.fengtan.sophie.beans.SolrUtils.java

License:Open Source License

/**
 * Get a list of declared fields from the remote Solr server.
 * //from   w w w.  j  a v  a 2  s .  c o m
 * Dynamic fields are named according to how they are declared so may be
 * globs (e.g. dynamic_*).
 * 
 * @return Map of fields keyed by field name.
 * @throws SophieException
 *             If the remote fields cannot be fetched.
 */
@SuppressWarnings("unchecked")
public static Map<String, FieldInfo> getRemoteSchemaFields() throws SophieException {
    // Send request.
    LukeRequest request = new LukeRequest();
    request.setShowSchema(true);
    LukeResponse response;
    try {
        response = request.process(Sophie.client);
    } catch (SolrServerException | IOException | SolrException e) {
        throw new SophieException("Unable to fetch list of Solr fields", e);
    }
    // Extract regular fields.
    Map<String, FieldInfo> fields = new HashMap<String, FieldInfo>();
    fields.putAll(response.getFieldInfo());
    // Extract dynamic fields.
    NamedList<Object> schema = (NamedList<Object>) response.getResponse().get("schema");
    if (schema != null) {
        NamedList<Object> dynamicFields = (NamedList<Object>) schema.get("dynamicFields");
        if (dynamicFields != null) {
            for (Map.Entry<String, Object> dynamicField : dynamicFields) {
                FieldInfo fieldInfo = new FieldInfo(dynamicField.getKey());
                fieldInfo.read((NamedList<Object>) dynamicField.getValue());
                fields.put(dynamicField.getKey(), fieldInfo);
            }
        }
    }
    return fields;
}

From source file:com.sindicetech.siren.solr.schema.TestExtendedJsonField.java

License:Open Source License

@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());
}

From source file:com.sindicetech.siren.solr.SolrServerWrapper.java

License:Open Source License

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();
    }/*  w w w  . j ava 2s  . co  m*/
    return fieldInfos;
}

From source file:net.yacy.cora.federate.solr.connector.SolrServerConnector.java

License:Open Source License

private LukeResponse getIndexBrowser(final boolean showSchema) throws SolrServerException {
    // get all fields contained in index
    final LukeRequest lukeRequest = new LukeRequest();
    lukeRequest.setResponseParser(new XMLResponseParser());
    lukeRequest.setNumTerms(0);/*from  w  ww  .  j a  v  a2  s . c  om*/
    lukeRequest.setShowSchema(showSchema);
    LukeResponse lukeResponse = null;
    try {
        lukeResponse = lukeRequest.process(this.server);
    } catch (IOException e) {
        throw new SolrServerException(e.getMessage());
    }
    return lukeResponse;
}

From source file:org.geotools.data.solr.SolrDataStore.java

License:Open Source License

/**
 * Retrieve SOLR attribute for specific type <br/>
 * Two SOLR LukeRequest are needed to discover SOLR fields and theirs schema for dynamic and
 * static kinds. <br/>/*from w w  w .  j  av  a 2s. c o m*/
 * For each discovered field a SOLR request is needed to verify if the field has no values in
 * the actual type, this information will be stored in {@link SolrAttribute#setEmpty}. <br/>
 * SolrJ not extracts information about uniqueKey so custom class
 * {@link ExtendedFieldSchemaInfo} is used. <br/>
 * MultiValued SOLR field is mapped as String type
 * 
 * @param layerName the type to use to query the SOLR field {@link SolrDataStore#field}
 * 
 * @see {@link SolrUtils#decodeSolrFieldType}
 * @see {@link ExtendedFieldSchemaInfo#ExtendedFieldSchemaInfo}
 * 
 */
public ArrayList<SolrAttribute> getSolrAttributes(String layerName) {
    if (solrAttributes.isEmpty()) {
        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());
            for (String k : keys) {
                FieldInfo fieldInfo = fis.get(k);
                String name = fieldInfo.getName();
                String type = fieldInfo.getType();

                SolrQuery query = new SolrQuery();
                query.setQuery("*:*");
                query.setRows(0);
                query.addFilterQuery(this.field + ":*");
                if (layerName != null && layerName.isEmpty()) {
                    query.addFilterQuery(name + ":" + layerName);
                } else {
                    query.addFilterQuery(name + ":*");
                }
                QueryResponse rsp = solrServer.query(query);
                long founds = rsp.getResults().getNumFound();

                FieldTypeInfo fty = processSchema.getFieldTypeInfo(type);
                if (fty != null) {
                    Class<?> objType = SolrUtils.decodeSolrFieldType(fty.getClassName());
                    if (objType != null) {
                        ExtendedFieldSchemaInfo extendedFieldSchemaInfo = new SolrUtils.ExtendedFieldSchemaInfo(
                                processSchema, processField, name);
                        SolrAttribute at = new SolrAttribute(name, objType);
                        if (extendedFieldSchemaInfo.getUniqueKey()) {
                            at.setPk(true);
                            at.setUse(true);
                        }
                        if (extendedFieldSchemaInfo.getMultivalued()
                                && !Geometry.class.isAssignableFrom(at.getType())) {
                            at.setType(String.class);
                        }
                        at.setEmpty(founds == 0);
                        solrAttributes.add(at);
                    } else {
                        if (LOGGER.isLoggable(Level.FINE)) {
                            LOGGER.log(Level.FINE,
                                    "Skipping attribute " + fty.getName()
                                            + " as we don't know how to map its type to a java object "
                                            + fty.getClassName());
                        }
                    }
                }
            }
            // Reorder fields: empty after
            List<BeanComparator> sortFields = Arrays.asList(new BeanComparator("empty"),
                    new BeanComparator("name"));
            ComparatorChain multiSort = new ComparatorChain(sortFields);
            Collections.sort(solrAttributes, multiSort);
        } catch (Exception ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
    return solrAttributes;
}

From source file:org.sindice.siren.solr.SolrServerWrapper.java

License:Apache License

private Map<String, FieldInfo> getFieldInfos() throws SolrServerException, IOException {
    if (fieldInfos == null) {
        final LukeRequest request = new FastLukeRequest();
        request.setShowSchema(true);
        final LukeResponse response = request.process(server);
        fieldInfos = response.getFieldInfo();
    }/*from   w  w w. j  a  v  a2 s. co  m*/
    return fieldInfos;
}

From source file:org.teiid.translator.solr.SolrMetadataProcessor.java

License:Open Source License

public void getConnectorMetadata(SolrConnection conn, MetadataFactory metadataFactory)
        throws TranslatorException {
    int count = 0;
    LukeRequest request = new LukeRequest();
    request.setShowSchema(true);
    LukeResponse response = conn.metadata(request);

    Map<String, FieldInfo> fields = response.getFieldInfo();

    Table table = metadataFactory.addTable(conn.getCoreName());
    table.setSupportsUpdate(true);//from  www. ja va 2 s  .co m

    for (String name : fields.keySet()) {
        FieldInfo field = fields.get(name);
        EnumSet<FieldFlag> flags = field.getFlags();
        if ((!name.startsWith("_") && !name.endsWith("_")) || name.startsWith("*") || name.endsWith("*")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            if (flags.contains(FieldFlag.INDEXED) && flags.contains(FieldFlag.STORED)) {
                Column column = null;
                // array type
                if (flags.contains(FieldFlag.MULTI_VALUED)) {
                    column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()) + "[]", //$NON-NLS-1$
                            table);
                } else {
                    column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()), table);
                }
                column.setUpdatable(true);
                column.setSearchType(SearchType.Searchable);

                // create primary key; and unique keys
                if (field.getDistinct() > 0 || field.getName().equals("id")) { //$NON-NLS-1$
                    if (table.getPrimaryKey() == null) {
                        metadataFactory.addPrimaryKey("PK0", Arrays.asList(field.getName()), table); //$NON-NLS-1$
                    } else {
                        metadataFactory.addIndex("UI" + count, true, Arrays.asList(field.getName()), table); //$NON-NLS-1$
                        count++;
                    }
                }
            }
        }
    }
}

From source file:uk.co.flax.biosolr.ontology.search.solr.SolrSearchEngine.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public List<String> getDynamicFieldNames() throws SearchEngineException {
    List<String> fields = new ArrayList<>();

    LukeRequest request = new LukeRequest();
    request.setNumTerms(0);/* w  w w  .ja va  2 s  .co m*/
    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;
}