Search in sources :

Example 1 with SearchFields

use of edu.harvard.iq.dataverse.search.SearchFields in project dataverse by IQSS.

the class Index method getSolrSchema.

/**
 * We use the output of this method to generate our Solr schema.xml
 *
 * @todo Someday we do want to have this return a Response rather than a
 * String per https://github.com/IQSS/dataverse/issues/298 but not yet while
 * we are trying to ship Dataverse 4.0.
 */
@GET
@Path("solr/schema")
public String getSolrSchema() {
    StringBuilder sb = new StringBuilder();
    for (DatasetFieldType datasetField : datasetFieldService.findAllOrderedByName()) {
        String nameSearchable = datasetField.getSolrField().getNameSearchable();
        SolrField.SolrType solrType = datasetField.getSolrField().getSolrType();
        String type = solrType.getType();
        if (solrType.equals(SolrField.SolrType.EMAIL)) {
            /**
             * @todo should we also remove all "email" field types (e.g.
             * datasetContact) from schema.xml? We are explicitly not
             * indexing them for
             * https://github.com/IQSS/dataverse/issues/759
             *
             * "The list of potential collaborators should be searchable"
             * according to https://github.com/IQSS/dataverse/issues/747 but
             * it's not clear yet if this means a Solr or database search.
             * For now we'll keep schema.xml as it is to avoid people having
             * to update it. If anything, we can remove the email field type
             * when we do a big schema.xml update for
             * https://github.com/IQSS/dataverse/issues/754
             */
            logger.info("email type detected (" + nameSearchable + ") See also https://github.com/IQSS/dataverse/issues/759");
        }
        String multivalued = datasetField.getSolrField().isAllowedToBeMultivalued().toString();
        // <field name="datasetId" type="text_general" multiValued="false" stored="true" indexed="true"/>
        sb.append("   <field name=\"" + nameSearchable + "\" type=\"" + type + "\" multiValued=\"" + multivalued + "\" stored=\"true\" indexed=\"true\"/>\n");
    }
    List<String> listOfStaticFields = new ArrayList<>();
    Object searchFieldsObject = new SearchFields();
    Field[] staticSearchFields = searchFieldsObject.getClass().getDeclaredFields();
    for (Field fieldObject : staticSearchFields) {
        String name = fieldObject.getName();
        String staticSearchField = null;
        try {
            staticSearchField = (String) fieldObject.get(searchFieldsObject);
        } catch (IllegalArgumentException ex) {
        } catch (IllegalAccessException ex) {
        }
        /**
         * @todo: if you search for "pdf" should you get all pdfs? do we
         * need a copyField source="filetypemime_s" to the catchall?
         */
        if (listOfStaticFields.contains(staticSearchField)) {
            return error("static search field defined twice: " + staticSearchField);
        }
        listOfStaticFields.add(staticSearchField);
    }
    sb.append("---\n");
    for (DatasetFieldType datasetField : datasetFieldService.findAllOrderedByName()) {
        String nameSearchable = datasetField.getSolrField().getNameSearchable();
        String nameFacetable = datasetField.getSolrField().getNameFacetable();
        if (listOfStaticFields.contains(nameSearchable)) {
            if (nameSearchable.equals(SearchFields.DATASET_DESCRIPTION)) {
            // Skip, expected conflct.
            } else {
                return error("searchable dataset metadata field conflict detected with static field: " + nameSearchable);
            }
        }
        if (listOfStaticFields.contains(nameFacetable)) {
            if (nameFacetable.equals(SearchFields.SUBJECT)) {
            // Skip, expected conflct.
            } else {
                return error("facetable dataset metadata field conflict detected with static field: " + nameFacetable);
            }
        }
        // <copyField source="*_i" dest="text" maxChars="3000"/>
        sb.append("   <copyField source=\"").append(nameSearchable).append("\" dest=\"text\" maxChars=\"3000\"/>\n");
    }
    return sb.toString();
}
Also used : SearchFields(edu.harvard.iq.dataverse.search.SearchFields) ArrayList(java.util.ArrayList) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) SolrField(edu.harvard.iq.dataverse.search.SolrField) Field(java.lang.reflect.Field) DvObject(edu.harvard.iq.dataverse.DvObject) JsonObject(javax.json.JsonObject) SolrField(edu.harvard.iq.dataverse.search.SolrField) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)1 DvObject (edu.harvard.iq.dataverse.DvObject)1 SearchFields (edu.harvard.iq.dataverse.search.SearchFields)1 SolrField (edu.harvard.iq.dataverse.search.SolrField)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 JsonObject (javax.json.JsonObject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1