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


Java SolrIndexSearcher.search方法代码示例

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


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

示例1: testOverwrite

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
@Test
public void testOverwrite() throws IOException{
  assertU(add(
    nest(doc("id","X", parent, "X"), 
           doc(child,"a", "id", "66"), 
           doc(child,"b", "id", "66"))));
  assertU(add(
    nest(doc("id","Y", parent, "Y"), 
           doc(child,"a", "id", "66"), 
           doc(child,"b", "id", "66"))));
  String overwritten = random().nextBoolean() ? "X": "Y";
  String dubbed = overwritten=="X" ? "Y":"X";
  
  assertU(add(
      nest(doc("id",overwritten, parent, overwritten), 
             doc(child,"c","id", "66"), 
             doc(child,"d","id", "66")), "overwrite", "true"));
  assertU(add(
      nest(doc("id",dubbed, parent, dubbed), 
             doc(child,"c","id", "66"), 
             doc(child,"d","id", "66")), "overwrite", "false"));
  
  assertU(commit());
  
  assertQ(req(parent+":"+overwritten, "//*[@numFound='1']"));
  assertQ(req(parent+":"+dubbed, "//*[@numFound='2']"));
  
  final SolrIndexSearcher searcher = getSearcher();
  assertSingleParentOf(searcher, one("ab"), dubbed);
  
  final TopDocs docs = searcher.search(join(one("cd")), 10);
  assertEquals(2, docs.totalHits);
  final String pAct = searcher.doc(docs.scoreDocs[0].doc).get(parent)+
                      searcher.doc(docs.scoreDocs[1].doc).get(parent);
  assertTrue(pAct.contains(dubbed) && pAct.contains(overwritten) && pAct.length()==2);
  
  assertQ(req("id:66", "//*[@numFound='6']"));
  assertQ(req(child+":(a b)", "//*[@numFound='2']"));
  assertQ(req(child+":(c d)", "//*[@numFound='4']"));
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:AddBlockUpdateTest.java

示例2: assertSingleParentOf

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
protected void assertSingleParentOf(final SolrIndexSearcher searcher,
    final String childTerm, String parentExp) throws IOException {
  final TopDocs docs = searcher.search(join(childTerm), 10);
  assertEquals(1, docs.totalHits);
  final String pAct = searcher.doc(docs.scoreDocs[0].doc).get(parent);
  assertEquals(parentExp, pAct);
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:AddBlockUpdateTest.java

示例3: getGroupedCounts

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher,
                                           DocSet base,
                                           String field,
                                           boolean multiToken,
                                           int offset,
                                           int limit,
                                           int mincount,
                                           boolean missing,
                                           String sort,
                                           String prefix,
                                           Predicate<BytesRef> termFilter) throws IOException {
  GroupingSpecification groupingSpecification = rb.getGroupingSpec();
  final String groupField  = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  BytesRef prefixBytesRef = prefix != null ? new BytesRef(prefix) : null;
  final TermGroupFacetCollector collector = TermGroupFacetCollector.createTermGroupFacetCollector(groupField, field, multiToken, prefixBytesRef, 128);
  
  Collector groupWrapper = getInsanityWrapper(groupField, collector);
  Collector fieldWrapper = getInsanityWrapper(field, groupWrapper);
  // When GroupedFacetCollector can handle numerics we can remove the wrapped collectors
  searcher.search(base.getTopFilter(), fieldWrapper);
  
  boolean orderByCount = sort.equals(FacetParams.FACET_SORT_COUNT) || sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY);
  TermGroupFacetCollector.GroupedFacetResult result 
    = collector.mergeSegmentResults(limit < 0 ? Integer.MAX_VALUE : 
                                    (offset + limit), 
                                    mincount, orderByCount);

  CharsRefBuilder charsRef = new CharsRefBuilder();
  FieldType facetFieldType = searcher.getSchema().getFieldType(field);
  NamedList<Integer> facetCounts = new NamedList<>();
  List<TermGroupFacetCollector.FacetEntry> scopedEntries 
    = result.getFacetEntries(offset, limit < 0 ? Integer.MAX_VALUE : limit);
  for (TermGroupFacetCollector.FacetEntry facetEntry : scopedEntries) {
    //:TODO:can we filter earlier than this to make it more efficient?
    if (termFilter != null && !termFilter.test(facetEntry.getValue())) {
      continue;
    }
    facetFieldType.indexedToReadable(facetEntry.getValue(), charsRef);
    facetCounts.add(charsRef.toString(), facetEntry.getCount());
  }

  if (missing) {
    facetCounts.add(null, result.getTotalMissingCount());
  }

  return facetCounts;
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:55,代码来源:SimpleFacets.java

示例4: getGroupedCounts

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher,
                                           DocSet base,
                                           String field,
                                           boolean multiToken,
                                           int offset,
                                           int limit,
                                           int mincount,
                                           boolean missing,
                                           String sort,
                                           String prefix) throws IOException {
  GroupingSpecification groupingSpecification = rb.getGroupingSpec();
  String groupField  = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  BytesRef prefixBR = prefix != null ? new BytesRef(prefix) : null;
  TermGroupFacetCollector collector = TermGroupFacetCollector.createTermGroupFacetCollector(groupField, field, multiToken, prefixBR, 128);
  searcher.search(new MatchAllDocsQuery(), base.getTopFilter(), collector);
  boolean orderByCount = sort.equals(FacetParams.FACET_SORT_COUNT) || sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY);
  TermGroupFacetCollector.GroupedFacetResult result 
    = collector.mergeSegmentResults(limit < 0 ? Integer.MAX_VALUE : 
                                    (offset + limit), 
                                    mincount, orderByCount);

  CharsRef charsRef = new CharsRef();
  FieldType facetFieldType = searcher.getSchema().getFieldType(field);
  NamedList<Integer> facetCounts = new NamedList<>();
  List<TermGroupFacetCollector.FacetEntry> scopedEntries 
    = result.getFacetEntries(offset, limit < 0 ? Integer.MAX_VALUE : limit);
  for (TermGroupFacetCollector.FacetEntry facetEntry : scopedEntries) {
    facetFieldType.indexedToReadable(facetEntry.getValue(), charsRef);
    facetCounts.add(charsRef.toString(), facetEntry.getCount());
  }

  if (missing) {
    facetCounts.add(null, result.getTotalMissingCount());
  }

  return facetCounts;
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:SimpleFacets.java

