• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ReturnFields类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: writeSolrDocument

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
/**
 * The SolrDocument should already have multivalued fields implemented as
 * Collections -- this will not rewrite to <arr>
 */ 
@Override
public void writeSolrDocument(String name, SolrDocument doc, ReturnFields returnFields, int idx ) throws IOException {
  startTag("doc", name, false);
  incLevel();

  for (String fname : doc.getFieldNames()) {
    if (!returnFields.wantsField(fname)) {
      continue;
    }
    
    Object val = doc.getFieldValue(fname);
    if( "_explain_".equals( fname ) ) {
      System.out.println( val );
    }
    writeVal(fname, val);
  }
  
  decLevel();
  writer.write("</doc>");
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:XMLWriter.java


示例2: writeSolrDocument

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
/**
 * The SolrDocument should already have multivalued fields implemented as
 * Collections -- this will not rewrite to &lt;arr&gt;
 */ 
@Override
public void writeSolrDocument(String name, SolrDocument doc, ReturnFields returnFields, int idx ) throws IOException {
  startTag("doc", name, false);
  incLevel();

  for (String fname : doc.getFieldNames()) {
    if (!returnFields.wantsField(fname)) {
      continue;
    }
    
    Object val = doc.getFieldValue(fname);
    if( "_explain_".equals( fname ) ) {
      System.out.println( val );
    }
    writeVal(fname, val);
  }

  if(doc.hasChildDocuments()) {
    for(SolrDocument childDoc : doc.getChildDocuments()) {
      writeSolrDocument(null, childDoc, new SolrReturnFields(), idx);
    }
  }
  
  decLevel();
  writer.write("</doc>");
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:XMLWriter.java


示例3: writeSolrDocumentList

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
public final void writeSolrDocumentList(String name, SolrDocumentList docs, ReturnFields returnFields) throws IOException
{
  writeStartDocumentList(name, docs.getStart(), docs.size(), docs.getNumFound(), docs.getMaxScore() );
  for( int i=0; i<docs.size(); i++ ) {
    writeSolrDocument( null, docs.get(i), returnFields, i );
  }
  writeEndDocumentList();
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:TextResponseWriter.java


示例4: writeDocuments

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
public final void writeDocuments(String name, ResultContext res, ReturnFields fields ) throws IOException {
  DocList ids = res.docs;
  TransformContext context = new TransformContext();
  context.query = res.query;
  context.wantsScores = fields.wantsScore() && ids.hasScores();
  context.req = req;
  writeStartDocumentList(name, ids.offset(), ids.size(), ids.matches(), 
      context.wantsScores ? new Float(ids.maxScore()) : null );
  
  DocTransformer transformer = fields.getTransformer();
  context.searcher = req.getSearcher();
  context.iterator = ids.iterator();
  if( transformer != null ) {
    transformer.setContext( context );
  }
  int sz = ids.size();
  Set<String> fnames = fields.getLuceneFieldNames();
  for (int i=0; i<sz; i++) {
    int id = context.iterator.nextDoc();
    Document doc = context.searcher.doc(id, fnames);
    SolrDocument sdoc = toSolrDocument( doc );
    if( transformer != null ) {
      transformer.transform( sdoc, id);
    }
    writeSolrDocument( null, sdoc, returnFields, i );
  }
  if( transformer != null ) {
    transformer.setContext( null );
  }
  writeEndDocumentList();
}
 
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:TextResponseWriter.java


示例5: optimizePreFetchDocs

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
/**
 * Pre-fetch documents into the index searcher's document cache.
 *
 * This is an entirely optional step which you might want to perform for
 * the following reasons:
 *
 * <ul>
 *     <li>Locates the document-retrieval costs in one spot, which helps
 *     detailed performance measurement</li>
 *
 *     <li>Determines a priori what fields will be needed to be fetched by
 *     various subtasks, like response writing and highlighting.  This
 *     minimizes the chance that many needed fields will be loaded lazily.
 *     (it is more efficient to load all the field we require normally).</li>
 * </ul>
 *
 * If lazy field loading is disabled, this method does nothing.
 */
public static void optimizePreFetchDocs(ResponseBuilder rb,
                                        DocList docs,
                                        Query query,
                                        SolrQueryRequest req,
                                        SolrQueryResponse res) throws IOException {
  SolrIndexSearcher searcher = req.getSearcher();
  if(!searcher.enableLazyFieldLoading) {
    // nothing to do
    return;
  }

  ReturnFields returnFields = res.getReturnFields();
  if(returnFields.getLuceneFieldNames() != null) {
    Set<String> fieldFilter = returnFields.getLuceneFieldNames();

    if (rb.doHighlights) {
      // copy return fields list
      fieldFilter = new HashSet<>(fieldFilter);
      // add highlight fields

      SolrHighlighter highlighter = HighlightComponent.getHighlighter(req.getCore());
      for (String field: highlighter.getHighlightFields(query, req, null))
        fieldFilter.add(field);

      // fetch unique key if one exists.
      SchemaField keyField = searcher.getSchema().getUniqueKeyField();
      if(null != keyField)
        fieldFilter.add(keyField.getName());
    }

    // get documents
    DocIterator iter = docs.iterator();
    for (int i=0; i<docs.size(); i++) {
      searcher.doc(iter.nextDoc(), fieldFilter);
    }

  }

}
 
开发者ID:europeana,项目名称:search,代码行数:58,代码来源:SolrPluginUtils.java


示例6: testJSONSolrDocument

import org.apache.solr.search.ReturnFields; //导入依赖的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


示例7: writeSolrDocument

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
@Override
public void writeSolrDocument(String name, SolrDocument doc, ReturnFields returnFields, int idx) throws IOException {
  if( idx > 0 ) {
    writeArraySeparator();
  }

  indent();
  writeMapOpener(doc.size()); 
  incLevel();

  boolean first=true;
  for (String fname : doc.getFieldNames()) {
    if (!returnFields.wantsField(fname)) {
      continue;
    }
    
    if (first) {
      first=false;
    }
    else {
      writeMapSeparator();
    }

    indent();
    writeKey(fname, true);
    Object val = doc.getFieldValue(fname);

    // SolrDocument will now have multiValued fields represented as a Collection,
    // even if only a single value is returned for this document.
    if (val instanceof List) {
      // shortcut this common case instead of going through writeVal again
      writeArray(name,((Iterable)val).iterator());
    } else {
      writeVal(fname, val);
    }
  }
  
  decLevel();
  writeMapCloser();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:41,代码来源:JSONResponseWriter.java


示例8: modifyRequest

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  // do the filterQParser stuff first
  super.modifyRequest(rb, who, sreq);
  
  if (! doMerge(rb)) {
    return;
  }
  
  ReturnFields rf = rb.rsp.getReturnFields();
  if (rf.wantsAllFields()) {
    // we already have what we need since we ask for everything...
    return;
  }

  IndexSchema schema = rb.req.getCore().getLatestSchema();
  for (SchemaField field : schema.getFields().values()) {
    if (! rf.wantsField(field.getName())) {
      continue;
    }
    for (String source : schema.getCopySources(field.getName())) {
      if (rf.wantsField(source)) {
        continue;
      }
      sreq.params.add(CommonParams.FL, source);
    }
  }
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:29,代码来源:MergeSearchComponent.java


示例9: optimizePreFetchDocs

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
/**
 * Pre-fetch documents into the index searcher's document cache.
 *
 * This is an entirely optional step which you might want to perform for
 * the following reasons:
 *
 * <ul>
 *     <li>Locates the document-retrieval costs in one spot, which helps
 *     detailed performance measurement</li>
 *
 *     <li>Determines a priori what fields will be needed to be fetched by
 *     various subtasks, like response writing and highlighting.  This
 *     minimizes the chance that many needed fields will be loaded lazily.
 *     (it is more efficient to load all the field we require normally).</li>
 * </ul>
 *
 * If lazy field loading is disabled, this method does nothing.
 */
public static void optimizePreFetchDocs(ResponseBuilder rb,
                                        DocList docs,
                                        Query query,
                                        SolrQueryRequest req,
                                        SolrQueryResponse res) throws IOException {
  SolrIndexSearcher searcher = req.getSearcher();
  if(!searcher.enableLazyFieldLoading) {
    // nothing to do
    return;
  }

  ReturnFields returnFields = res.getReturnFields();
  if(returnFields.getLuceneFieldNames() != null) {
    Set<String> fieldFilter = returnFields.getLuceneFieldNames();

    if (rb.doHighlights) {
      // copy return fields list
      fieldFilter = new HashSet<String>(fieldFilter);
      // add highlight fields

      SolrHighlighter highlighter = HighlightComponent.getHighlighter(req.getCore());
      for (String field: highlighter.getHighlightFields(query, req, null))
        fieldFilter.add(field);

      // fetch unique key if one exists.
      SchemaField keyField = searcher.getSchema().getUniqueKeyField();
      if(null != keyField)
        fieldFilter.add(keyField.getName());
    }

    // get documents
    DocIterator iter = docs.iterator();
    for (int i=0; i<docs.size(); i++) {
      searcher.doc(iter.nextDoc(), fieldFilter);
    }

  }

}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:58,代码来源:SolrPluginUtils.java


示例10: writeSolrDocument

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
@Override
public void writeSolrDocument(String name, SolrDocument doc, ReturnFields returnFields, int idx) throws IOException {
  if( idx > 0 ) {
    writeArraySeparator();
  }

  indent();
  writeMapOpener(doc.size()); 
  incLevel();

  boolean first=true;
  for (String fname : doc.getFieldNames()) {
    if (!returnFields.wantsField(fname)) {
      continue;
    }
    
    if (first) {
      first=false;
    }
    else {
      writeMapSeparator();
    }

    indent();
    writeKey(fname, true);
    Object val = doc.getFieldValue(fname);

    // SolrDocument will now have multiValued fields represented as a Collection,
    // even if only a single value is returned for this document.
    if (val instanceof List) {
      // shortcut this common case instead of going through writeVal again
      writeArray(name,((Iterable)val).iterator());
    } else {
      writeVal(fname, val);
    }
  }

  if(doc.hasChildDocuments()) {
    if(first == false) {
      writeMapSeparator();
      indent();
    }
    writeKey("_childDocuments_", true);
    writeArrayOpener(doc.getChildDocumentCount());
    List<SolrDocument> childDocs = doc.getChildDocuments();
    ReturnFields rf = new SolrReturnFields();
    for(int i=0; i<childDocs.size(); i++) {
      writeSolrDocument(null, childDocs.get(i), rf, i);
    }
    writeArrayCloser();
  }
  
  decLevel();
  writeMapCloser();
}
 
开发者ID:europeana,项目名称:search,代码行数:56,代码来源:JSONResponseWriter.java


示例11: writeSolrDocument

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
@Override
public void writeSolrDocument(String name, SolrDocument doc, ReturnFields returnFields, int idx) throws IOException {
  // no-op
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:SchemaXmlWriter.java


示例12: Resolver

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
public Resolver(SolrQueryRequest req, ReturnFields returnFields) {
  solrQueryRequest = req;
  this.returnFields = returnFields;
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:BinaryResponseWriter.java


示例13: createMainQuery

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
private void createMainQuery(ResponseBuilder rb) {
  ShardRequest sreq = new ShardRequest();
  sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;

  String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();

  // one-pass algorithm if only id and score fields are requested, but not if fl=score since that's the same as fl=*,score
  ReturnFields fields = rb.rsp.getReturnFields();

  // distrib.singlePass=true forces a one-pass query regardless of requested fields
  boolean distribSinglePass = rb.req.getParams().getBool(ShardParams.DISTRIB_SINGLE_PASS, false);

  if(distribSinglePass || (fields != null && fields.wantsField(keyFieldName)
      && fields.getRequestedFieldNames() != null
      && (!fields.hasPatternMatching() && Arrays.asList(keyFieldName, "score").containsAll(fields.getRequestedFieldNames())))) {
    sreq.purpose |= ShardRequest.PURPOSE_GET_FIELDS;
    rb.onePassDistributedQuery = true;
  }

  sreq.params = new ModifiableSolrParams(rb.req.getParams());
  // TODO: base on current params or original params?

  // don't pass through any shards param
  sreq.params.remove(ShardParams.SHARDS);

  // set the start (offset) to 0 for each shard request so we can properly merge
  // results from the start.
  if(rb.shards_start > -1) {
    // if the client set shards.start set this explicitly
    sreq.params.set(CommonParams.START,rb.shards_start);
  } else {
    sreq.params.set(CommonParams.START, "0");
  }
  // TODO: should we even use the SortSpec?  That's obtained from the QParser, and
  // perhaps we shouldn't attempt to parse the query at this level?
  // Alternate Idea: instead of specifying all these things at the upper level,
  // we could just specify that this is a shard request.
  if(rb.shards_rows > -1) {
    // if the client set shards.rows set this explicity
    sreq.params.set(CommonParams.ROWS,rb.shards_rows);
  } else {
    sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
  }

  sreq.params.set(ResponseBuilder.FIELD_SORT_VALUES,"true");

  boolean shardQueryIncludeScore = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore();
  StringBuilder additionalFL = new StringBuilder();
  boolean additionalAdded = false;
  if (distribSinglePass)  {
    String[] fls = rb.req.getParams().getParams(CommonParams.FL);
    if (fls != null && fls.length > 0 && (fls.length != 1 || !fls[0].isEmpty())) {
      // If the outer request contains actual FL's use them...
      sreq.params.set(CommonParams.FL, fls);
      if (!fields.wantsField(keyFieldName))  {
        additionalAdded = addFL(additionalFL, keyFieldName, additionalAdded);
      }
    } else {
      // ... else we need to explicitly ask for all fields, because we are going to add
      // additional fields below
      sreq.params.set(CommonParams.FL, "*");
    }
    if (!fields.wantsScore() && shardQueryIncludeScore) {
      additionalAdded = addFL(additionalFL, "score", additionalAdded);
    }
  } else {
    // reset so that only unique key is requested in shard requests
    sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName());
    if (shardQueryIncludeScore) {
      additionalAdded = addFL(additionalFL, "score", additionalAdded);
    }
  }

  if (additionalAdded) sreq.params.add(CommonParams.FL, additionalFL.toString());

  rb.addRequest(this, sreq);
}
 
开发者ID:europeana,项目名称:search,代码行数:78,代码来源:QueryComponent.java


示例14: prepare

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException {
  // Set field flags
  ReturnFields returnFields = new SolrReturnFields( rb.req );
  rb.rsp.setReturnFields( returnFields );
}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:RealTimeGetComponent.java


示例15: prepare

import org.apache.solr.search.ReturnFields; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException
{

  SolrQueryRequest req = rb.req;
  SolrParams params = req.getParams();
  if (!params.getBool(COMPONENT_NAME, true)) {
    return;
  }
  SolrQueryResponse rsp = rb.rsp;

  // Set field flags    
  ReturnFields returnFields = new SolrReturnFields( req );
  rsp.setReturnFields( returnFields );
  int flags = 0;
  if (returnFields.wantsScore()) {
    flags |= SolrIndexSearcher.GET_SCORES;
  }
  rb.setFieldFlags( flags );

  String defType = params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);

  // get it from the response builder to give a different component a chance
  // to set it.
  String queryString = rb.getQueryString();
  if (queryString == null) {
    // this is the normal way it's set.
    queryString = params.get( CommonParams.Q );
    rb.setQueryString(queryString);
  }

  try {
    QParser parser = QParser.getParser(rb.getQueryString(), defType, req);
    Query q = parser.getQuery();
    if (q == null) {
      // normalize a null query to a query that matches nothing
      q = new BooleanQuery();        
    }
    rb.setQuery( q );
    rb.setSortSpec( parser.getSort(true) );
    rb.setQparser(parser);
    
    final String cursorStr = rb.req.getParams().get(CursorMarkParams.CURSOR_MARK_PARAM);
    if (null != cursorStr) {
      final CursorMark cursorMark = new CursorMark(rb.req.getSchema(),
                                                   rb.getSortSpec());
      cursorMark.parseSerializedTotem(cursorStr);
      rb.setCursorMark(cursorMark);
    }

    String[] fqs = req.getParams().getParams(CommonParams.FQ);
    if (fqs!=null && fqs.length!=0) {
      List<Query> filters = rb.getFilters();
      // if filters already exists, make a copy instead of modifying the original
      filters = filters == null ? new ArrayList<Query>(fqs.length) : new ArrayList<Query>(filters);
      for (String fq : fqs) {
        if (fq != null && fq.trim().length()!=0) {
          QParser fqp = QParser.getParser(fq, null, req);
          filters.add(fqp.getQuery());
        }
      }
      // only set the filters if they are not empty otherwise
      // fq=&someotherParam= will trigger all docs filter for every request 
      // if filter cache is disabled
      if (!filters.isEmpty()) {
        rb.setFilters( filters );
      }
    }
  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }

  if (params.getBool(GroupParams.GROUP, false)) {
    prepareGrouping(rb);
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:77,代码来源:QueryComponent.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CLAParser类代码示例发布时间:2022-05-23
下一篇:
Java RepositorySelector类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap