Exemplo n.º 1
0
  /** Connect to searchd server and run current search query. */
  public SphinxResult Query(String query, String index, String comment) throws SphinxException {
    myAssert(
        _reqs == null || _reqs.size() == 0,
        "AddQuery() and Query() can not be combined; use RunQueries() instead");

    AddQuery(query, index, comment);
    SphinxResult[] results = RunQueries();
    _reqs = new ArrayList(); /* just in case it failed too early */
    if (results == null || results.length < 1)
      return null; /* probably network error; error message should be already filled */

    SphinxResult res = results[0];
    _warning = res.warning;
    _error = res.error;
    if (res == null || res.getStatus() == SEARCHD_ERROR) return null;
    return res;
  }
  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;
  }