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


Java SolrDocumentList.setNumFound方法代码示例

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


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

示例1: testGetDocumentCount

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * Test of getDocumentCount method, of class SolrDocumentServiceImpl.
 */
@Test
public void testGetDocumentCount() {
    final QueryFacetsSelection selection = new QueryFacetsSelection("query", Collections.<String, FacetSelection>emptyMap());

    final SolrQuery solrQuery = new SolrQuery("query");
    final SolrDocumentList resultList = new SolrDocumentList();
    resultList.setNumFound(42);

    context.checking(new Expectations() {
        {
            oneOf(queryFactory).createDocumentQuery(with(equal(selection)), with(any(Integer.class)), with(any(Integer.class)));
            will(returnValue(solrQuery));
            oneOf(dao).getDocuments(solrQuery);
            will(returnValue(resultList));
        }
    });
    final long result = instance.getDocumentCount(selection);
    assertEquals(42, result);
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:23,代码来源:SolrDocumentServiceImplTest.java

示例2: 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

示例3: getHistory

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
public SolrDocumentList getHistory(long since, AtomicBoolean found) {
  if(history==null) {
    return null;
  }
  
  SolrDocumentList docs = new SolrDocumentList();
  Iterator<E> iter = history.iterator();
  while(iter.hasNext()) {
    E e = iter.next();
    long ts = getTimestamp(e);
    if(ts == since) {
      if(found!=null) {
        found.set(true);
      }
    }
    if(ts>since) {
      docs.add(toSolrDocument(e));
    }
  }
  docs.setNumFound(docs.size()); // make it not look too funny
  return docs;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:LogWatcher.java

示例4: 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

示例5: mergeResponses

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
private void mergeResponses(ResponseBuilder rb) {
  SolrDocumentList docList = new SolrDocumentList();
  
  for (ShardRequest sreq : rb.finished) {
    // if shards=shard1,shard2 was used, then  we query both shards for each id and
    // can get more than one response
    for (ShardResponse srsp : sreq.responses) {
      SolrResponse sr = srsp.getSolrResponse();
      NamedList nl = sr.getResponse();
      SolrDocumentList subList = (SolrDocumentList)nl.get("response");
      docList.addAll(subList);
    }
  }

  if (docList.size() <= 1 && rb.req.getParams().getParams("ids")==null) {
    // if the doc was not found, then use a value of null.
    rb.rsp.add("doc", docList.size() > 0 ? docList.get(0) : null);
  } else {
    docList.setNumFound(docList.size());
    rb.rsp.add("response", docList);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:RealTimeGetComponent.java

示例6: createQueryResponse

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * Creates a query response
 * @param qTime
 * @return
 */
protected QueryResponse createQueryResponse(int qTime) {
	QueryResponse response = new QueryResponse();
	NamedList<Object> headerNamedList = new NamedList<Object>();
	headerNamedList.add("QTime", qTime);
	NamedList<Object> responseNamedList = new NamedList<Object>();
	responseNamedList.add("responseHeader", headerNamedList);
	
	SolrDocumentList resultsNamedList = new SolrDocumentList();
	resultsNamedList.add(new SolrDocument());
	resultsNamedList.add(new SolrDocument());
	resultsNamedList.add(new SolrDocument());
	resultsNamedList.setNumFound(10);
	responseNamedList.add("response", resultsNamedList);
	response.setResponse(responseNamedList);
	return response;
}
 
开发者ID:lafourchette,项目名称:solrmeter,代码行数:22,代码来源:BaseTestCase.java

示例7: 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

示例8: handleRequestBody

import org.apache.solr.common.SolrDocumentList; //导入方法依赖的package包/类
/**
 * Executes the user search request.
 *
 * @param req the solr query request
 * @param rsp the solr query response holding the result
 * @throws Exception if bad things happen
 */
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    LOGGER.debug("Handling analysis request {}", req);
    //First check if the request should return documents => rows > 0
    String rowsParam = req.getParams().get(CommonParams.ROWS, null);
    int rows = -1;
    if (rowsParam != null) {
        rows = Integer.parseInt(rowsParam);
    }

    SolrDocumentList results = new SolrDocumentList();
    String[] chronixFunctions = req.getParams().getParams(ChronixQueryParams.CHRONIX_FUNCTION);
    String chronixJoin = req.getParams().get(ChronixQueryParams.CHRONIX_JOIN);

    //Do a query and collect them on the join function
    JoinFunction key = new JoinFunction(chronixJoin);
    Map<String, List<SolrDocument>> collectedDocs = collectDocuments(req, key);

    //If no rows should returned, we only return the num found
    if (rows == 0) {
        results.setNumFound(collectedDocs.keySet().size());
    } else {
        //Otherwise return the analyzed time series
        final TypeFunctions typeFunctions = QueryEvaluator.extractFunctions(chronixFunctions, TYPES, FUNCTIONS);
        final List<SolrDocument> resultDocuments = analyze(req, typeFunctions, key, collectedDocs, !JoinFunction.isDefaultJoinFunction(key));
        results.addAll(resultDocuments);
        //As we have to analyze all docs in the query at once,
        // the number of documents is also the number of documents found
        results.setNumFound(resultDocuments.size());
    }
    //Add the results to the response
    rsp.add("response", results);
}
 
开发者ID:ChronixDB,项目名称:chronix.server,代码行数:42,代码来源:AnalysisHandler.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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.setNumFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。