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


Java SolrDocumentList.setStart方法代码示例

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


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

示例1: getDocs

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
private SolrDocumentList getDocs(int start, int rows) {
  SolrDocumentList docs = new SolrDocumentList();
  docs.setNumFound(docsData.size());
  docs.setStart(start);

  int endIndex = start + rows;
  int end = docsData.size() < endIndex ? docsData.size() : endIndex;
  for (int i = start; i < end; i++) {
    SolrDocument doc = new SolrDocument();
    SolrTestCaseJ4.Doc testDoc = docsData.get(i);
    doc.addField("id", testDoc.id);
    doc.addField("description", testDoc.getValues("description"));
    docs.add(doc);
  }
  return docs;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:MockSolrEntityProcessor.java

示例2: transform

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void transform(Map<String, ?> result, ResponseBuilder rb, SolrDocumentSource solrDocumentSource) {
  Object value = result.get(rb.getGroupingSpec().getFields()[0]);
  if (TopGroups.class.isInstance(value)) {
    @SuppressWarnings("unchecked")
    TopGroups<BytesRef> topGroups = (TopGroups<BytesRef>) value;
    SolrDocumentList docList = new SolrDocumentList();
    docList.setStart(rb.getGroupingSpec().getOffset());
    docList.setNumFound(rb.totalHitCount);

    Float maxScore = Float.NEGATIVE_INFINITY;
    for (GroupDocs<BytesRef> group : topGroups.groups) {
      for (ScoreDoc scoreDoc : group.scoreDocs) {
        if (maxScore < scoreDoc.score) {
          maxScore = scoreDoc.score;
        }
        docList.add(solrDocumentSource.retrieve(scoreDoc));
      }
    }
    if (maxScore != Float.NEGATIVE_INFINITY) {
      docList.setMaxScore(maxScore);
    }
    rb.rsp.add("response", docList);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:MainEndResultTransformer.java

示例3: mergeDistributedResultsIntSingleResponse

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
private void mergeDistributedResultsIntSingleResponse(ResponseBuilder rb, List<AcGroupResult> resultsToMerge, String responseTagName) {
  int docs = 0;
  float maxScore = 0.0f;
  
  // if groups have to be displayed in some custom order, other than the order specified in 
  // ac_grouping_field_def
  String groupingSort = rb.req.getParams().get(AC_GROUPING_SORT_PARAM_NAME);
  if (groupSorts.containsKey(groupingSort)) {
    groupSorts.get(groupingSort).sort(rb, resultsToMerge);
  }
  
  SolrDocumentList docList = new SolrDocumentList();
  // first find count of documents
  for (AcGroupResult acGroupResult : resultsToMerge) {
    // if slice contains more results than requested, take requested count; if it contains less results than
    // requested, we have to take what we got, not more
    docs += ((acGroupResult.getDistributedResultingDocs().size() > acGroupResult.getAcGroupingFieldValue().getRequestedCountOfSuggestions() == true) ? 
        acGroupResult.getAcGroupingFieldValue().getRequestedCountOfSuggestions() : acGroupResult.getDistributedResultingDocs().size());
    
    if (acGroupResult.getDistributedResultingDocs().getMaxScore() > maxScore) {
      maxScore = acGroupResult.getDistributedResultingDocs().getMaxScore();
    }
    
    docList.addAll(acGroupResult.getDistributedResultingDocs());
  }
  
  docList.setStart(0);
  docList.setNumFound(docs);

  rb.rsp.add(responseTagName, docList);
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:32,代码来源:AutoCompleteSearchComponent.java

示例4: readDocuments

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
protected SolrDocumentList readDocuments( XMLStreamReader parser ) throws XMLStreamException
{
  SolrDocumentList docs = new SolrDocumentList();

  // Parse the attributes
  for( int i=0; i<parser.getAttributeCount(); i++ ) {
    String n = parser.getAttributeLocalName( i );
    String v = parser.getAttributeValue( i );
    if( "numFound".equals( n ) ) {
      docs.setNumFound( Long.parseLong( v ) );
    }
    else if( "start".equals( n ) ) {
      docs.setStart( Long.parseLong( v ) );
    }
    else if( "maxScore".equals( n ) ) {
      docs.setMaxScore( Float.parseFloat( v ) );
    }
  }
  
  // Read through each document
  int event;
  while( true ) {
    event = parser.next();
    if( XMLStreamConstants.START_ELEMENT == event ) {
      if( !"doc".equals( parser.getLocalName() ) ) {
        throw new RuntimeException( "should be doc! "+parser.getLocalName() + " :: " + parser.getLocation() );
      }
      docs.add( readDocument( parser ) );
    }
    else if ( XMLStreamConstants.END_ELEMENT == event ) {
      return docs;  // only happens once
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:XMLResponseParser.java

示例5: readSolrDocumentList

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
public SolrDocumentList readSolrDocumentList(DataInputInputStream dis) throws IOException {
  SolrDocumentList solrDocs = new SolrDocumentList();
  List list = (List) readVal(dis);
  solrDocs.setNumFound((Long) list.get(0));
  solrDocs.setStart((Long) list.get(1));
  solrDocs.setMaxScore((Float) list.get(2));

  @SuppressWarnings("unchecked")
  List<SolrDocument> l = (List<SolrDocument>) readVal(dis);
  solrDocs.addAll(l);
  return solrDocs;
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:JavaBinCodec.java

示例6: transform

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void transform(Map<String, ?> result, ResponseBuilder rb, SolrDocumentSource solrDocumentSource) {
  NamedList<Object> commands = new SimpleOrderedMap<>();
  for (Map.Entry<String, ?> entry : result.entrySet()) {
    Object value = entry.getValue();
    if (TopGroups.class.isInstance(value)) {
      @SuppressWarnings("unchecked")
      TopGroups<BytesRef> topGroups = (TopGroups<BytesRef>) value;
      NamedList<Object> command = new SimpleOrderedMap<>();
      command.add("matches", rb.totalHitCount);
      if (topGroups.totalGroupCount != null) {
        command.add("ngroups", topGroups.totalGroupCount);
      }
      SolrDocumentList docList = new SolrDocumentList();
      docList.setStart(rb.getGroupingSpec().getOffset());
      docList.setNumFound(topGroups.totalHitCount);

      Float maxScore = Float.NEGATIVE_INFINITY;
      for (GroupDocs<BytesRef> group : topGroups.groups) {
        for (ScoreDoc scoreDoc : group.scoreDocs) {
          if (maxScore < scoreDoc.score) {
            maxScore = scoreDoc.score;
          }
          docList.add(solrDocumentSource.retrieve(scoreDoc));
        }
      }
      if (maxScore != Float.NEGATIVE_INFINITY) {
        docList.setMaxScore(maxScore);
      }
      command.add("doclist", docList);
      commands.add(entry.getKey(), command);
    }
  }

  rb.rsp.add("grouped", commands);
}
 
开发者ID:europeana,项目名称:search,代码行数:40,代码来源:SimpleEndResultTransformer.java

示例7: testJSONSolrDocument

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
@Test
public void testJSONSolrDocument() throws IOException {
  SolrQueryRequest req = req(CommonParams.WT,"json",
                             CommonParams.FL,"id,score");
  SolrQueryResponse rsp = new SolrQueryResponse();
  JSONResponseWriter w = new JSONResponseWriter();

  ReturnFields returnFields = new SolrReturnFields(req);
  rsp.setReturnFields(returnFields);

  StringWriter buf = new StringWriter();

  SolrDocument solrDoc = new SolrDocument();
  solrDoc.addField("id", "1");
  solrDoc.addField("subject", "hello2");
  solrDoc.addField("title", "hello3");
  solrDoc.addField("score", "0.7");

  SolrDocumentList list = new SolrDocumentList();
  list.setNumFound(1);
  list.setStart(0);
  list.setMaxScore(0.7f);
  list.add(solrDoc);

  rsp.add("response", list);

  w.write(buf, req, rsp);
  String result = buf.toString();
  assertFalse("response contains unexpected fields: " + result, 
              result.contains("hello") || 
              result.contains("\"subject\"") || 
              result.contains("\"title\""));
  assertTrue("response doesn't contain expected fields: " + result, 
             result.contains("\"id\"") &&
             result.contains("\"score\""));


  req.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:40,代码来源:JSONWriterTest.java

示例8: generateAllDataTypes

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
private List<Object> generateAllDataTypes() {
  List<Object> types = new ArrayList<>();

  types.add(null); //NULL
  types.add(true);
  types.add(false);
  types.add((byte) 1);
  types.add((short) 2);
  types.add((double) 3);

  types.add(-4);
  types.add(4);
  types.add(42);

  types.add((long) -5);
  types.add((long) 5);
  types.add((long) 50);

  types.add((float) 6);
  types.add(new Date(0));

  Map<Integer, Integer> map = new HashMap<>();
  map.put(1, 2);
  types.add(map);

  SolrDocument doc = new SolrDocument();
  doc.addField("foo", "bar");
  types.add(doc);

  SolrDocumentList solrDocs = new SolrDocumentList();
  solrDocs.setMaxScore(1.0f);
  solrDocs.setNumFound(1);
  solrDocs.setStart(0);
  solrDocs.add(0, doc);
  types.add(solrDocs);

  types.add(new byte[] {1,2,3,4,5});

  // TODO?
  // List<String> list = new ArrayList<String>();
  // list.add("one");
  // types.add(list.iterator());

  types.add((byte) 15); //END

  SolrInputDocument idoc = new SolrInputDocument();
  idoc.addField("foo", "bar");
  types.add(idoc);

  SolrInputDocument parentDoc = new SolrInputDocument();
  parentDoc.addField("foo", "bar");
  SolrInputDocument childDoc = new SolrInputDocument();
  childDoc.addField("foo", "bar");
  parentDoc.addChildDocument(childDoc);
  types.add(parentDoc);

  types.add(new EnumFieldValue(1, "foo"));

  types.add(map.entrySet().iterator().next()); //Map.Entry

  types.add((byte) (1 << 5)); //TAG_AND_LEN

  types.add("foo");
  types.add(1);
  types.add((long) 2);

  SimpleOrderedMap simpleOrderedMap = new SimpleOrderedMap();
  simpleOrderedMap.add("bar", "barbar");
  types.add(simpleOrderedMap);

  NamedList<String> nl = new NamedList<>();
  nl.add("foo", "barbar");
  types.add(nl);

  return types;
}
 
开发者ID:europeana,项目名称:search,代码行数:77,代码来源:TestJavaBinCodec.java


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