public static boolean getCorrelation(String ypmc, String icd_name) {
    boolean flag = false;
    SphinxClient cl = new SphinxClient();
    try {
      cl.SetServer(MRecommendCost.SphinxIP, MRecommendCost.SphinxPortYpmcDisease);
      cl.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED2);
      cl.SetLimits(0, MRecommendCost.YPMC_DISEASE_RANK);
      cl.SetConnectTimeout(MRecommendCost.SPHINX_TIMEOUT);

      // 过滤条件
      cl.SetFilter("ypmc_id", CRC32.getCRC32(ypmc), false);
      cl.SetFilterRange("rank", 1, MRecommendCost.YPMC_DISEASE_RANK, false);

      String query = "\"" + icd_name + "\"";
      SphinxResult res = cl.Query(query, "index");

      if (res != null) {
        if (res.total == 1) flag = true;
      } else {
        System.out.println("无查询结果");
      }
    } catch (SphinxException ex) {
      ex.printStackTrace();
    } finally {
      if (cl != null) {
        try {
          cl.Close();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }

    return flag;
  }
  public static boolean getCorrelation(String ypmc, int icd_name_id) {
    boolean flag = false;
    SphinxClient cl = new SphinxClient();
    try {
      cl.SetServer(MRecommendCost.SphinxIP, MRecommendCost.SphinxPortYpmcDisease);
      cl.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED2);
      cl.SetLimits(0, MRecommendCost.YPMC_DISEASE_RANK);
      cl.SetConnectTimeout(MRecommendCost.SPHINX_TIMEOUT);

      // 过滤条件
      cl.SetFilter("icd_name_id", icd_name_id, false);
      cl.SetFilter("ypmc_id", CRC32.getCRC32(ypmc), false);
      cl.SetFilterRange("rank", 1, MRecommendCost.YPMC_DISEASE_RANK, false);

      SphinxResult res = cl.Query("", "index");
      if (res != null) {
        if (res.total == 1) {
          SphinxMatch info = res.matches[0];
          System.out.println(
              info.attrValues.get(0)
                  + "\t"
                  + info.attrValues.get(1)
                  + "\t"
                  + info.attrValues.get(2)
                  + "\t"
                  + info.attrValues.get(3));
          flag = true;
        }
      } else {
        System.out.println(ypmc + "-" + icd_name_id + ":无查询结果");
      }
      cl.ResetFilters();
    } catch (SphinxException ex) {
      ex.printStackTrace();
    } finally {
      if (cl != null) {
        try {
          cl.Close();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }

    return flag;
  }
  public static boolean[] getCorrelation(String[] ypmcs, int icd_name_id) {
    boolean[] flags = new boolean[ypmcs.length];
    SphinxClient cl = new SphinxClient();
    try {
      cl.SetServer(MRecommendCost.SphinxIP, MRecommendCost.SphinxPortYpmcDisease);
      cl.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED2);
      cl.SetLimits(0, MRecommendCost.YPMC_DISEASE_RANK);
      cl.SetConnectTimeout(MRecommendCost.SPHINX_TIMEOUT);

      for (int i = 0; i < ypmcs.length; i++) {
        int ypmc_id = CRC32.getCRC32(ypmcs[i]);
        cl.ResetFilters();
        cl.SetFilter("ypmc_id", ypmc_id, false);
        cl.SetFilter("icd_name_id", icd_name_id, false);
        cl.SetFilterRange("rank", 1, MRecommendCost.YPMC_DISEASE_RANK, false);
        cl.AddQuery("", "index", "");
      }
      SphinxResult[] res = cl.RunQueries();

      if (res != null) {
        for (int i = 0; i < res.length; ++i) {
          if (res[i].total == 1) flags[i] = true;
          else flags[i] = false;
        }
      } else {
        System.out.println("连接出错");
      }
    } catch (SphinxException ex) {
      ex.printStackTrace();
    } finally {
      if (cl != null) {
        try {
          cl.Close();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }

    return flags;
  }
Esempio n. 4
0
 /** Set matches offset and limit to return to client. */
 public void SetLimits(int offset, int limit) throws SphinxException {
   SetLimits(offset, limit, _maxMatches, _cutoff);
 }
Esempio n. 5
0
 /** Set matches offset and limit to return to client, and max matches to retrieve on server. */
 public void SetLimits(int offset, int limit, int max) throws SphinxException {
   SetLimits(offset, limit, max, _cutoff);
 }