Package com.senseidb.util.JSONUtil

Examples of com.senseidb.util.JSONUtil.FastJSONObject


  public Query doConstructQuery(JSONObject jsonQuery) throws JSONException
  {
    Filter filter = null;
    try
    {
      JSONObject newJson = new FastJSONObject();
      newJson.put(QUERY_TYPE, jsonQuery);
      filter = FilterConstructor.constructFilter(newJson, null/* QueryParser is not used by this filter */);
    }
    catch(Exception e)
    {
      throw new JSONException(e);
View Full Code Here


  public static final String FILTER_TYPE = "const_exp";

  @Override
  protected SenseiFilter doConstructFilter(Object json) throws Exception
  {
    Query q = QueryConstructor.constructQuery(new FastJSONObject().put(FILTER_TYPE, (JSONObject)json), null);
    if (q == null)
      return null;

    final QueryWrapperFilter filter = new QueryWrapperFilter(q);
View Full Code Here

  }

  @Override
  public JSONObject fromBytes(byte[] data) {
    try {
      return new FastJSONObject(new String(data,UTF8));
    } catch (JSONException e) {
      return null;
    }
  }
View Full Code Here

  public final static Charset UTF8 = Charset.forName("UTF-8");
 
  @Override
  protected JSONObject doFilter(DataPacket packet) throws Exception {
    String jsonString = new String(packet.data,packet.offset,packet.size,UTF8);
    return new FastJSONObject(jsonString);
  }
View Full Code Here

      throws JSONException
  {
    JSONObject jsonObject = null;
    if (expl != null)
    {
      jsonObject = new FastJSONObject(5);
      jsonObject.put(PARAM_RESULT_HITS_EXPL_VALUE, expl.getValue());
      String descr = expl.getDescription();
      jsonObject.put(PARAM_RESULT_HITS_EXPL_DESC, descr == null ? "" : descr);
      Explanation[] details = expl.getDetails();
      if (details != null)
View Full Code Here

  }

  public static JSONObject convert(Map<String, FacetAccessible> facetValueMap, SenseiRequest req)
      throws JSONException
  {
    JSONObject resMap = new FastJSONObject(25);
    if (facetValueMap != null)
    {
      Set<Entry<String, FacetAccessible>> entrySet = facetValueMap.entrySet();

      for (Entry<String, FacetAccessible> entry : entrySet)
      {
        String fieldname = entry.getKey();

        BrowseSelection sel = req.getSelection(fieldname);
        HashSet<String> selectedVals = new HashSet<String>();
        if (sel != null)
        {
          String[] vals = sel.getValues();
          if (vals != null && vals.length > 0)
          {
            selectedVals.addAll(Arrays.asList(vals));
          }
        }

        FacetAccessible facetAccessible = entry.getValue();
        List<BrowseFacet> facetList = facetAccessible.getFacets();

        ArrayList<JSONObject> facets = new ArrayList<JSONObject>();

        for (BrowseFacet f : facetList)
        {
          String fval = f.getValue();
          if (fval != null && fval.length() > 0)
          {
            JSONObject fv = new FastJSONObject();
            fv.put(PARAM_RESULT_FACET_INFO_COUNT, f.getFacetValueHitCount());
            fv.put(PARAM_RESULT_FACET_INFO_VALUE, fval);
            fv.put(PARAM_RESULT_FACET_INFO_SELECTED, selectedVals.remove(fval));
            facets.add(fv);
          }
        }

        if (selectedVals.size() > 0)
        {
          // selected vals did not make it in top n
          for (String selectedVal : selectedVals)
          {
            if (selectedVal != null && selectedVal.length() > 0)
            {
              BrowseFacet selectedFacetVal = facetAccessible.getFacet(selectedVal);
              JSONObject fv = new FastJSONObject(5);
              fv.put(PARAM_RESULT_FACET_INFO_COUNT, selectedFacetVal == null ? 0 : selectedFacetVal.getFacetValueHitCount());
              String fval = selectedFacetVal == null ? selectedVal : selectedFacetVal.getValue();
              fv.put(PARAM_RESULT_FACET_INFO_VALUE, fval);
              fv.put(PARAM_RESULT_FACET_INFO_SELECTED, true);
              facets.add(fv);
            }
          }

          // we need to sort it
View Full Code Here

      {
        int totalDocs = 0;
        try
        {
          SenseiRequest req = new SenseiRequest();
          req.setQuery(new SenseiJSONQuery(new FastJSONObject().put("query", "dummy:dummy")));
          SenseiResult res = _senseiBroker.browse(req);
          totalDocs = res.getTotalDocs();
        }
        catch(Exception e)
        {
View Full Code Here

    if (requestContext.content != null)
    {
      if (requestContext.content.length() == 0) requestContext.content = "{}";
      try
      {
        requestContext.jsonObj = new FastJSONObject(requestContext.content);
      }
      catch(JSONException jse)
      {
        logger.error("JSON parsing error", jse);
        writeEmptyResponse(req, resp, new SenseiError(jse.getMessage(), ErrorType.JsonParsingError));
View Full Code Here

    BufferedReader reader = req.getReader();
    requestContext.content = readContent(reader);
    if (requestContext.content == null || requestContext.content.length() == 0) requestContext.content = "{}";
    try
    {
      requestContext.jsonObj = new FastJSONObject(requestContext.content);
    }
    catch(JSONException jse)
    {
      String contentType = req.getHeader("Content-Type");
      if (contentType != null && contentType.indexOf("json") >= 0)
View Full Code Here

        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));
      }
View Full Code Here

TOP

Related Classes of com.senseidb.util.JSONUtil.FastJSONObject

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.