Example usage for org.apache.solr.common SolrDocument containsKey

List of usage examples for org.apache.solr.common SolrDocument containsKey

Introduction

In this page you can find the example usage for org.apache.solr.common SolrDocument containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:au.org.aekos.shared.api.model.dataset.SharedSearchResultFactory.java

/**
 * @param solrDoc         document to extract the embargo date from
 * @param compareToDate      compare the embargo date to this date to determine if we are under embargo.
 *                      Should be today but can be used against any day.
 * @return               <code>true</code> if we are still under embargo, <code>false</code> otherwise
 *///  w  w  w . j  a v  a  2  s  .c  om
boolean determineIsEmbargoedOnDate(SolrDocument solrDoc, Date compareToDate) {
    if (!solrDoc.containsKey(embargoDateIndexName))
        return false;
    Date embargoDate = (Date) solrDoc.getFirstValue(embargoDateIndexName);
    return compareToDate.before(embargoDate);
}

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

License:Open Source License

private List<String[]> intersectResults(String layersServiceUrl, String[] analysisLayers,
        SolrDocumentList results) {//  w  w  w .  j a  va  2  s.  com
    List<String[]> intersection = new ArrayList<String[]>();

    if (analysisLayers.length > 0 && StringUtils.isNotEmpty(layersServiceUrl)) {
        try {
            double[][] points = new double[results.size()][2];
            int invalid = 0;
            int i = 0;
            for (SolrDocument sd : results) {
                if (sd.containsKey("sensitive_longitude") && sd.containsKey("sensitive_latitude")) {
                    points[i][0] = (double) sd.getFirstValue("sensitive_longitude");
                    points[i][1] = (double) sd.getFirstValue("sensitive_latitude");
                } else if (sd.containsKey("longitude") && sd.containsKey("latitude")) {
                    points[i][0] = (double) sd.getFirstValue("longitude");
                    points[i][1] = (double) sd.getFirstValue("latitude");
                } else {
                    points[i][0] = 0;
                    points[i][1] = 0;
                    invalid++;
                }
                i++;
            }

            if (invalid < results.size()) {
                LayersStore ls = new LayersStore(layersServiceUrl);
                Reader reader = ls.sample(analysisLayers, points, null);

                CSVReader csv = new CSVReader(reader);
                intersection = csv.readAll();
                csv.close();
            }
        } catch (IOException e) {
            logger.error("Failed to intersect analysis layers", e);
        }
    }

    return intersection;
}

From source file:ec.edu.ucuenca.dcc.sld.SolrConnection.java

public JSONArray FindModX(String endpoint, String pquery, int limit, String mm)
        throws SolrServerException, IOException {

    String[] out = { "uri", "Icon", "Title", "Language", "Handle", "endpoint", "CallNumber", "BibLevel" };
    String[] outr = { "URI", "Icon", "Title", "Language", "Handle", "Repository", "CallNumber", "BibLevel" };
    boolean[] outt = { true, true, true, true, true, true, false, true };
    int current = 0;
    JSONArray lsResults = new JSONArray();
    NamedList params = new NamedList();

    String newquery = "+(" + pquery + ") +(endpoint:\"" + endpoint + "\")";
    System.out.println("LOG_Solr_" + newquery);
    params.add("q", newquery);
    params.add("fl", "*,score");
    params.add("start", current + "");
    params.add("defType", "edismax");
    //params.add("mm", ""+mm);
    params.add("qf", "finalText");
    while (true) {
        params.setVal(2, current + "");
        SolrParams toSolrParams = SolrParams.toSolrParams(params);
        QueryResponse query = Solr.query(toSolrParams, SolrRequest.METHOD.POST);
        SolrDocumentList results = query.getResults();
        if (!query.getResults().isEmpty()) {
            boolean end = false;
            for (int i = 0; i < results.size(); i++) {
                SolrDocument get = results.get(i);
                current++;//from  w w  w . j ava2  s  .  c o  m
                JSONObject mp = new JSONObject();
                for (int ix = 0; ix < out.length; ix++) {
                    if (get.containsKey(out[ix])) {
                        if (outt[ix]) {
                            String toString = get.getFieldValue(out[ix]).toString();
                            mp.put(outr[ix], toString);
                        } else {
                            Collection<Object> fieldValues = get.getFieldValues(out[ix]);
                            JSONArray vls = new JSONArray();
                            for (Object ob : fieldValues) {
                                vls.add(ob.toString());
                            }
                            mp.put(outr[ix], vls);
                        }
                    }
                }
                if (Double.parseDouble(get.getFieldValue("score").toString()) > 1.0) {
                    lsResults.add(mp);
                }
                if (limit != -1 && current >= limit) {
                    end = true;
                    break;
                }
            }
            if (end) {
                break;
            }
        } else {
            break;
        }
    }

    return lsResults;

}

