Examples of FastJSONArray


Examples of com.senseidb.util.JSONUtil.FastJSONArray

        tableObj.put("compress-src-data", false);
      else
        tableObj.put("compress-src-data", true);

      NodeList columns = tableElem.getElementsByTagName("column");
      JSONArray columnArray = new FastJSONArray();
      tableObj.put("columns", columnArray);

      for (int i = 0; i < columns.getLength(); ++i)
      {
        try
        {
          Element column = (Element) columns.item(i);
          JSONObject columnObj = new FastJSONObject();
          columnArray.put(columnObj);

          String n = column.getAttribute("name");
          String t = column.getAttribute("type");
          String frm = column.getAttribute("from");

          columnObj.put("name", n);
          columnObj.put("type", t);
          columnObj.put("from", frm);

          columnObj.put("multi", Boolean.parseBoolean(column.getAttribute("multi")));
          columnObj.put("activity", Boolean.parseBoolean(column.getAttribute("activity")));
          columnObj.put("wildcard", Boolean.parseBoolean(column.getAttribute("wildcard")));

            String delimString = column.getAttribute("delimiter");
          if (delimString != null && delimString.trim().length() > 0)
          {
            columnObj.put("delimiter", delimString);
          }

          String f = "";
          try
          {
            f = column.getAttribute("format");
          }
          catch (Exception ex)
          {
            logger.error(ex.getMessage(), ex);
          }
          if (!f.isEmpty())
            columnObj.put("format", f);

          String idxString = column.getAttribute("index");
          if (idxString != null)
          {
            columnObj.put("index", idxString);
          }
          String storeString = column.getAttribute("store");
          if (storeString != null)
          {
            columnObj.put("store", storeString);
          }
          String tvString = column.getAttribute("termvector");
          if (tvString != null)
          {
            columnObj.put("termvector", tvString);
          }

        }
        catch (Exception e)
        {
          throw new ConfigurationException("Error parsing schema: " + columns.item(i), e);
        }
      }
    }


    NodeList facets = schemaDoc.getElementsByTagName("facet");
    JSONArray facetArray = new FastJSONArray();
    jsonObj.put("facets", facetArray);

    for (int i = 0; i < facets.getLength(); ++i)
    {
      try
      {
        Element facet = (Element) facets.item(i);
        JSONObject facetObj = new FastJSONObject();
        facetArray.put(facetObj);

        facetObj.put("name", facet.getAttribute("name"));
        facetObj.put("type", facet.getAttribute("type"));
        String depends = facet.getAttribute("depends");
        if (depends!=null){
          String[] dependsList = depends.split(",");
          JSONArray dependsArr = new FastJSONArray();
          for (String dependName : dependsList)
          {
            if (dependName != null)
            {
              dependName = dependName.trim();
              if (dependName.length() != 0)
                dependsArr.put(dependName);
            }
          }
          facetObj.put("depends", dependsArr);
        }
        String column = facet.getAttribute("column");
        if (column!=null && column.length() > 0){
          facetObj.put("column", column);
        }
        String dynamic = facet.getAttribute("dynamic");
        if (dynamic!=null){
          facetObj.put("dynamic",dynamic);
        }

        NodeList paramList = facet.getElementsByTagName("param");
        if (paramList!=null){
          JSONArray params = new FastJSONArray();
          facetObj.put("params", params);
          for (int j = 0; j < paramList.getLength(); ++j) {
            Element param = (Element) paramList.item(j);
            String paramName = param.getAttribute("name");
            String paramValue = param.getAttribute("value");
            JSONObject paramObj = new FastJSONObject();
            paramObj.put("name", paramName);
            paramObj.put("value", paramValue);
            params.put(paramObj);
          }
        }
      }
      catch(Exception e){
        throw new ConfigurationException("Error parsing schema: " + facets.item(i), e);
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

 
  public static void main(String args[]) throws JSONException{
    JSONObject json = new FastJSONObject();
    JSONObject func = new FastJSONObject();
    func.put("function", "length");
    func.put("params", new FastJSONArray().put(new FastJSONArray()));
    json.put("lvalue", func);
    json.put("operator", "==");
    json.put("rvalue", 0);
   
    ConstExpQueryConstructor c = new ConstExpQueryConstructor();
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

    try {
      List<JSONObject> ret = new ArrayList<JSONObject>();
      for (GroupedValue grouped : reduceResult) {
        ret.add(new FastJSONObject().put(grouped.key, grouped.value));
      }
      return new FastJSONObject().put("groupedCounts", new FastJSONArray(ret));
    } catch (JSONException ex) {
      throw new RuntimeException(ex);
    }
  }
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

                    // Accept scalar values here too.  This is useful in
                    // supporting variable substitutions.
                    Object value = jsonParamValues.opt(RequestConverter2.FACETINIT_VALUES);
                    if (value != null)
                    {
                      jsonValues = new FastJSONArray().put(value);
                    }
                  }
                  if (jsonValues != null)
                  {
                    if (type.equals(RequestConverter2.FACETINIT_TYPE_INT))
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

      String descr = expl.getDescription();
      jsonObject.put(PARAM_RESULT_HITS_EXPL_DESC, descr == null ? "" : descr);
      Explanation[] details = expl.getDetails();
      if (details != null)
      {
        JSONArray detailArray = new FastJSONArray(details.length);
        for (Explanation detail : details)
        {
          JSONObject subObj = convertExpl(detail);
          if (subObj != null)
          {
            detailArray.put(subObj);
          }
        }
        jsonObject.put(PARAM_RESULT_HITS_EXPL_DETAILS, detailArray);
      }
    }
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

  public static JSONArray buildJSONHits(SenseiRequest req, SenseiHit[] hits)
      throws Exception
  {
    Set<String> selectSet = req.getSelectSet();

    JSONArray hitArray = new FastJSONArray(hits.length);
    for (SenseiHit hit : hits)
    {
      Map<String, String[]> fieldMap = hit.getFieldValues();
      int fieldMapSize = fieldMap == null ? 0 : fieldMap.size();

      JSONObject hitObj = new FastJSONObject(20 + fieldMapSize);

      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_UID))
      {
        hitObj.put(PARAM_RESULT_HIT_UID, hit.getUID());
      }
      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_DOCID))
      {
        hitObj.put(PARAM_RESULT_HIT_DOCID, hit.getDocid());
      }
      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_SCORE))
      {
        hitObj.put(PARAM_RESULT_HIT_SCORE, formatScore(req.getScoreMeaningfulDigits(), hit.getScore()));
      }
      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_GROUPFIELD))
      {
        hitObj.put(PARAM_RESULT_HIT_GROUPFIELD, hit.getGroupField());
      }
      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_GROUPVALUE))
      {
        hitObj.put(PARAM_RESULT_HIT_GROUPVALUE, hit.getGroupValue());
      }
      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_GROUPHITSCOUNT))
      {
        hitObj.put(PARAM_RESULT_HIT_GROUPHITSCOUNT, hit.getGroupHitsCount());
      }
      if (hit.getGroupHits() != null && hit.getGroupHits().length > 0)
        hitObj.put(PARAM_RESULT_HIT_GROUPHITS, buildJSONHits(req, hit.getSenseiGroupHits()));

      // get fetchStored even if request does not have it because it could be set at the
      // federated broker level
      if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_SRC_DATA) ||
          req.isFetchStoredFields() || hit.getSrcData() != null)
      {
        hitObj.put(PARAM_RESULT_HIT_SRC_DATA, hit.getSrcData());
      }
      if (fieldMap != null)
      {
        Set<Entry<String, String[]>> entries = fieldMap.entrySet();
        for (Entry<String, String[]> entry : entries)
        {
          String key = entry.getKey();
          if (key.equals(PARAM_RESULT_HIT_UID))
          {
            // UID is already set.
            continue;
          }

          if (selectSet == null || selectSet.contains(key))
          {
            String[] vals = entry.getValue();

            JSONArray valArray;
            if (vals != null)
            {
              valArray = new FastJSONArray(vals.length);
              for (String val : vals)
              {
                valArray.put(val);
              }
            }
            else
            {
              valArray = new FastJSONArray();
            }
            hitObj.put(key, valArray);
          }
        }
      }

      Document doc = hit.getStoredFields();
      if (doc != null)
      {
        if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_STORED_FIELDS))
        {
          List<Fieldable> fields = doc.getFields();
          List<JSONObject> storedData = new ArrayList<JSONObject>(fields.size());
          for (Fieldable field : fields)
          {
            JSONObject data = new FastJSONObject(4);
            data.put(PARAM_RESULT_HIT_STORED_FIELDS_NAME, field.name());
            data.put(PARAM_RESULT_HIT_STORED_FIELDS_VALUE, field.stringValue());
            storedData.add(data);
          }

          hitObj.put(PARAM_RESULT_HIT_STORED_FIELDS, new FastJSONArray(storedData));
        }
      }

      Map<String,BrowseHit.TermFrequencyVector> tvMap = hit.getTermFreqMap();
      if (tvMap != null && tvMap.size() > 0){
        JSONObject tvObj = new FastJSONObject(2 * tvMap.entrySet().size());
        if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_TERMVECTORS))
        {
          hitObj.put(PARAM_RESULT_HIT_TERMVECTORS, tvObj);
        }

        Set<Entry<String,BrowseHit.TermFrequencyVector>> entries = tvMap.entrySet();
        for (Entry<String,BrowseHit.TermFrequencyVector> entry : entries){
          String field = entry.getKey();

          String[] terms = entry.getValue().terms;
          int[] freqs = entry.getValue().freqs;

          JSONArray tvArray = new FastJSONArray(terms.length);
          for (int i=0;i<terms.length;++i){
            JSONObject tv = new FastJSONObject(4);
            tv.put("term", terms[i]);
            tv.put("freq", freqs[i]);
            tvArray.put(tv);
          }

          tvObj.put(field, tvArray);
        }
      }

      Explanation expl = hit.getExplanation();
      if (expl != null)
      {
        if (selectSet == null || selectSet.contains(PARAM_RESULT_HIT_EXPLANATION))
        {
          hitObj.put(PARAM_RESULT_HIT_EXPLANATION, convertExpl(expl));
        }
      }

      float [] features = hit.getFeatures();
      if (features != null)
      {
        JSONArray featureArray = new FastJSONArray(features.length);
        for (float f : features)
        {
          featureArray.put(f);
        }

        hitObj.put(PARAM_RESULT_FEATURES, featureArray);
      }

