Package org.apache.solr.util

Examples of org.apache.solr.util.NamedList


    while (iter.hasNext()) {
      count[si.order[iter.nextDoc()]]++;
    }

    FieldType ft = searcher.getSchema().getFieldType(fieldName);
    NamedList res = new NamedList();

    // IDEA: we could also maintain a count of "other"... everything that fell outside
    // of the top 'N'

    BoundedTreeSet<CountPair<String,Integer>> queue=null;

    if (limit>=0) {
      // TODO: compare performance of BoundedTreeSet compare against priority queue?
      queue = new BoundedTreeSet<CountPair<String,Integer>>(limit);
    }

    int min=-1// the smallest value in the top 'N' values
    for (int i=1; i<count.length; i++) {
      int c = count[i];
      if (c==0 && !zeros) continue;
      if (limit<0) {
        res.add(ft.indexedToReadable(si.lookup[i]), c);
      } else if (c>min) {
        // NOTE: we use c>min rather than c>=min as an optimization because we are going in
        // index order, so we already know that the keys are ordered.  This can be very
        // important if a lot of the counts are repeated (like zero counts would be).
        queue.add(new CountPair<String,Integer>(ft.indexedToReadable(si.lookup[i]), c));
        if (queue.size()>=limit) min=queue.last().val;
      }
    }

    if (limit>=0) {
      for (CountPair<String,Integer> p : queue) {
        res.add(p.key, p.val);
      }
    }


    if (missing) res.add(null, count[0]);
    return res;
  }
View Full Code Here


                     (t.text(), count));

      }
    } while (te.next());

    NamedList res = new NamedList();
    for (CountPair<String,Integer> p : counts) {
      res.add(ft.indexedToReadable(p.key), p.val);
    }

    if (missing) {
      res.add(null, getFieldMissingCount(searcher,docs,field));
    }

    return res;
  }
View Full Code Here

    return new MapSolrParams(map);
  }
 
  /** Convert this to a NamedList */
  public NamedList toNamedList() {
    final NamedList result = new NamedList();
   
    for(Iterator<String> it=getParameterNamesIterator(); it.hasNext(); ) {
      final String name = it.next();
      final String [] values = getParams(name);
      if(values.length==1) {
        result.add(name,values[0]);
      } else {
        // currently no reason not to use the same array
        result.add(name,values);
      }
    }
    return result;
  }
View Full Code Here

  public URL[] getDocs() {
    return null;
  }

  public NamedList getStatistics() {
    NamedList lst = new NamedList();
    lst.add("caching", cachingEnabled);
    lst.add("numDocs", reader.numDocs());
    lst.add("maxDoc", reader.maxDoc());
    lst.add("readerImpl", reader.getClass().getSimpleName());
    lst.add("readerDir", reader.directory());
    lst.add("indexVersion", reader.getVersion());
    lst.add("openedAt", new Date(openTime));
    if (registerTime!=0) lst.add("registeredAt", new Date(registerTime));
    return lst;
  }
View Full Code Here

  public String getName() {
    return this.getClass().getName();
  }

  public NamedList getStatistics() {
    NamedList lst = new NamedList();
    lst.add("requests", numRequests);
    lst.add("errors", numErrors);
    return lst;
  }