From source file:edu.tamu.tcat.trc.digires.books.hathitrust.HTFilesSearchService.java

License:Apache License

private CopySearchResult getSearchResults(QueryResponse response) {
    SolrDocumentList documents = response.getResults();
    Collection<DigitalCopyProxy> digitalProxy = new ArrayList<>();
    for (SolrDocument doc : documents) {
        String htid = doc.getFieldValue("id").toString();
        String recordId = doc.getFieldValue("recordNumber").toString();

        HTCopyProxy htProxy = new HTCopyProxy();
        htProxy.identifier = buildIdentifier(recordId, htid);
        htProxy.sourceSummary = doc.getFieldValue("source").toString();
        htProxy.title = doc.getFieldValue("title").toString();
        htProxy.rights = doc.getFieldValue("rights").toString();
        if (doc.containsKey("publicationDate"))
            htProxy.publicationDate = doc.getFieldValue("publicationDate").toString();
        else/*  w  w  w. j  a v  a  2  s .  c  o m*/
            htProxy.publicationDate = "";

        digitalProxy.add(htProxy);
    }
    return new CopySearchResultImpl(digitalProxy);
}

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

License:Open Source License

public SolrDocument doc2SolrDoc(Document doc) {
    SolrDocument solrDoc = new SolrDocument();
    for (IndexableField field : doc) {
        String fieldName = field.name();
        SchemaField sf = getSchemaField(fieldName); // hack-patch of this.core.getLatestSchema().getFieldOrNull(fieldName); makes it a lot faster!!
        Object val = null;
        try {//from  w ww.jav a2s  .  co m
            FieldType ft = null;
            if (sf != null)
                ft = sf.getType();
            if (ft == null) {
                BytesRef bytesRef = field.binaryValue();
                if (bytesRef != null) {
                    if (bytesRef.offset == 0 && bytesRef.length == bytesRef.bytes.length) {
                        val = bytesRef.bytes;
                    } else {
                        final byte[] bytes = new byte[bytesRef.length];
                        System.arraycopy(bytesRef.bytes, bytesRef.offset, bytes, 0, bytesRef.length);
                        val = bytes;
                    }
                } else {
                    val = field.stringValue();
                }
            } else {
                val = ft.toObject(field);
            }
        } catch (Throwable e) {
            continue;
        }

        if (sf != null && sf.multiValued() && !solrDoc.containsKey(fieldName)) {
            ArrayList<Object> l = new ArrayList<Object>();
            l.add(val);
            solrDoc.addField(fieldName, l);
        } else {
            solrDoc.addField(fieldName, val);
        }
    }
    return solrDoc;
}

From source file:net.yacy.search.index.Fulltext.java

License:Open Source License

/**
 * deprecated method to store document metadata, use Solr documents wherever possible
 *///from  w ww.j ava2 s.c  o  m
public void putMetadata(final URIMetadataNode entry) throws IOException {
    byte[] idb = entry.hash();
    String id = ASCII.String(idb);
    try {
        // because node entries are richer than metadata entries we must check if they exist to prevent that they are overwritten
        long date = this.getLoadTime(id);
        if (date == -1) {
            // document does not exist
            putDocument(getDefaultConfiguration().metadata2solr(entry));
        } else {
            // check if document contains rich data
            if (date < entry.loaddate().getTime()) {
                SolrDocument doc = this.getDefaultConnector().getDocumentById(id,
                        CollectionSchema.collection_sxt.getSolrFieldName());
                if (doc == null || !doc.containsKey(CollectionSchema.collection_sxt.getSolrFieldName())) {
                    putDocument(getDefaultConfiguration().metadata2solr(entry));
                } else {
                    Collection<Object> collections = doc
                            .getFieldValues(CollectionSchema.collection_sxt.getSolrFieldName());
                    // collection dht is used to identify metadata from full crawled documents (if "dht" exists don't overwrite rich crawldata with metadata
                    if (!collections.contains("dht"))
                        return;

                    // passed all checks, overwrite document
                    putDocument(getDefaultConfiguration().metadata2solr(entry));
                }
            }
        }
    } catch (final SolrException e) {
        throw new IOException(e.getMessage(), e);
    }
    if (MemoryControl.shortStatus())
        clearCaches();
}

From source file:org.apache.sentry.tests.e2e.solr.AbstractSolrSentryTestBase.java

License:Apache License

