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

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

Introduction

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

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:de.hebis.it.hds.gnd.out.AutorityRecordSolrFinder.java

License:Open Source License

/**
 * Do real time get.//from w w  w. ja  v  a2 s .co m
 *
 * @param documentId the id of the authority record
 * @return a authority bean representing the authority record or null if the id does not exist.
 * @throws AuthorityRecordException
 */
private AuthorityBean doRealTimeGet(String documentId) throws AuthorityRecordException {
    QueryResponse response = null;
    SolrQuery rtg_query = new SolrQuery();
    rtg_query.setRequestHandler("/get");
    rtg_query.set("fl", "fullrecord");
    rtg_query.setFields("id", "preferred", "synonyms");
    rtg_query.set("id", documentId);
    try {
        response = server.query(rtg_query);
        if (response.getStatus() != 0)
            throw new SolrServerException("Response state: " + response.getStatus());
    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
        throw new AuthorityRecordException("Solr query \"" + rtg_query.toString() + "\" can't be executed.", e);
    }
    // Workaround: RTG does not allow to call response.getBeans(AuthorityBean.class);
    NamedList<Object> result = response.getResponse();
    if (result == null)
        throw new AuthorityRecordException("Solr query \"" + rtg_query.toString() + "\" has no result.");
    SolrDocument doc = (SolrDocument) result.get("doc");
    if ((doc == null) || (doc.size() == 0)) {
        if (LOG.isDebugEnabled())
            LOG.debug("Solr query \"" + rtg_query.toString() + "\" No doc found.");
        return null;
    }
    return documentObjectBinder.getBean(AuthorityBean.class, doc);
}

From source file:org.alfresco.solr.transformer.CachedDocTransformerTest.java

License:Open Source License

@Test
public void transformDocument_noDocTransformer_shouldReturnBasicFields() throws Exception {
    putHandleDefaults();//from  www  .j ava 2  s  .c  o  m
    //Test 1: Running a simple query without invoking CachedDocTransformer, expected to see id,DBID and _version_
    QueryResponse resp = query(getDefaultTestClient(), true, ALFRESCO_JSON,
            params("q", "*", "qt", "/afts", "shards.qt", "/afts"));
    assertNotNull(resp);
    SolrDocumentList results = resp.getResults();
    assertEquals("Expecting 5 rows", 5, results.size());
    SolrDocument doc = results.get(0);
    assertTrue(doc.size() == 3);
    assertNotNull(doc);
    String id = (String) doc.get("id");
    assertNotNull(id);
    long version = (long) doc.get("_version_");
    assertNotNull(version);
    long dbid = (long) doc.get("DBID");
    assertNotNull(dbid);
    //Not expected to see below as part of the solr response.
    String title = (String) doc.get("cm:title");
    assertNull(title);
    String owner = (String) doc.get("OWNER");
    assertNull(owner);
}

From source file:org.alfresco.solr.transformer.CachedDocTransformerTest.java

License:Open Source License

@Test
public void transformDocument_docTransformer_shouldReturnAllFields() throws Exception {
    putHandleDefaults();/*from   w  w w.jav  a 2 s .c o  m*/

    //Test 2: Running simple query with CachedDocTransformer, expected to see all fields returned
    QueryResponse resp = query(getDefaultTestClient(), true, ALFRESCO_JSON,
            params("q", "*", "qt", "/afts", "shards.qt", "/afts", "fl", "*,[cached]"));
    SolrDocument docWithAllFields = resp.getResults().get(0);
    assertTrue(docWithAllFields.size() > 3);

    Integer version2 = (Integer) docWithAllFields.get("_version_");
    assertNotNull(version2);
    String owner = ((ArrayList) docWithAllFields.get("OWNER")).toString();
    assertNotNull(owner);
    assertEquals("[mike]", owner);
    String title = ((ArrayList) docWithAllFields.get("cm:title")).toString();
    assertEquals("[title1]", title);
    assertNotNull(title);
    long dbid2 = (long) docWithAllFields.get("DBID");
    assertNotNull(dbid2);
}

