Ejemplo n.º 1
0
  private void addPropertiesFile() {
    Properties indexProperties = new Properties();
    indexProperties.put("version", "1");
    indexProperties.put(
        "java.specification.version", System.getProperty("java.specification.version"));
    indexProperties.put("java.vendor", System.getProperty("java.vendor"));
    indexProperties.put(
        "lucene.specification.version", LucenePackage.get().getSpecificationVersion());

    List<Book> books = (List<Book>) BookInstaller.getInstalledBooks();
    for (Book book : books) {
      System.out.println(
          "Adding properties file:" + book.getInitials() + " name:" + book.getName());
      String initials = book.getInitials();
      File indexPropertiesFile = new File(LUCENE_INDEX_DIR_FILE, initials + "/index.properties");

      FileOutputStream fos = null;
      try {
        fos = new FileOutputStream(indexPropertiesFile);
        indexProperties.store(fos, null);
      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
        ioe.printStackTrace();
      } finally {
        if (fos != null) {
          try {
            fos.close();
          } catch (IOException e2) {
            e2.printStackTrace();
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * @param args
   * @throws IOException
   * @throws CorruptIndexException
   * @throws InterruptedException
   * @throws BrowseException
   */
  public static void main(String[] args)
      throws CorruptIndexException, IOException, InterruptedException, BrowseException {
    System.out.println(LucenePackage.get());
    System.out.println(Arrays.toString(args));
    String filename = "/Users/xgu/lucene29test/caches/people-search-index";
    if (args.length > 0) filename = "/Users/xgu/lucene29test/caches/people-search-index";
    System.out.println(filename);
    File file = new File(filename);
    FSDirectory directory = new SimpleFSDirectory(file);
    //    FSDirectory directory = FSDirectory.getDirectory(file);
    System.out.println(directory.getClass().getName());
    IndexReader reader = IndexReader.open(directory, true);
    loadFile();
    //    TermEnum termEnum = reader.terms(new Term("b", ""));
    //    while(termEnum.next())
    //    {
    //      Term t = termEnum.term();
    //      wordlist.add(t.text());
    //    }
    //    words = wordlist.toArray(new String[1]);
    System.out.println("load the words " + words.length);

    final Collection<FacetHandler<?>> facetHandlers = new ArrayList<FacetHandler<?>>();
    facetHandlers.add(
        new MultiValueFacetHandler(
            "ccid", new PredefinedTermListFactory<Integer>(Integer.class, "0000000000")));
    //    facetHandlers.add(new MultiValueFacetHandler("pcid", new
    // PredefinedTermListFactory<Integer>(Integer.class,"0000000000")));
    facetHandlers.add(
        new SimpleFacetHandler(
            "industry", new PredefinedTermListFactory<Integer>(Integer.class, "0000000000")));
    facetHandlers.add(new SimpleFacetHandler("geo_region"));
    facetHandlers.add(
        new MultiValueFacetHandler(
            "education_id", new PredefinedTermListFactory<Integer>(Integer.class, "0000000000")));
    long tgetinstance = System.currentTimeMillis();
    final BoboIndexReader boboReader = BoboIndexReader.getInstance(reader, facetHandlers, null);
    System.out.println("getInstanceTime: " + (System.currentTimeMillis() - tgetinstance));
    // warming
    for (int x = 0; x < 30; x++) {
      doSearch(5, boboReader, facetHandlers);
    }
    long start = System.currentTimeMillis();
    int numThread = 2;
    System.out.println(numThread + " threads");
    int numItr = 1000;
    long ttime = 0;
    for (int x = 1; x < numItr + 1; x++) {
      long time = doSearch(numThread, boboReader, facetHandlers);
      ttime += time;
      if (x % 20 == 0) {
        System.out.println("total time: " + ttime);
        System.out.println(
            "average time: " + ((float) ttime / (float) x / (float) numThread / (float) inNumItr));
      }
    }
    System.out.println("total time: " + ttime);
    System.out.println(
        "number of iterations: "
            + numItr
            + "\t\tnumThread: "
            + numThread
            + "\t\tinner itr: "
            + inNumItr);
    System.out.println(
        "average time: " + ((float) ttime / (float) numItr / (float) numThread / (float) inNumItr));
    System.out.println(LucenePackage.get());
  }