示例#1
0
  public TopDocCollectorSearchResult searchByScore(
      String queryStr, int startFrom, String operator) {

    try {
      queryStr = queryStr.trim();
      QueryParser parser = new QueryParser("contents", analyzer);
      if (QueryParser.AND_OPERATOR.toString().equalsIgnoreCase(operator)) {
        parser.setDefaultOperator(QueryParser.AND_OPERATOR);
      } else {
        parser.setDefaultOperator(QueryParser.OR_OPERATOR);
      }
      Query query;
      query = parser.parse(queryStr);
      TopDocCollector collector = doPagingSearch(query, startFrom);
      TopDocCollectorSearchResult result = new TopDocCollectorSearchResult(collector, searcher);
      return result;
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;

    // System.out.println("Searching for: " + query.toString("contents"));

    // doPagingSearch(in, searcher, query, hitsPerPage, raw, queries ==
    // null);

    // }
    // reader.close();
  }
示例#2
0
  public TopFieldDocsSearchResult searchBySession(String queryStr, int startFrom, String operator) {

    try {
      queryStr = queryStr.trim();
      QueryParser parser = new QueryParser("contents", analyzer);
      Operator op = QueryParser.AND_OPERATOR;
      if (QueryParser.AND_OPERATOR.toString().equalsIgnoreCase(operator)) {
        parser.setDefaultOperator(QueryParser.AND_OPERATOR);
      } else {
        parser.setDefaultOperator(QueryParser.OR_OPERATOR);
      }

      Query query;
      query = parser.parse(queryStr);
      Sort sort = new Sort("summary", true);

      TopFieldDocs tfd = searcher.search(query, null, startFrom + 10, sort);
      TopFieldDocsSearchResult result = new TopFieldDocsSearchResult(tfd, searcher);
      return result;
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;
  }