Example #1
0
  /**
   * Search the query file to find the query words and add them in to an array list.
   *
   * @param filename : file of queries
   */
  public void search(String filename, InvertedIndex index) {
    Path file = Paths.get(filename);

    try (BufferedReader reader = Files.newBufferedReader(file, Charset.forName("UTF-8"))) {
      String parseWord;
      while ((parseWord = reader.readLine()) != null) {
        lock.acquireWriteLock();
        map.put(parseWord, null);
        lock.releaseWriteLock();
        workers.execute(new Searcher(parseWord, index));
      }
      finish();
    } catch (IOException e) {
      System.out.println("The file " + filename + " could not be read.");
    }
  }