Package org.apache.solr.common.util

Examples of org.apache.solr.common.util.NamedList


   * {@inheritDoc}
   */
  public NamedList transform(List<Command> data) throws IOException {
    NamedList<NamedList> result = new NamedList<NamedList>();
    for (Command command : data) {
      NamedList commandResult;
      if (TopGroupsFieldCommand.class.isInstance(command)) {
        TopGroupsFieldCommand fieldCommand = (TopGroupsFieldCommand) command;
        SchemaField groupField = rb.req.getSearcher().getSchema().getField(fieldCommand.getKey());
        commandResult = serializeTopGroups(fieldCommand.result(), groupField);
      } else if (QueryCommand.class.isInstance(command)) {
View Full Code Here


  public Map<String, ?> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) {
    Map<String, Object> result = new HashMap<String, Object>();

    for (Map.Entry<String, NamedList> entry : shardResponse) {
      String key = entry.getKey();
      NamedList commandResult = entry.getValue();
      Integer totalGroupedHitCount = (Integer) commandResult.get("totalGroupedHitCount");
      Integer totalHits = (Integer) commandResult.get("totalHits");
      if (totalHits != null) {
        Integer matches = (Integer) commandResult.get("matches");
        Float maxScore = (Float) commandResult.get("maxScore");
        if (maxScore == null) {
          maxScore = Float.NaN;
        }
    Double sum = (Double) commandResult.get("sum");
    Double max = (Double) commandResult.get("max");
        Double min = (Double) commandResult.get("min");
        if (sum == null) { sum = Double.valueOf(0.0f); }
        if (max == null) { max = Double.NEGATIVE_INFINITY; }
        if (min == null) { min = Double.POSITIVE_INFINITY; }

        @SuppressWarnings("unchecked")
        List<NamedList<Object>> documents = (List<NamedList<Object>>) commandResult.get("documents");
        ScoreDoc[] scoreDocs = new ScoreDoc[documents.size()];
        int j = 0;
        for (NamedList<Object> document : documents) {
          Object uniqueId = document.get("id").toString();
          Float score = (Float) document.get("score");
          if (score == null) {
            score = Float.NaN;
          }
          Object[] sortValues = ((List) document.get("sortValues")).toArray();
          scoreDocs[j++] = new ShardDoc(score, sortValues, uniqueId, shard);
        }
        result.put(key, new QueryCommandResult(new TopDocs(totalHits, scoreDocs, maxScore, sum, max, min), matches));
        continue;
      }

      Integer totalHitCount = (Integer) commandResult.get("totalHitCount");
      Integer totalGroupCount = (Integer) commandResult.get("totalGroupCount");

      List<GroupDocs<String>> groupDocs = new ArrayList<GroupDocs<String>>();
      for (int i = totalGroupCount == null ? 2 : 3; i < commandResult.size(); i++) {
        String groupValue = commandResult.getName(i);
        @SuppressWarnings("unchecked")
        NamedList<Object> groupResult = (NamedList<Object>) commandResult.getVal(i);
        Integer totalGroupHits = (Integer) groupResult.get("totalHits");
        Float maxScore = (Float) groupResult.get("maxScore");
        if (maxScore == null) {
          maxScore = Float.NaN;
        }
View Full Code Here

   * {@inheritDoc}
   */
  public NamedList transform(List<Command> data) throws IOException {
    NamedList<NamedList> result = new NamedList<NamedList>();
    for (Command command : data) {
      NamedList commandResult;
      if (SearchGroupsFieldCommand.class.isInstance(command)) {
        SearchGroupsFieldCommand fieldCommand = (SearchGroupsFieldCommand) command;
        Collection<SearchGroup<String>> searchGroups = fieldCommand.result();
        if (searchGroups == null) {
          continue;
View Full Code Here

    protected Integer getNumberOfGroups() {
      return null;
    }

    protected NamedList commonResponse() {
      NamedList groupResult = new SimpleOrderedMap();
      grouped.add(key, groupResult)// grouped={ key={

      int matches = getMatches();
      groupResult.add("matches", matches);
      if (totalCount == TotalCount.grouped) {
        Integer totalNrOfGroups = getNumberOfGroups();
        groupResult.add("ngroups", totalNrOfGroups == null ? 0 : totalNrOfGroups);
      }
      maxMatches = Math.max(maxMatches, matches);
      return groupResult;
    }
View Full Code Here

      if (main) {
        mainResult = createSimpleResponse();
        return;
      }

      NamedList groupResult = commonResponse();

      if (format == Format.simple) {
        groupResult.add("doclist", createSimpleResponse());
        return;
      }

      List groupList = new ArrayList();
      groupResult.add("groups", groupList);        // grouped={ key={ groups=[

      if (result == null) {
        return;
      }

      // handle case of rows=0
      if (numGroups == 0) return;

      for (GroupDocs<String> group : result.groups) {
        NamedList nl = new SimpleOrderedMap();
        groupList.add(nl);                         // grouped={ key={ groups=[ {


        // To keep the response format compatable with trunk.
        // In trunk MutableValue can convert an indexed value to its native type. E.g. string to int
        // The only option I currently see is the use the FieldType for this
        if (group.groupValue != null) {
          SchemaField schemaField = searcher.getSchema().getField(groupBy);
          FieldType fieldType = schemaField.getType();
          String readableValue = fieldType.indexedToReadable(group.groupValue);
          Fieldable field = schemaField.createField(readableValue, 0.0f);
          nl.add("groupValue", fieldType.toObject(field));
        } else {
          nl.add("groupValue", null);
        }

        addDocList(nl, group);
      }
    }
View Full Code Here

               topDocs.getMax(),
               topDocs.getMin());
      if (main) {
        mainResult = getDocList(groupDocs);
      } else {
        NamedList rsp = commonResponse();
        addDocList(rsp, groupDocs);
      }
    }
View Full Code Here

  }
 
  public static void setGroupByCrc(QueryResponse qr, QueryResponse qr2)
      throws JSONException {
    StringBuffer buff = new StringBuffer();
    NamedList ff = (NamedList) qr.get_mdrillData();

    ArrayList<Object> facetCounts = (ArrayList<Object>) ff.get("list");

    int fcsize = 0;
    if (facetCounts != null) {
      fcsize = facetCounts.size();
    }

    Map<Long, String> crcvalue = (Map<Long, String>) qr2.get_mdrillData();
    ArrayList<Object> newlist = new ArrayList<Object>();
    for (int i = 0; i < fcsize; i++) {
      GroupbyRow row = new GroupbyRow((ArrayList<Object>) facetCounts.get(i));
      row.setKey(new ColumnKey(crcvalue.get(row.getKey().getCrc())));
      newlist.add(row.toNamedList());
    }

    ff.remove("list");
    ff.add("list", newlist);
  }
View Full Code Here

    ff.add("list", newlist);
  }
 
  public static String getGroupByCrc(QueryResponse qr) throws JSONException {
    StringBuffer buff = new StringBuffer();
    NamedList ff = (NamedList) qr.get_mdrillData();

    ArrayList<Object> facetCounts = (ArrayList<Object>) ff.get("list");

    int fcsize = 0;
    if (facetCounts != null) {
      fcsize = facetCounts.size();
    }
View Full Code Here

  }
 
  public static void setDetailCrc(QueryResponse qr,QueryResponse qr2) throws JSONException
  {
   StringBuffer buff=new StringBuffer();
   NamedList ff = (NamedList) qr.get_mdrillData();
   Map<Long,String> crcvalue = (Map<Long,String>) qr2.get_mdrillData();

     
      ArrayList<Object> facetCounts=(ArrayList<Object>) ff.get("list");

      int fcsize = 0;
      if(facetCounts != null){
        fcsize = facetCounts.size();
      }
     
      ArrayList<Object> newlist=new ArrayList<Object>();
      for(int i=0;i<fcsize;i++){
        SelectDetailRow row = new SelectDetailRow((ArrayList<Object>)facetCounts.get(i));
        row.setKey(new ColumnKey(crcvalue.get(row.getKey().getCrc())));
        newlist.add(row.toNamedList());
      }
     
      ff.remove("list");
      ff.add("list",newlist);
  }
View Full Code Here

  }
 
  public static String getDetailCrc(QueryResponse qr) throws JSONException
  {
   StringBuffer buff=new StringBuffer();
   NamedList ff = (NamedList) qr.get_mdrillData();

     
      ArrayList<Object> facetCounts=(ArrayList<Object>) ff.get("list");

      int fcsize = 0;
      if(facetCounts != null){
        fcsize = facetCounts.size();
      }
View Full Code Here

TOP

Related Classes of org.apache.solr.common.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.