From source file:org.alfresco.solr.transformer.CachedDocTransformerTest.java

License:Open Source License

@Test
public void transformDocument_docTransformerAndFieldsSelects_shouldReturnOnlySelectedFields() throws Exception {
    putHandleDefaults();/*w  w  w  .  ja va2 s.  c o  m*/

    //Test 3: Running simple query with CachedDocTransformer, expected to see selected fields returned
    QueryResponse resp = query(getDefaultTestClient(), true, ALFRESCO_JSON,
            params("q", "*", "qt", "/afts", "shards.qt", "/afts", "fl", "id,DBID,[cached]"));

    assertNotNull(resp);
    SolrDocument docWithRequestedFields = resp.getResults().get(0);
    assertTrue(docWithRequestedFields.size() == 2);
    assertNotNull(docWithRequestedFields.get("id"));
    assertNotNull(docWithRequestedFields.get("DBID"));
}

From source file:org.alfresco.solr.transformer.CachedDocTransformerTest.java

License:Open Source License

@Test
public void transformDocument_docTransformerNotDefaultFields_shouldReternOnlySelectedFields() throws Exception {
    putHandleDefaults();//  w ww .  j av a 2 s .  c  o m

    //Test 4: Running simple query with CachedDocTransformer on non default fields, expected to see selected fields returned
    QueryResponse resp = query(getDefaultTestClient(), true, ALFRESCO_JSON,
            params("q", "*", "qt", "/afts", "shards.qt", "/afts", "fl", "id, cm_title,[cached]"));

    assertNotNull(resp);
    SolrDocument docWithRequestedFields3 = resp.getResults().get(0);
    assertTrue(docWithRequestedFields3.size() == 2);
    assertNotNull(docWithRequestedFields3.get("id"));
    String title = (String) docWithRequestedFields3.getFieldValue("cm_title");
    assertEquals("title1", title);
}

From source file:org.alfresco.solr.transformer.CachedDocTransformerTest.java

License:Open Source License

@Test
public void transformDocument_docTransformerAndScoreRequested_shouldReturnScore() throws Exception {
    putHandleDefaults();//  w  w  w . j  ava2  s  . c o  m

    QueryResponse resp = query(getDefaultTestClient(), true, ALFRESCO_JSON,
            params("q", "*", "qt", "/afts", "shards.qt", "/afts", "fl", "cm_name, score, [cached]"));
    assertNotNull(resp);
    SolrDocumentList results = resp.getResults();
    SolrDocument docWithAllFields = results.get(0);
    assertTrue(docWithAllFields.size() == 2);
    assertNotNull(docWithAllFields.get("cm_name"));
    Float score = (Float) docWithAllFields.get("score");
    assertNotNull(score);
}

From source file:org.alfresco.solr.transformer.CachedDocTransformerTest.java

License:Open Source License

@Test
public void transformDocument_docTransformerFieldsAndScoreRequested_shouldReturnScoreAndSelectedFields()
        throws Exception {
    putHandleDefaults();// w w w  .  ja  va2  s .com

    QueryResponse resp = query(getDefaultTestClient(), true, ALFRESCO_JSON, params("q", "*", "qt", "/afts",
            "shards.qt", "/afts", "fl", "cm_title, cm_created, DBID, score, [cached]"));
    assertNotNull(resp);
    SolrDocumentList results = resp.getResults();
    SolrDocument docWithAllFields = results.get(0);
    assertTrue(docWithAllFields.size() == 4);
    assertNotNull(docWithAllFields.get("cm_title"));
    assertNotNull(docWithAllFields.get("cm_created"));
    assertNotNull(docWithAllFields.get("score"));
    assertNotNull(docWithAllFields.get("DBID"));
}

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 w w  w . j  ava2s. com
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)
 *///from ww w.j  ava 2s  .  co  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");
}