Package com.tistory.devyongsik.crescent.search.searcher

Source Code of com.tistory.devyongsik.crescent.search.searcher.IndexSearcherTest

package com.tistory.devyongsik.crescent.search.searcher;

import java.io.IOException;

import javax.annotation.PostConstruct;

import junit.framework.Assert;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SearcherManager;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.junit.Test;

import com.tistory.devyongsik.utils.CrescentTestCaseUtil;

public class IndexSearcherTest extends CrescentTestCaseUtil {

  @PostConstruct
  public void init() {
    super.init();
  }

  @Test
  public void defaultSearch() throws IOException {
    SearcherManager searcherManager = crescentSearcherManager.getSearcherManager("sample");
    IndexSearcher indexSearcher = searcherManager.acquire();
   
    Term t = new Term("title", "2");
    Query q = new TermQuery(t);
   
    TopDocs topDocs = indexSearcher.search(q, 5);
   
    int totalCount = topDocs.totalHits;
   
    System.out.print("total count : " + totalCount);
   
    Assert.assertTrue(totalCount > 0);
  }
}
TOP

Related Classes of com.tistory.devyongsik.crescent.search.searcher.IndexSearcherTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.