View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

    jsonObj.put(PARAM_RESULT_HITS, hitArray);

    List<String> selectList = req.getSelectList();
    if (selectList != null)
    {
      JSONArray jsonSelectList = new FastJSONArray(selectList.size());
      for (String col: selectList)
      {
        jsonSelectList.put(col);
      }
      jsonObj.put(PARAM_RESULT_SELECT_LIST, jsonSelectList);
    }

    jsonObj.put(PARAM_RESULT_TIME, res.getTime());
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

      return String.format("%." + digits + "f", score);
    }
  }

  private static void addErrors(JSONObject jsonResult, SenseiResult res) throws JSONException {
    JSONArray errorsJson = new FastJSONArray(res.getErrors().size());
    for (SenseiError error: res.getErrors()) {
      errorsJson.put(new FastJSONObject(5).put(PARAM_RESULT_ERROR_MESSAGE, error.getMessage())
                                         .put(PARAM_RESULT_ERROR_TYPE, error.getErrorType().name())
                                         .put(PARAM_RESULT_ERROR_CODE, error.getErrorCode()));
    }
    jsonResult.put(PARAM_RESULT_ERRORS, errorsJson);
    if (res.getErrors().size() > 0) {
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

    {
      jsonObj.put(PARAM_SYSINFO_SCHEMA, new FastJSONObject(info.getSchema()));
    }

    Set<SenseiSystemInfo.SenseiFacetInfo> facets = info.getFacetInfos();
    JSONArray jsonArray = new FastJSONArray(facets == null ? 0 : facets.size());
    if (facets != null) {
        for (SenseiSystemInfo.SenseiFacetInfo facet : facets) {
          JSONObject facetObj = new FastJSONObject(6);
          facetObj.put(PARAM_SYSINFO_FACETS_NAME, facet.getName());
          facetObj.put(PARAM_SYSINFO_FACETS_RUNTIME, facet.isRunTime());
          facetObj.put(PARAM_SYSINFO_FACETS_PROPS, facet.getProps());
          jsonArray.put(facetObj);
        }
    }
    jsonObj.put(PARAM_SYSINFO_FACETS, jsonArray);

    List<SenseiSystemInfo.SenseiNodeInfo> clusterInfo = info.getClusterInfo();
    jsonArray = new FastJSONArray(clusterInfo == null ? 0 : clusterInfo.size());
    if (clusterInfo != null)
    {
      for (SenseiSystemInfo.SenseiNodeInfo nodeInfo : clusterInfo)
      {
        JSONObject nodeObj = new FastJSONObject(7);
        nodeObj.put(PARAM_SYSINFO_CLUSTERINFO_ID, nodeInfo.getId());
        nodeObj.put(PARAM_SYSINFO_CLUSTERINFO_PARTITIONS, new FastJSONArray(Arrays.asList(nodeInfo.getPartitions())));
        nodeObj.put(PARAM_SYSINFO_CLUSTERINFO_NODELINK, nodeInfo.getNodeLink());
        nodeObj.put(PARAM_SYSINFO_CLUSTERINFO_ADMINLINK, nodeInfo.getAdminLink());
        jsonArray.put(nodeObj);
      }
    }
    jsonObj.put(PARAM_SYSINFO_CLUSTERINFO, jsonArray);

    return supportJsonp(httpReq, jsonObj.toString());
View Full Code Here

Examples of com.senseidb.util.JSONUtil.FastJSONArray

        writeEmptyResponse(req, resp, new SenseiError("BQL parsing error for additional preds: " + errMsg + ", BQL: " + bql2, ErrorType.BQLParsingError));
        return false;
      }

      // Combine filters
      JSONArray filter_list = new FastJSONArray();
      JSONObject currentFilter = requestContext.compiledJson.optJSONObject("filter");
      if (currentFilter != null)
      {
        filter_list.put(currentFilter);
      }

      JSONArray selections = predObj.optJSONArray("selections");
      if (selections != null)
      {
        for (int i = 0; i < selections.length(); ++i)
        {
          JSONObject pred = selections.getJSONObject(i);
          if (pred != null)
          {
            filter_list.put(pred);
          }
        }
      }
      JSONObject additionalFilter = predObj.optJSONObject("filter");
      if (additionalFilter != null)
      {
        filter_list.put(additionalFilter);
      }
     
      if (filter_list.length() > 1)
      {
        requestContext.compiledJson.put("filter", new FastJSONObject().put("and", filter_list));
      }
      else if (filter_list.length() == 1)
      {
        requestContext.compiledJson.put("filter", filter_list.get(0));
      }
    }

    JSONObject metaData = requestContext.compiledJson.optJSONObject("meta");
    if (metaData != null)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.