Lucene3.6.2 getting started series _ describes common search functions in Lucene

Source: Internet
Author: User
Package COM. jadyer. lucene; import Java. io. file; import Java. io. ioexception; import Java. text. simpledateformat; import Java. util. date; import Org. apache. lucene. analysis. standard. standardanalyzer; import org.apache.e.doc ument. document; import org.apache.e.doc ument. field; import org.apache.e.doc ument. numericfield; import Org. apache. lucene. index. indexreader; import Org. apache. lucene. index. indexwri Ter; import Org. apache. lucene. index. indexwriterconfig; import Org. apache. lucene. index. term; import Org. apache. lucene. queryparser. parseexception; import Org. apache. lucene. queryparser. queryparser; import Org. apache. lucene. search. booleanquery; import Org. apache. lucene. search. fuzzyquery; import Org. apache. lucene. search. indexsearcher; import Org. apache. lucene. search. numericrangequery; import Org. apache. lucene. s Earch. phrasequery; import Org. apache. lucene. search. prefixquery; import Org. apache. lucene. search. query; import Org. apache. lucene. search. scoredoc; import Org. apache. lucene. search. termquery; import Org. apache. lucene. search. termrangequery; import Org. apache. lucene. search. topdocs; import Org. apache. lucene. search. wildcardquery; import Org. apache. lucene. search. booleanclause. occur; import Org. apache. lucene. store. d Irectory; import Org. apache. lucene. store. fsdirectory; import Org. apache. lucene. util. version;/*** [Starter e3.6.2 entry series] section 03rd _ describes common Lucene search functions * @ create Aug 1, 2013 3:54:27 pm * @ author Xuan Yu 

The following is a test written by junit4.x.

package com.jadyer.test;import java.io.File;import org.junit.Before;import org.junit.Test;import com.jadyer.lucene.HelloSearch;public class HelloSearchTest {private HelloSearch hello;@Beforepublic void init(){hello = new HelloSearch();}@Testpublic void searchByTerm(){hello.searchByTerm("content", "my");}@Testpublic void searchByTermRange(){hello.searchByTermRange("name", "M", "o");}@Testpublic void searchByNumericRange(){hello.searchByNumericRange("attach", 2, 5);}@Testpublic void searchByPrefix(){hello.searchByPrefix("content", "b");}@Testpublic void searchByWildcard(){hello.searchByWildcard("name", "Ja??er");}@Testpublic void searchByFuzzy(){hello.searchByFuzzy("name", "Jadk");}@Testpublic void searchByBoolean(){hello.searchByBoolean();}@Testpublic void searchByPhrase(){hello.searchByPhrase();}@Testpublic void searchByQueryParse(){hello.searchByQueryParse();}@Testpublic void searchPage(){for(File file : new File("myExample/03_index/").listFiles()){file.delete();}hello = new HelloSearch(true);hello.searchPage("mycontent:javase", 2, 10);}@Testpublic void searchPageByAfter(){for(File file : new File("myExample/03_index/").listFiles()){file.delete();}hello = new HelloSearch(true);hello.searchPageByAfter("mycontent:javase", 3, 10);}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.