示例5: testDocListConversion

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
@Test
public void testDocListConversion() throws Exception {
  assertU("", adoc("id", "3234", "val_i", "1", 
                   "val_dynamic", "quick red fox"));
  assertU("", adoc("id", "3235", "val_i", "1", 
                   "val_dynamic", "quick green fox"));
  assertU("", adoc("id", "3236", "val_i", "1", 
                   "val_dynamic", "quick brown fox"));
  assertU("", commit());

  RefCounted<SolrIndexSearcher> holder = h.getCore().getSearcher();
  try {
    SolrIndexSearcher srchr = holder.get();
    SolrIndexSearcher.QueryResult qr = new SolrIndexSearcher.QueryResult();
    SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand();
    cmd.setQuery(new MatchAllDocsQuery());
    cmd.setLen(10);
    qr = srchr.search(qr, cmd);
    
    DocList docs = qr.getDocList();
    assertEquals("wrong docs size", 3, docs.size());
    Set<String> fields = new HashSet<>();
    fields.add("val_dynamic");
    fields.add("dynamic_val");
    fields.add("range_facet_l"); // copied from id
    
    SolrDocumentList list = SolrPluginUtils.docListToSolrDocumentList(docs, srchr, fields, null);
    assertEquals("wrong list Size", docs.size(), list.size());
    for (SolrDocument document : list) {
      
      assertTrue("unexpected field", ! document.containsKey("val_i"));
      assertTrue("unexpected id field", ! document.containsKey("id"));

      assertTrue("original field", document.containsKey("val_dynamic"));
      assertTrue("dyn copy field", document.containsKey("dynamic_val"));
      assertTrue("copy field", document.containsKey("range_facet_l"));
      
      assertNotNull("original field null", document.get("val_dynamic"));
      assertNotNull("dyn copy field null", document.get("dynamic_val"));
      assertNotNull("copy field null", document.get("range_facet_l"));
    }
  } finally {
    if (null != holder) holder.decref();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:46,代码来源:SolrPluginUtilsTest.java


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