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


Java ReturnFields.wantsScore方法代码示例

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


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

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

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

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