当前位置: 首页>>代码示例>>Java>>正文


Java SolrDocumentList.get方法代码示例

本文整理汇总了Java中org.apache.solr.common.SolrDocumentList.get方法的典型用法代码示例。如果您正苦于以下问题:Java SolrDocumentList.get方法的具体用法?Java SolrDocumentList.get怎么用?Java SolrDocumentList.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.SolrDocumentList的用法示例。


在下文中一共展示了SolrDocumentList.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createListIdentifiers

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * for the server request ?verb=ListIdentifiers this method build the xml section
 * 
 * @param handler
 * @param firstRow
 * @param numRows
 * @return
 * @throws SolrServerException
 */
public Element createListIdentifiers(RequestHandler handler, int firstRow, int numRows) throws SolrServerException {
    Map<String, String> datestamp = filterDatestampFromRequest(handler);
    SolrDocumentList listIdentifiers = solr.getListIdentifiers(datestamp, firstRow, numRows, false);
    if (listIdentifiers == null || listIdentifiers.isEmpty()) {
        return new ErrorCode().getNoRecordsMatch();
    }

    Namespace xmlns = DataManager.getInstance().getConfiguration().getStandardNameSpace();
    Element xmlListIdentifiers = new Element("ListIdentifiers", xmlns);
    long totalHits = listIdentifiers.getNumFound();
    for (int i = 0; i < listIdentifiers.size(); i++) {
        SolrDocument doc = listIdentifiers.get(i);
        Element header = getHeader(doc, null, handler);
        xmlListIdentifiers.addContent(header);
    }

    // Create resumption token
    if (totalHits > firstRow + numRows) {
        Element resumption = createResumptionTokenAndElement(totalHits, firstRow + numRows, xmlns, handler);
        xmlListIdentifiers.addContent(resumption);
    }

    return xmlListIdentifiers;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:34,代码来源:XMLGeneration.java

示例2: prepareUpdate

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * Prepares the given record for an update. Creation timestamp is preserved. A new update timestamp is added, child docs are removed.
 * 
 * @param indexObj {@link IndexObject}
 * @throws IOException -
 * @throws SolrServerException
 * @throws FatalIndexerException
 */
private void prepareUpdate(IndexObject indexObj) throws IOException, SolrServerException, FatalIndexerException {
    String pi = indexObj.getPi().trim();
    SolrDocumentList hits = hotfolder.getSolrHelper().search(SolrConstants.PI + ":" + pi, null);
    if (hits != null && hits.getNumFound() > 0) {
        logger.debug("This file has already been indexed, initiating an UPDATE instead...");
        indexObj.setUpdate(true);
        SolrDocument doc = hits.get(0);
        // Set creation timestamp, if exists (should never be updated)
        Object dateCreated = doc.getFieldValue(SolrConstants.DATECREATED);
        if (dateCreated != null) {
            // Set creation timestamp, if exists (should never be updated)
            indexObj.setDateCreated((Long) dateCreated);
        }
        // Set update timestamp
        Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
        if (dateUpdatedValues != null) {
            for (Object date : dateUpdatedValues) {
                indexObj.getDateUpdated().add((Long) date);
            }
        }
        // Recursively delete all children
        deleteWithPI(pi, false, hotfolder.getSolrHelper());
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:33,代码来源:LidoIndexer.java

示例3: getSolrDocument

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
public SolrDocument getSolrDocument(String docId) {
    if (docId == null) {
        throw new NullPointerException("Cannot get SOLR document for null docId");
    }
    SolrDocument result = null;
    SolrQuery query = new SolrQuery();
    query.setQuery("id:" + ClientUtils.escapeQueryChars(docId));
    query.setFields("*");
    SolrDocumentList docs = fireQuery(query).getResults();
    if (docs.getNumFound() > 1) {
        logger.error("Error: found multiple documents for id (will return first one): " + docId + " \nDocuments found: " + docs);
        result = docs.get(0);
    } else if (docs.getNumFound() == 1) {
        result = docs.get(0);
    }
    return result;
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:18,代码来源:SolrDaoImpl.java

示例4: assertQ

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
protected void assertQ(String query, int expectedCount, String... expectedFields)
    throws SolrServerException, IOException {

  SolrQuery solrQuery = new SolrQuery();
  solrQuery.setQuery(query);

  QueryResponse rsp = cloudSolrClient.query(solrQuery);
  SolrDocumentList docs = rsp.getResults();
  assertEquals(expectedCount, docs.size());
  log.info("docs: " + docs.toString());

  if (docs.isEmpty()) {
    fail("No results for query " + query);
  }

  SolrDocument doc = docs.get(0);
  if (expectedFields != null) {
    for (int counter = 0; counter < expectedFields.length; counter += 2) {
      assertTrue(
          doc.getFieldValue(expectedFields[counter]).toString() + " != " + expectedFields[counter
              + 1], doc.getFieldValue(expectedFields[counter]).toString()
              .equals(expectedFields[counter + 1]));
    }
  }
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:26,代码来源:SolrCloudClusterSupport.java

示例5: assertFieldValues

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * Fails if the number of documents in the given SolrDocumentList differs
 * from the given number of expected values, or if any of the values in the
 * given field don't match the expected values in the same order.
 */
public static void assertFieldValues(SolrDocumentList documents, String fieldName, Object... expectedValues) {
  if (documents.size() != expectedValues.length) {
    fail("Number of documents (" + documents.size()
        + ") is different from number of expected values (" + expectedValues.length);
  }
  for (int docNum = 1 ; docNum <= documents.size() ; ++docNum) {
    SolrDocument doc = documents.get(docNum - 1);
    Object expected = expectedValues[docNum - 1];
    Object actual = doc.get(fieldName);
    if ((null == expected && null != actual) ||
        (null != expected && null == actual) ||
        (null != expected && null != actual && !expected.equals(actual))) {
      fail("Unexpected " + fieldName + " field value in document #" + docNum
          + ": expected=[" + expected + "], actual=[" + actual + "]");
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:SolrTestCaseJ4.java

示例6: testSimple

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
@Test
public void testSimple() throws Exception {
  DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml);
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set("command", "full-import");
  params.set("clean", "false");
  req.setParams(params);
  HttpSolrServer solrServer = new HttpSolrServer(buildUrl(jetty.getLocalPort(), "/solr"));
  solrServer.request(req);
  ModifiableSolrParams qparams = new ModifiableSolrParams();
  qparams.add("q", "*:*");
  QueryResponse qres = solrServer.query(qparams);
  SolrDocumentList results = qres.getResults();
  assertEquals(2, results.getNumFound());
  SolrDocument doc = results.get(0);
  assertEquals("1", doc.getFieldValue("id"));
  assertEquals("Hello C1", ((List)doc.getFieldValue("desc")).get(0));
  solrServer.shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestContentStreamDataSource.java

示例7: assertExpandGroupCountAndOrder

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
private void assertExpandGroupCountAndOrder(String group, int count, Map<String, SolrDocumentList>expandedResults, String... docs) throws Exception {
  SolrDocumentList results = expandedResults.get(group);
  if(results == null) {
    throw new Exception("Group Not Found:"+group);
  }

  if(results.size() != count) {
    throw new Exception("Expected Count "+results.size()+" Not Found:"+count);
  }

  for(int i=0; i<docs.length;i++) {
    String id = docs[i];
    SolrDocument doc = results.get(i);
    if(!doc.getFieldValue("id").toString().equals(id)) {
      throw new Exception("Id not in results or out of order:"+id+"!="+doc.getFieldValue("id"));
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:DistributedExpandComponentTest.java

示例8: prepareUpdate

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * Prepares the given record for an update. Creation timestamp and representative thumbnail and anchor IDDOC are preserved. A new update timestamp
 * is added, child docs are removed.
 * 
 * @param indexObj {@link IndexObject}
 * @throws IOException
 * @throws SolrServerException
 * @throws FatalIndexerException
 * @should keep creation timestamp
 * @should set update timestamp correctly
 * @should keep representation thumbnail
 * @should keep anchor IDDOC
 * @should delete anchor secondary docs
 */
protected void prepareUpdate(IndexObject indexObj) throws IOException, SolrServerException, FatalIndexerException {
    String pi = indexObj.getPi().trim();
    SolrDocumentList hits = hotfolder.getSolrHelper().search(SolrConstants.PI + ":" + pi, null);
    if (hits != null && hits.getNumFound() > 0) {
        logger.debug("This file has already been indexed, initiating an UPDATE instead...");
        indexObj.setUpdate(true);
        SolrDocument doc = hits.get(0);
        // Set creation timestamp, if exists (should never be updated)
        Object dateCreated = doc.getFieldValue(SolrConstants.DATECREATED);
        if (dateCreated != null) {
            // Set creation timestamp, if exists (should never be updated)
            indexObj.setDateCreated((Long) dateCreated);
        }
        // Set update timestamp
        Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
        if (dateUpdatedValues != null) {
            for (Object date : dateUpdatedValues) {
                indexObj.getDateUpdated().add((Long) date);
            }
        }
        // Set previous representation thumbnail, if available
        Object thumbnail = doc.getFieldValue(SolrConstants.THUMBNAILREPRESENT);
        if (thumbnail != null) {
            indexObj.setThumbnailRepresent((String) thumbnail);
        }

        // Recursively delete all children, if not an anchor
        deleteWithPI(pi, false, hotfolder.getSolrHelper());
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:45,代码来源:WorldViewsIndexer.java

示例9: checkAndCreateGroupDoc

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * 
 * @param groupIdField Field name of the group identifier.
 * @param groupId Field value of the group identifier.
 * @param metadata Map with additional metadat fields to add to the group document.
 * @param iddoc IDDOC for the new document.
 * @return Group SolrInputDocument, if created.
 * @should create new document with all values if none exists
 * @should create updated document with all values if one already exists
 */
public SolrInputDocument checkAndCreateGroupDoc(String groupIdField, String groupId, Map<String, String> metadata, long iddoc) {
    try {
        SolrDocumentList docs = search(SolrConstants.PI + ":" + groupId, null);
        SolrInputDocument doc = new SolrInputDocument();
        Date now = new Date();
        if (docs.isEmpty()) {
            // Document does not exist yet
            doc.setField(SolrConstants.IDDOC, String.valueOf(iddoc));
            doc.setField(SolrConstants.GROUPFIELD, String.valueOf(iddoc));
            doc.setField(SolrConstants.DOCTYPE, DocType.GROUP.name());
            doc.setField(SolrConstants.DATECREATED, now.getTime());
        } else {
            // A document already exists for this groupId
            SolrDocument oldDoc = docs.get(0);
            doc.setField(SolrConstants.IDDOC, oldDoc.getFieldValue(SolrConstants.IDDOC));
            if (doc.getField(SolrConstants.GROUPFIELD) == null) {
                doc.setField(SolrConstants.GROUPFIELD, oldDoc.getFieldValue(SolrConstants.IDDOC));
            }
            doc.setField(SolrConstants.DOCTYPE, DocType.GROUP.name());
            doc.setField(SolrConstants.DATECREATED, oldDoc.getFieldValue(SolrConstants.DATECREATED));
        }
        doc.setField(SolrConstants.DATEUPDATED, now.getTime());
        doc.setField(SolrConstants.PI, groupId);
        doc.setField(SolrConstants.PI_TOPSTRUCT, groupId);
        doc.setField(SolrConstants.GROUPTYPE, groupIdField);
        if (metadata != null) {
            for (String fieldName : metadata.keySet()) {
                String fieldValue = metadata.get(fieldName);
                doc.setField(fieldName, fieldValue);
            }
        }
        return doc;
    } catch (SolrServerException e) {
        logger.error(e.getMessage(), e);
    }

    return null;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:49,代码来源:SolrHelper.java

示例10: getDocument

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
@Override
public SolrDocument getDocument(String docId) {
    final SolrQuery query = queryFatory.createDocumentQuery(docId);
    final SolrDocumentList result = searchResultsDao.getDocuments(query);
    if (result.size() < 1) {
        return null;
    } else {
        logger.debug("Document with docId {} retrieved:", result);
        return result.get(0);
    }
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:12,代码来源:SolrDocumentServiceImpl.java

示例11: indexModel_sampleModel_shouldIndexAllModelSplits

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
@Test
public void indexModel_sampleModel_shouldIndexAllModelSplits() throws IOException, SolrServerException {
    String sampleModelsDirPath = getResourcePath();
    String modelJson = "lambdaMARTModel1.json";

    modelIndexerToTest.indexModel(sampleModelsDirPath + "/" + modelJson);

    final QueryResponse allDocs = embeddedSolrServer.query(new SolrQuery("*:*"));
    final SolrDocumentList results = allDocs.getResults();

    assertThat(results.getNumFound(),is(4L));

    final SolrDocument split1 = results.get(0);
    assertThat(split1.getFieldValue(SolrFields.Models.MODEL_NAME),is("lambdaMARTModel1"));
    assertThat(split1.getFieldValue(SolrFields.Models.FEATURE),is("feature1"));
    assertThat(split1.getFieldValue(SolrFields.Models.THRESHOLD),is(0.5));

    final SolrDocument split2 = results.get(1);
    assertThat(split2.getFieldValue(SolrFields.Models.MODEL_NAME),is("lambdaMARTModel1"));
    assertThat(split2.getFieldValue(SolrFields.Models.FEATURE),is("feature2"));
    assertThat(split2.getFieldValue(SolrFields.Models.THRESHOLD),is(10.0));

    final SolrDocument split3 = results.get(2);
    assertThat(split3.getFieldValue(SolrFields.Models.MODEL_NAME),is("lambdaMARTModel1"));
    assertThat(split3.getFieldValue(SolrFields.Models.FEATURE),is("feature2"));
    assertThat(split3.getFieldValue(SolrFields.Models.THRESHOLD),is(0.8));

    final SolrDocument split4 = results.get(3);
    assertThat(split4.getFieldValue(SolrFields.Models.MODEL_NAME),is("lambdaMARTModel1"));
    assertThat(split4.getFieldValue(SolrFields.Models.FEATURE),is("feature1"));
    assertThat(split4.getFieldValue(SolrFields.Models.THRESHOLD),is(100.0));

}
 
开发者ID:alessandrobenedetti,项目名称:ltr-tools,代码行数:34,代码来源:ModelIndexerTest.java

示例12: indexTrainingSet_noFeatureMappingSpecified_shouldIndexPlainFeaturesNames

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
@Test
public void indexTrainingSet_noFeatureMappingSpecified_shouldIndexPlainFeaturesNames() throws IOException, SolrServerException {
    String sampleModelsDirPath = getResourcePath();
    String trainingSet="trainingSet1";

    trainingSetIndexerToTest.indexTrainingSet(sampleModelsDirPath+"/"+trainingSet,null,null);

    final QueryResponse allDocs = embeddedSolrServer.query(new SolrQuery("*:*"));
    final SolrDocumentList results = allDocs.getResults();

    assertThat(results.getNumFound(),is(4L));

    final SolrDocument sample1 = results.get(0);
    assertThat(sample1.getFieldValue(SolrFields.TrainingSet.RELEVANCY),is(1.0));
    assertThat(sample1.getFieldValue("1"),is(300.0));
    assertThat(sample1.getFieldValue("2"),is(4.0));
    assertThat(sample1.getFieldValue("3"),is(1.0));
    assertThat(sample1.getFieldValue("6"),is(1.0));

    final SolrDocument sample2 = results.get(1);
    assertThat(sample2.getFieldValue(SolrFields.TrainingSet.RELEVANCY),is(4.0));
    assertThat(sample2.getFieldValue("1"),is(250.0));
    assertThat(sample2.getFieldValue("2"),is(4.5));
    assertThat(sample2.getFieldValue("4"),is(1.0));
    assertThat(sample2.getFieldValue("7"),is(1.0));

    final SolrDocument sample3 = results.get(2);
    assertThat(sample3.getFieldValue(SolrFields.TrainingSet.RELEVANCY),is(5.0));
    assertThat(sample3.getFieldValue("1"),is(450.0));
    assertThat(sample3.getFieldValue("2"),is(5.0));
    assertThat(sample3.getFieldValue("5"),is(1.0));
    assertThat(sample3.getFieldValue("6"),is(1.0));

    final SolrDocument sample4 = results.get(3);
    assertThat(sample4.getFieldValue(SolrFields.TrainingSet.RELEVANCY),is(2.0));
    assertThat(sample4.getFieldValue("1"),is(200.0));
    assertThat(sample4.getFieldValue("2"),is(3.5));
    assertThat(sample4.getFieldValue("3"),is(1.0));
    assertThat(sample4.getFieldValue("8"),is(1.0));
}
 
开发者ID:alessandrobenedetti,项目名称:ltr-tools,代码行数:41,代码来源:TrainingSetIndexerTest.java

示例13: doBoltActionTest

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
protected void doBoltActionTest() throws Exception {
  // Spring @Autowired property at runtime
  SolrBoltAction sba = new SolrBoltAction(cloudSolrClient);
  sba.setUpdateRequestStrategy(new DefaultUpdateRequestStrategy());
  sba.setMaxBufferSize(1); // to avoid buffering docs

  // Mock the Storm tuple
  String docId = "1";
  TestDoc testDoc = new TestDoc(docId, "foo", 10);
  Tuple mockTuple = mock(Tuple.class);
  when(mockTuple.size()).thenReturn(2);
  when(mockTuple.getString(0)).thenReturn(docId);
  when(mockTuple.getValue(1)).thenReturn(testDoc);
  SpringBolt.ExecuteResult result = sba.execute(mockTuple, null);
  assertTrue(result == SpringBolt.ExecuteResult.ACK);
  cloudSolrClient.commit();

  // verify the object to Solr mapping worked correctly using reflection and dynamic fields
  SolrQuery query = new SolrQuery("id:" + docId);
  QueryResponse qr = cloudSolrClient.query(query);
  SolrDocumentList results = qr.getResults();
  assertTrue(results.getNumFound() == 1);
  SolrDocument doc = results.get(0);
  assertNotNull(doc);
  assertEquals("foo", doc.getFirstValue("text_s"));
  assertEquals(new Integer(testDoc.number), doc.getFirstValue("number_i"));
  assertTrue(doc.getFirstValue("timestamp_tdt") != null);
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:29,代码来源:SolrBoltActionTest.java

示例14: doNestedDocTest

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
protected void doNestedDocTest() throws Exception {
  SolrBoltAction sba = new SolrBoltAction(cloudSolrClient);
  sba.setSolrInputDocumentMapper(new NestedDocumentMapper());
  sba.setUpdateRequestStrategy(new DefaultUpdateRequestStrategy());
  sba.setMaxBufferSize(1); // to avoid buffering docs

  String docId = "1";

  JSONArray jsonDocs = NestedDocumentMapperTest.loadNestedDocs();
  Tuple mockTuple = mock(Tuple.class);
  when(mockTuple.size()).thenReturn(2);
  when(mockTuple.getString(0)).thenReturn(docId);
  when(mockTuple.getValue(1)).thenReturn(jsonDocs.get(0));

  SpringBolt.ExecuteResult result = sba.execute(mockTuple, null);
  assertTrue(result == SpringBolt.ExecuteResult.ACK);
  cloudSolrClient.commit();

  // verify the object to Solr mapping worked correctly using reflection and dynamic fields
  SolrQuery query = new SolrQuery("id:" + docId);
  query.set("fl", "*,[child parentFilter=id:"+docId+" limit=100]");
  QueryResponse qr = cloudSolrClient.query(query);
  SolrDocumentList results = qr.getResults();
  assertTrue(results.getNumFound() == 1);
  SolrDocument doc = results.get(0);
  assertNotNull(doc);

  System.out.println("\n\n>> doc: "+doc+"\n\n");
  if (doc.hasChildDocuments()) {
    for (SolrDocument child : doc.getChildDocuments()) {
      System.out.println("\n>> "+child+"\n");
    }
  } else {
    System.out.println("no child documents returned");
  }

}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:38,代码来源:SolrBoltActionTest.java

示例15: assertOrder

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
private void assertOrder(QueryResponse rsp, String ... docs) throws Exception {
  SolrDocumentList list = rsp.getResults();
  for(int i=0; i<docs.length; i++) {
    SolrDocument doc = list.get(i);
    Object o = doc.getFieldValue("id");
    if(!docs[i].equals(o)) {
      throw new Exception("Order is not correct:"+o+"!="+docs[i]);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:MergeStrategyTest.java


注:本文中的org.apache.solr.common.SolrDocumentList.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。