예제 #1
0
    public String createCombinedTerm(String[] termArray) {
      String term1Combined = "";

      for (String aTermArray : termArray) {
        if (filterGrayList.containsKey(aTermArray.toLowerCase())) {
          String filterTerms = filterGrayList.get(aTermArray.toLowerCase());
          String[] splitFilterTerms = filterTerms.split(",");

          term1Combined = term1Combined + "(+\"" + aTermArray + "\" -(";
          for (String splitFilterTerm : splitFilterTerms) {
            term1Combined = term1Combined + "\"" + splitFilterTerm + "\" ";
          }
          term1Combined = term1Combined + ")) ";
        } else if (keepGrayList.containsKey(aTermArray.toLowerCase())) {
          String keepTerms = keepGrayList.get(aTermArray.toLowerCase());
          String[] splitKeepTerms = keepTerms.split(",");

          term1Combined = term1Combined + "(+\"" + aTermArray + "\" +(";
          for (String splitKeepTerm : splitKeepTerms) {
            term1Combined = term1Combined + "\"" + splitKeepTerm + "\" ";
          }
          term1Combined = term1Combined + ")) ";
        } else {
          term1Combined = term1Combined + "\"" + aTermArray + "\" ";
        }
      }

      return term1Combined;
    }
예제 #2
0
  private static long getTermCount(
      SolrServer server,
      Map<String, Integer> singleCountMap,
      SearchTermAndList searchTermAndList,
      Map<String, String> filterGrayList,
      Map<String, String> keepGrayList) {
    List<String[]> searchTerms = searchTermAndList.asListArray();
    Integer searchTermCountObject =
        searchTerms.size() != 1 ? null : singleCountMap.get(join(searchTerms.get(0), ","));
    long searchTermCount = 0;
    if (searchTermCountObject == null) {
      // didn't find it in map, so need to go get count
      SolrQuery query = new SolrQuery();
      query.setQuery("+text:(*:*)");
      query.addFilterQuery("+pub_date_year:[1993 TO 2013]");
      query.setParam("fl", "pmid");

      for (int i = 0; i < searchTerms.size(); i++) {
        String term1 = "";
        for (String aTermArray : searchTerms.get(i)) {
          if (filterGrayList.containsKey(aTermArray.toLowerCase())) {
            String filterTerms = filterGrayList.get(aTermArray.toLowerCase());
            String[] splitFilterTerms = filterTerms.split(",");
            term1 = term1 + "(+\"" + aTermArray + "\" -(";

            for (String splitFilterTerm : splitFilterTerms) {
              term1 = term1 + "\"" + splitFilterTerm + "\" ";
            }
            term1 = term1 + ")) ";
          } else if (keepGrayList.containsKey(aTermArray.toLowerCase())) {
            String keepTerms = keepGrayList.get(aTermArray.toLowerCase());
            String[] splitKeepTerms = keepTerms.split(",");
            term1 = term1 + "(+\"" + aTermArray + "\" +(";

            for (String splitKeepTerm : splitKeepTerms) {
              term1 = term1 + "\"" + splitKeepTerm + "\" ";
            }
            term1 = term1 + ")) ";
          } else {
            term1 = term1 + "\"" + aTermArray + "\" ";
          }
        }

        query.addFilterQuery("+text:(" + term1 + ")");
      }

      try {
        QueryResponse rsp = server.query(query);
        searchTermCount = rsp.getResults().getNumFound();
        singleCountMap.put(
            join(searchTerms.get(0), ","), Integer.parseInt(Long.toString(searchTermCount)));
      } catch (SolrServerException e) {
        // exit out if there is an error
        log.warning(e.getMessage());
        System.exit(1);
      }
    } else {
      searchTermCount = searchTermCountObject;
    }
    return searchTermCount;
  }