Example usage for org.apache.solr.common SolrInputField toString

List of usage examples for org.apache.solr.common SolrInputField toString

Introduction

In this page you can find the example usage for org.apache.solr.common SolrInputField toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.intermine.api.searchengine.solr.SolrObjectHandler.java

License:GNU General Public License

/**
 * Add object references to search document.
 *///  w  ww . j  ava 2s.  c o m
private void addReferences(InterMineObject object, HashSet<String> references,
        HashMap<String, InterMineResultsContainer> referenceResults,
        HashMap<String, KeywordSearchFacetData> referenceFacetFields, SolrInputDocument doc)
        throws IllegalAccessException {

    // find all references and add them
    for (String reference : references) {
        InterMineResultsContainer resultsContainer = referenceResults.get(reference);
        //step through the reference results (ordered) while ref.id = obj.id
        while (resultsContainer.getIterator().hasNext()) {
            @SuppressWarnings("rawtypes")
            ResultsRow next = resultsContainer.getIterator().next();

            // It is possible that the inner loop iterator "lags behind" the
            // current object's id. See:
            // https://github.com/intermine/intermine/issues/473
            while (resultsContainer.getIterator().hasNext()
                    && ((Integer) next.get(0)).compareTo(object.getId()) == -1) {
                next = resultsContainer.getIterator().next();
            }

            //reference is not for the current object?
            if (!next.get(0).equals(object.getId())) {
                // go back one step
                if (resultsContainer.getIterator().hasPrevious()) {
                    resultsContainer.getIterator().previous();
                }

                break;
            }

            // add reference to doc
            addObjectToDocument((InterMineObject) next.get(1), null, doc);

            //check if this reference contains an attribute we need for a facet
            KeywordSearchFacetData referenceFacet = referenceFacetFields.get(reference);
            if (referenceFacet != null) {
                //handle PATH facets FIXME: UNTESTED!
                if (referenceFacet.getType() == KeywordSearchFacetType.PATH) {
                    String virtualPathField = "path_" + referenceFacet.getName().toLowerCase();
                    for (String field : referenceFacet.getFields()) {
                        if (field.startsWith(reference + ".")) {
                            String facetAttribute = field.substring(field.lastIndexOf('.') + 1);
                            Object facetValue = ((InterMineObject) next.get(1)).getFieldValue(facetAttribute);

                            if (facetValue instanceof String && !StringUtils.isBlank((String) facetValue)) {
                                SolrInputField f = doc.getField(virtualPathField);

                                if (f != null) {
                                    f.setValue(f.toString() + "/" + facetValue);
                                } else {
                                    doc.addField(virtualPathField, (String) facetValue);
                                    addFieldNameToSchema(virtualPathField, RAW_FIELD_TYPE_NAME, false, true);
                                }
                            }
                        }
                    }
                } else {
                    //SINGLE/MULTI facet
                    //add attribute to document a second time, but unstemmed
                    //and with the field name corresponding to the facet name
                    String facetAttribute = referenceFacet.getField()
                            .substring(referenceFacet.getField().lastIndexOf('.') + 1);
                    Object facetValue = ((InterMineObject) next.get(1)).getFieldValue(facetAttribute);

                    if (facetValue instanceof String && !StringUtils.isBlank((String) facetValue)) {
                        doc.addField(referenceFacet.getField(), (String) facetValue);
                        addFieldNameToSchema(referenceFacet.getField(), RAW_FIELD_TYPE_NAME, false, true);
                    }
                }
            }
        }
    }
}