RAM Storage in Lucene

Source: Internet
Author: User

Package Com.fxr.demo3;import Java.io.ioexception;import Org.apache.lucene.analysis.analyzer;import Org.apache.lucene.analysis.standard.standardanalyzer;import Org.apache.lucene.document.document;import Org.apache.lucene.document.field;import Org.apache.lucene.index.corruptindexexception;import Org.apache.lucene.index.indexwriter;import Org.apache.lucene.index.term;import Org.apache.lucene.search.indexsearcher;import Org.apache.lucene.search.scoredoc;import Org.apache.lucene.search.termquery;import Org.apache.lucene.search.topdocs;import Org.apache.lucene.store.directory;import Org.apache.lucene.store.fsdirectory;import    Org.apache.lucene.store.ramdirectory;public class Testramsearcher {Directory directory=new ramdirectory (); public void Creatramindex () throws ioexception{String [] ids={"1", "2", "3", "4"}; String [] names={"Zhangsan", "Lisi", "Wangwu", "Zhaoliu"}; String [] addresses={"tianjing", "Nanjing", "Beijing", "Nanning"}; String [] birthdays={"19820720", "19840203", "19770409", "19830130 "}; Analyzer analyzer=new StandardAnalyzer ();//true indicates that the current index is created or overwritten; false means that the current index is appended//default value is 128IndexWriter writer= New IndexWriter (directory,analyzer,true,indexwriter.maxfieldlength.limited); for (int i=0;i<ids.length;i++) { Document Document=new document ();d Ocument.add (new Field ("id", ids[i],field.store.yes,field.index.analyzed)); Document.add (new Field ("Name", names[i],field.store.yes,field.index.analyzed));d Ocument.add ("Address", addresses[i],field.store.yes,field.index.analyzed));d Ocument.add (New Field ("Birthday", Birthdays[i],    field.store.yes,field.index.analyzed)); Writer.adddocument (document);}    Writer.optimize (); Writer.close ();        System.out.println ("OK");} public void Searchram () throws Corruptindexexception, ioexception{indexsearcher searcher=new indexsearcher (directory) ; Scoredoc [] hits=null; Term term=new term ("address", "Nanjing"); Termquery query=new Termquery (term); Topdocs topdocs=searcher.search (query, +); hits=topdocs.scoredocs;for (int i=0;i

Another notation in Lucene:

Package Com.fxr.demo3;import Java.io.ioexception;import Org.apache.lucene.analysis.analyzer;import Org.apache.lucene.analysis.standard.standardanalyzer;import Org.apache.lucene.document.document;import Org.apache.lucene.index.term;import Org.apache.lucene.search.indexsearcher;import Org.apache.lucene.search.scoredoc;import Org.apache.lucene.search.termquery;import Org.apache.lucene.search.topdoccollector;import Org.apache.lucene.store.directory;import Org.apache.lucene.store.fsdirectory;public class Testtopdoccollectller {public static void main (string[] args) throws IOException {Analyzer Analyzer = new StandardAnalyzer (); String Indexdir = "F:/lucenefxrindex";D irectory dir=fsdirectory.getdirectory (indexdir);//location of index storage Indexsearcher Indexsearcher = new Indexsearcher (dir); Scoredoc[]hits = null; Topdoccollector topdoccollector = new Topdoccollector (10); Term term = new term ("address", "Zhengzhou"); Termquery query = new Termquery (term); Indexsearcher.search (query,topdoccollector); hits = TopdoccoLlector.topdocs (). scoredocs;for (int i=0;i

  

RAM Storage in Lucene

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.