Example #1
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());
  }