Filter w 5PLFOΛҰఆͷϧʔϧͰআڈ͢ΔʢFHStopFilterʣ w 5PLFOͷจࣈྻΛҰఆͷϧʔϧͰஔ͢ΔʢFHLowerCaseFilterʣ w AnalyzerͷྫStandardAnalyzer w StandardAnalyzerStandardTokenizer + StopFilter LowerCaseFilter w 6OJDPEF5FYU4FHNFOUBUJPO ϕʔεͷ Tokenizer "Lucene in Action" "Lucene", "in", "Action" "Lucene", "Action" "lucene", "action" StandardTokenizer StopFilter LowerCaseFilter *GUIFStopFilterIBTlJOzBTBTUPQXPSE
Path indexDirPath = Files.createDirectory(Path.of("index")); Directory directory = FSDirectory.open(indexDirPath); // Set up IndexWriter Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter indexWriter = new IndexWriter(directory, config); // Index a document: "Lucene in Action" Document doc1 = new Document(); doc1.add(new Field("title", "Lucene in Action", TextField.TYPE_STORED)); indexWriter.addDocument(doc1); // Index a document: "Lucene Cookbook" Document doc2 = new Document(); doc2.add(new Field("title", "Lucene Cookbook", TextField.TYPE_STORED)); indexWriter.addDocument(doc2); // Write index to the directory indexWriter.close();
// Create a directory for storing Lucene index Path indexDirPath = Files.createDirectory(Path.of("index")); Directory directory = FSDirectory.open(indexDirPath); // Set up IndexWriter Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter indexWriter = new IndexWriter(directory, config); // Index a document: "Lucene in Action" Document doc1 = new Document(); doc1.add(new Field("title", "Lucene in Action", TextField.TYPE_STORED)); indexWriter.addDocument(doc1); // Index a document: "Lucene Cookbook" Document doc2 = new Document(); doc2.add(new Field("title", "Lucene Cookbook", TextField.TYPE_STORED)); indexWriter.addDocument(doc2); // Write index to the directory indexWriter.close();
w IndexWriter w ΠϯσοΫεͷॻ͖ࠐΈΛΦʔέετϨʔγϣϯ͢ΔΫϥε // Create a directory for storing Lucene index Path indexDirPath = Files.createDirectory(Path.of("index")); Directory directory = FSDirectory.open(indexDirPath); // Set up IndexWriter Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter indexWriter = new IndexWriter(directory, config); // Index a document: "Lucene in Action" Document doc1 = new Document(); doc1.add(new Field("title", "Lucene in Action", TextField.TYPE_STORED)); indexWriter.addDocument(doc1); // Index a document: "Lucene Cookbook" Document doc2 = new Document(); doc2.add(new Field("title", "Lucene Cookbook", TextField.TYPE_STORED)); indexWriter.addDocument(doc2); // Write index to the directory indexWriter.close();
w IndexWriter w ΠϯσοΫεͷॻ͖ࠐΈΛΦʔέετϨʔγϣϯ͢ΔΫϥε w addDocument()ϝιουͰDocumentΛՃ // Create a directory for storing Lucene index Path indexDirPath = Files.createDirectory(Path.of("index")); Directory directory = FSDirectory.open(indexDirPath); // Set up IndexWriter Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter indexWriter = new IndexWriter(directory, config); // Index a document: "Lucene in Action" Document doc1 = new Document(); doc1.add(new Field("title", "Lucene in Action", TextField.TYPE_STORED)); indexWriter.addDocument(doc1); // Index a document: "Lucene Cookbook" Document doc2 = new Document(); doc2.add(new Field("title", "Lucene Cookbook", TextField.TYPE_STORED)); indexWriter.addDocument(doc2); // Write index to the directory indexWriter.close();
w IndexWriter w ΠϯσοΫεͷॻ͖ࠐΈΛΦʔέετϨʔγϣϯ͢ΔΫϥε w addDocument()ϝιουͰDocumentΛՃ w close()͢ΔͱʢσϑΥϧτͷઃఆͰʣDirectoryʹ ॻ͖ࠐΉ // Create a directory for storing Lucene index Path indexDirPath = Files.createDirectory(Path.of("index")); Directory directory = FSDirectory.open(indexDirPath); // Set up IndexWriter Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter indexWriter = new IndexWriter(directory, config); // Index a document: "Lucene in Action" Document doc1 = new Document(); doc1.add(new Field("title", "Lucene in Action", TextField.TYPE_STORED)); indexWriter.addDocument(doc1); // Index a document: "Lucene Cookbook" Document doc2 = new Document(); doc2.add(new Field("title", "Lucene Cookbook", TextField.TYPE_STORED)); indexWriter.addDocument(doc2); // Write index to the directory indexWriter.close();
w όοϑΝʹอଘ͞Εͨ3".αΠζจॻͳͲ͕τϦΨʔ w ໌ࣔతʹflush()ΛݺͿ͜ͱͰϑϥογϡͰ͖Δ ʢͨͩ͠DPNNJUॲཧ͠ͳ͍ʣ w commit()ΛݺͿͱϑϥογϡ͔ͯ͠ΒDPNNJUॲཧΛߦ͏ addDocument() IndexWriter Directory #V ff FSJO3". 'MVTI
_0_Lucene84_0.tip _0_Lucene84_0.tmd segments_1 write.lock *OEFYBGUFSTUDPNNJU 4FHNFOU 4FHNFOUT'JMF -PDL'JMF TFHNFOUT@ 4FHNFOU w ΠϯσοΫεෳͷηάϝϯτ TFHNFOU ͔ΒͳΔ w ͯ͢ಉ͡σΟϨΫτϦʹอଘ͞ΕΔ w ηάϝϯταϒΠϯσοΫε w ୯ମͰ΄΅-VDFOFΠϯσοΫεͱͯ͠ػೳ͢Δ w ηάϝϯτෳͷϑΝΠϧ͔ΒͳΔ w ϑΝΠϧ໊_gen.extPS_gen_Lucene84_0.extͷܗࣜ w &H_0.fnm _0_Lucene84_0.pos ʜ w genηάϝϯτͷੈ FH w extϑΥʔϚοτ͝ͱͷ֦ுࢠ FHGON QPT w IndexWriter͕ fl VTIͨ͠ͱ͖ʹηάϝϯτ͕ͭ࡞ΒΕΔ w DPNNJU͞Εͨͱ͖ʹॳΊͯsegments_N͔Βࢀর͞ΕΔ w N ʜ *OEFY4FHNFOUT -VDFOFJOEFY fi MFT
w MergePolicyɺͲͷηάϝϯτΛϚʔδ͢Δ͔Λܾఆ͢Δ w খ͍͞ηάϝϯτ͕େྔʹ͋Δͱݕࡧ͕͘ͳΔ w Ϛʔδͯ͠େ͖͍ηάϝϯτʹ·ͱΊΔ͜ͱͰύϑΥʔϚϯε্͕͢Δ w MergePolicy ʹΑͬͯΠϯσΩγϯάͷεϧʔϓοτશମͷෛՙͳͲΛνϡʔ χϯάͰ͖Δ 4FHNFOU 4FHNFOU 4FHNFOU 4FHNFOU 4FHNFOU 4FHNFOU SFG$IBOHJOH#JUT7JTVBMJ[JOH-VDFOFTTFHNFOUNFSHFT IUUQCMPHNJLFNDDBOEMFTTDPNWJTVBMJ[JOHMVDFOFTTFHNFOUNFSHFTIUNM merge()
&YFDVUF w -JOVYNBD04lucene-8.8.1/luke/luke.s h w 8JOEPXTlucene-8.8.1/luke/luke.bat SFG-VDFOFೖXJUI-VLFCZNPDPCFUB IUUQTNPDPCFUBNFEJVNDPNMVDFOF&#&"&XJUIMVLFBDDCDB
directory = FSDirectory.open(Path.of("index")); // Create an IndexSearcher IndexReader indexReader = DirectoryReader.open(directory); IndexSearcher indexSearcher = new IndexSearcher(indexReader); // Create Query object that searches for "lucene" on "title" field Query query = new TermQuery(new Term("title", "lucene")); TopDocs results = indexSearcher.search(query, 10); ScoreDoc[] hits = results.scoreDocs; // Iterate through the results for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); System.out.println("Hit: " + hitDoc.get("title")); } // Post-processing indexReader.close(); directory.close(); w IndexSearcher w IndexReaderΛ௨ͯ͠ΠϯσοΫεʹΞΫηε w TermQuery w TermʢసஔΠϯσοΫεʹ͓͚ΔΩʔʣͰݕࡧ w BOBMZ[FޙͷςΩετΛ͢ w -VDFOFͰݕࡧͯ͠ώοτͤͣɺMVDFOFͳΒώοτ
w BOBMZ[FޙͷςΩετΛ͢ w -VDFOFͰݕࡧͯ͠ώοτͤͣɺMVDFOFͳΒώοτ w IndexSearcher#search()ʹͯ͠ݕࡧ w TopDocsʢ5PQLͷ݁Ռʣ͕ಘΒΕΔ // Open a directory which stores index Directory directory = FSDirectory.open(Path.of("index")); // Create an IndexSearcher IndexReader indexReader = DirectoryReader.open(directory); IndexSearcher indexSearcher = new IndexSearcher(indexReader); // Create Query object that searches for "lucene" on "title" field Query query = new TermQuery(new Term("title", "lucene")); TopDocs results = indexSearcher.search(query, 10); ScoreDoc[] hits = results.scoreDocs; // Iterate through the results for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); System.out.println("Hit: " + hitDoc.get("title")); } // Post-processing indexReader.close(); directory.close();
IUUQTMVDFOFBQBDIFPSHDPSF@@DPSFJOEFYIUNM w $IBOHFT IUUQTMVDFOFBQBDIFPSHDPSF@@DIBOHFT$IBOHFTIUNM w *TTVFT IUUQTJTTVFTBQBDIFPSHKJSBQSPKFDUT-6$&/&JTTVFT w #PPLT w -VDFOFJO"DUJPO 4FDPOE&EJUJPO IUUQTXXXNBOOJOHDPNCPPLTMVDFOFJOBDUJPOTFDPOEFEJUJPO w 7JEFPT w -VDJEXPSLT IUUQTXXXZPVUVCFDPNDIBOOFM6$1*U0EG6L@UKMWRHHL:+T"TFBSDI RVFSZ-VDFOF w -VDFOF4PMS3FWPMVUJPO IUUQTXXXZPVUVCFDPNDIBOOFM6$,V3S[&2:1QG$H$/JMH2WJEFPT