View Full Code Here

      /* * * Generate Main Results * * */

      flags |= U.setReturnFields(req,rsp);
     
      DocListAndSet results = new DocListAndSet();
      NamedList facetInfo = null;
      if (params.getBool(FACET,false)) {
        results = s.getDocListAndSet(query, restrictions,
                                     SolrPluginUtils.getSort(req),
                                     req.getStart(), req.getLimit(),
                                     flags);
        facetInfo = getFacetInfo(req, rsp, results.docSet);
      } else {
        results.docList = s.getDocList(query, restrictions,
                                       SolrPluginUtils.getSort(req),
                                       req.getStart(), req.getLimit(),
                                       flags);
      }
      rsp.add("response",results.docList);
      // pre-fetch returned documents
      U.optimizePreFetchDocs(results.docList, query, req, rsp);

     
      if (null != facetInfo) rsp.add("facet_counts", facetInfo);


           
      /* * * Debugging Info * * */

      try {
        NamedList debug = U.doStandardDebug(req, userQuery, query, results.docList);
        if (null != debug) {
          debug.add("boostquery", boostQuery);
          debug.add("boostfunc", boostFunc);
          if (null != restrictions) {
            debug.add("filter_queries", params.getParams(FQ));
            List<String> fqs = new ArrayList<String>(restrictions.size());
            for (Query fq : restrictions) {
              fqs.add(QueryParsing.toString(fq, req.getSchema()));
            }
            debug.add("parsed_filter_queries",fqs);
          }
          rsp.add("debug", debug);
        }

      } catch (Exception e) {
        SolrException.logOnce(SolrCore.log,
                              "Exception durring debug", e);
        rsp.add("exception_during_debug", SolrException.toStr(e));
      }

      /* * * Highlighting/Summarizing  * * */
      if(HighlightingUtils.isHighlightingEnabled(req)) {

        BooleanQuery highlightQuery = new BooleanQuery();
        U.flattenBooleanQuery(highlightQuery, query);
        String[] highFields = queryFields.keySet().toArray(new String[0]);
        NamedList sumData =
          HighlightingUtils.doHighlighting(results.docList, highlightQuery,
                                           req, highFields);
        if(sumData != null)
          rsp.add("highlighting", sumData);
      }
View Full Code Here

    namedListStyle = namedListStyle==null ? JSON_NL_MAP : namedListStyle.intern();
    wrapperFunction = req.getParam(JSON_WRAPPER_FUNCTION);
  }

  public void writeResponse() throws IOException {
    NamedList nl = new NamedList();
    nl.addAll(rsp.getValues());
    // give the main response a name it it doesn't have one
    if(wrapperFunction!=null) {
        writer.write(wrapperFunction + "(");
    }
    writeNamedList(null, nl);
View Full Code Here

  public URL[] getDocs() {
    return null;
  }

  public NamedList getStatistics() {
    NamedList lst = new NamedList();
    return lst;
  }
View Full Code Here

  public URL[] getDocs() {
    return null;
  }

  public NamedList getStatistics() {
    NamedList lst = new NamedList();
    lst.add("commits", commitCommands.get());
    lst.add("optimizes", optimizeCommands.get());
    lst.add("docsPending", numDocsPending.get());
    // pset.size() not synchronized, but it should be fine to access.
    lst.add("deletesPending", pset.size());
    lst.add("adds", addCommands.get());
    lst.add("deletesById", deleteByIdCommands.get());
    lst.add("deletesByQuery", deleteByQueryCommands.get());
    lst.add("errors", numErrors.get());
    lst.add("cumulative_adds", addCommandsCumulative.get());
    lst.add("cumulative_deletesById", deleteByIdCommandsCumulative.get());
    lst.add("cumulative_deletesByQuery", deleteByQueryCommandsCumulative.get());
    lst.add("cumulative_errors", numErrorsCumulative.get());
    lst.add("docsDeleted", numDocsDeleted.get());

    return lst;
  }
View Full Code Here

        xw.setIndent(true);
      }
    }

    // dump response values
    NamedList lst = rsp.getValues();
    int sz = lst.size();
    int start=0;

    // special case the response header if the version is 2.1 or less   
    if (xw.version<=2100 && sz>0) {
      Object header = lst.getVal(0);
      if (header instanceof NamedList && "responseHeader".equals(lst.getName(0))) {
        writer.write("<responseHeader>");
        xw.incLevel();
        NamedList nl = (NamedList)header;
        for (int i=0; i<nl.size(); i++) {
          String name = nl.getName(i);
          Object val = nl.getVal(i);
          if ("status".equals(name) || "QTime".equals(name)) {
            xw.writePrim(name,null,val.toString(),false);
          } else {
            xw.writeVal(name,val);
          }
View Full Code Here

TOP

Related Classes of org.apache.solr.util.NamedList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.