Exemplo n.º 1
0
  public List<String> queryQA(String queryString) throws IOException, Exception {

    List<String> results = Lists.newArrayList();
    Query query = parser.parse(queryString);
    long startTime = System.currentTimeMillis();
    List<Document> searchResult = luceneService.search(query, new HashSet<SortField>(), 5);
    List<Map<String, String>> convertedResult =
        new ArrayList<Map<String, String>>(searchResult.size());
    for (Document document : searchResult) {
      results.add(document.get(ANSWER_NAME));
    }
    long endTime = System.currentTimeMillis();
    double timeConsumed = (endTime - startTime) / 1000.0;
    System.out.println("rr : " + results);
    return results;
  }
Exemplo n.º 2
0
  public void addQA(String question, String answer) {
    Map<String, Object> result = new HashMap<String, Object>();
    //        Document document = new Document();
    //        document.add(new StringField("question", question, Field.Store.YES));
    //        document.add(new StringField("answer", answer, Field.Store.YES));

    Document document = new Document();
    document.add(new Field(QUERY_NAME, question, Field.Store.YES, Field.Index.ANALYZED));
    document.add(new Field(ANSWER_NAME, answer, Field.Store.YES, Field.Index.ANALYZED));

    long startTime = System.currentTimeMillis();
    luceneService.addDocument(document);
    long endTime = System.currentTimeMillis();
    result.put("timeConsumed", (endTime - startTime) / 1000.0);
    result.put("question", question);
    result.put("answer", answer);
    System.out.println("put : " + result);
  }