Exemple #1
0
  public static SearchTermAndList getTermAndTermList(
      String searchTerm, boolean useAlias, boolean tabDelimited) {
    SearchTermAndList terms;
    // first see if the item is an expression term or regular term
    if (searchTerm.trim().endsWith(")") && searchTerm.trim().startsWith("(")) {
      // this is an expression, so need to parse string
      terms = new SearchTermAndList(searchTerm.trim());

      int startIndex = 1;
      int phraseIndex = searchTerm.trim().indexOf(")");
      while (startIndex > 0 && phraseIndex > 0) {
        String[] termInfo =
            getTermAliasList(searchTerm.trim().substring(startIndex, phraseIndex), false);
        terms.addItems(termInfo);
        startIndex = searchTerm.trim().indexOf("(", phraseIndex) + 1;
        phraseIndex = searchTerm.trim().indexOf(")", startIndex);
      }

    } else { // regular term with possible aliases
      String[] finalItems = getTermAliasList(searchTerm, tabDelimited);
      terms = new SearchTermAndList(finalItems[0]);

      if (useAlias) {
        terms.addItems(finalItems);
      } else {
        terms.addItems(finalItems[0]);
      }
    }
    return terms;
  }
Exemple #2
0
 public SolrCallable(
     SearchTermAndList stal1,
     SearchTermAndList stal2,
     long term1count,
     long term2count,
     SolrServer server,
     boolean useAlias,
     HashMap<String, String> filterGrayList,
     HashMap<String, String> keepGrayList,
     long totalDocCount) {
   this.term1 = stal1.getTerm();
   this.term2 = stal2.getTerm();
   this.term1count = term1count;
   this.term2count = term2count;
   this.server = server;
   this.term1Array = stal1.asListArray();
   this.term2Array = stal2.asListArray();
   this.useAlias = useAlias;
   this.filterGrayList = filterGrayList;
   this.keepGrayList = keepGrayList;
   this.totalDocCount = totalDocCount;
 }
Exemple #3
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;
  }