/**
 * Function to validate the content of Solr response with that of input document.
 * @param solrInputDoc - Solr doc inserted into Solr
 * @param solrRespDocs - List of Solr doc obtained as response
 * (NOTE: This function ignores "_version_" field in validating Solr doc content)
 *///from  ww  w . j ava 2 s.  c  o m
public void validateSolrDocContent(SolrInputDocument solrInputDoc, SolrDocumentList solrRespDocs) {
    for (SolrDocument solrRespDoc : solrRespDocs) {
        String expFieldValue = (String) solrInputDoc.getFieldValue("id");
        String resFieldValue = (String) solrRespDoc.getFieldValue("id");
        if (expFieldValue.equals(resFieldValue)) {
            int expectedRespFieldCount = solrRespDoc.size();
            if (solrRespDoc.containsKey("_version_")) {
                expectedRespFieldCount = expectedRespFieldCount - 1;
            }
            int expectedOrigFieldCount = solrInputDoc.size();
            if (solrInputDoc.containsKey("_version_")) {
                expectedOrigFieldCount = expectedOrigFieldCount - 1;
            }
            assertEquals("Expected " + expectedOrigFieldCount + " fields. But, found " + expectedRespFieldCount
                    + " fields", expectedOrigFieldCount, expectedRespFieldCount);
            for (String field : solrInputDoc.getFieldNames()) {
                if (field.equals("_version_") == true) {
                    continue;
                }

                expFieldValue = (String) solrInputDoc.getFieldValue(field);
                resFieldValue = (String) solrRespDoc.getFieldValue(field);
                assertEquals("Expected value for field: " + field + " is " + expFieldValue + "; But, found "
                        + resFieldValue, expFieldValue, resFieldValue);
            }

            return;
        }
    }

    fail("Solr doc not found in Solr collection");
}

From source file:org.apache.sentry.tests.e2e.solr.AbstractSolrSentryTestCase.java

License:Apache License

/**
 * Function to validate the content of Solr response with that of input document.
 * @param solrInputDoc - Solr doc inserted into Solr
 * @param solrRespDocs - List of Solr doc obtained as response
 * (NOTE: This function ignores "_version_" field in validating Solr doc content)
 *//*ww w.java2 s .c o m*/
public void validateSolrDocContent(SolrDocument solrInputDoc, SolrDocumentList solrRespDocs) {
    for (SolrDocument solrRespDoc : solrRespDocs) {
        String expFieldValue = (String) solrInputDoc.getFieldValue("id");
        String resFieldValue = (String) solrRespDoc.getFieldValue("id");
        if (expFieldValue.equals(resFieldValue)) {
            int expectedRespFieldCount = solrRespDoc.size();
            if (solrRespDoc.containsKey("_version_")) {
                expectedRespFieldCount = expectedRespFieldCount - 1;
            }
            int expectedOrigFieldCount = solrInputDoc.size();
            if (solrInputDoc.containsKey("_version_")) {
                expectedOrigFieldCount = expectedOrigFieldCount - 1;
            }
            assertEquals("Expected " + expectedOrigFieldCount + " fields. But, found " + expectedRespFieldCount
                    + " fields", expectedOrigFieldCount, expectedRespFieldCount);
            for (String field : solrInputDoc.getFieldNames()) {
                if (field.equals("_version_") == true) {
                    continue;
                }

                expFieldValue = (String) solrInputDoc.getFieldValue(field);
                resFieldValue = (String) solrRespDoc.getFieldValue(field);
                assertEquals("Expected value for field: " + field + " is " + expFieldValue + "; But, found "
                        + resFieldValue, expFieldValue, resFieldValue);
            }

            return;
        }
    }

    fail("Solr doc not found in Solr collection");
}

From source file:org.dataconservancy.dcs.access.impl.solr.DcsSolrIndexWriter.java

License:Apache License

private void copy(SolrDocument from, SolrInputDocument to, SolrName... fields) {
    for (SolrName field : fields) {
        if (from.containsKey(field.solrName())) {
            // don't copy if field is null

            String isnull = field.solrName() + DcsSolrMapper.IS_NULL_FIELD_SUFFIX;

            if (!from.containsKey(isnull) || !(Boolean) from.getFieldValue(isnull)) {

                to.addField(field.solrName(), from.getFieldValue(field.solrName()));
            }//from w  w  w  .j a  v  a 2s  .  com
        }
    }
}

From source file:org.dataconservancy.dcs.access.impl.solr.DcsSolrMapper.java

License:Apache License

private static boolean has(SolrDocument doc, SolrName field) {
    return doc.containsKey(field.solrName());
}