Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 36611 invoked from network); 11 Oct 2010 20:45:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Oct 2010 20:45:49 -0000 Received: (qmail 50559 invoked by uid 500); 11 Oct 2010 20:45:47 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 50508 invoked by uid 500); 11 Oct 2010 20:45:46 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 50500 invoked by uid 99); 11 Oct 2010 20:45:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Oct 2010 20:45:46 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of erickerickson@gmail.com designates 209.85.216.176 as permitted sender) Received: from [209.85.216.176] (HELO mail-qy0-f176.google.com) (209.85.216.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Oct 2010 20:45:42 +0000 Received: by qyk29 with SMTP id 29so5284018qyk.14 for ; Mon, 11 Oct 2010 13:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=L6TkrzIDOYkAxfdPyf6JdMMMV8AzqJw5DFfg4j/g1rk=; b=rHW0njwHfEGULdFvfdzHxAGEqkDXdGMtTuzFnytieYauJRnvF4HB8LFUuVfuxXFkX8 4O0+nMEPe5O7kP1WMna1n0tsfytH4mpFQ1xfp1pjPLokXA2nZlpiuRljUScc8U9LOpJT rKbj0p4g3IeH12pPnf4oeVz5l0Fj5qVhtWjgU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=YKMc4g9eAt4hFeNkHubCxqPZNXkoIGJSrykVeLjSwp45dMrfh4YIm9J4OFimDo1mJD aWQU76NHC8S8EAIUcGhMQ6zU1GmzKI6cTlwXKcEbBKxTx5Fe+NvL8S4hkrNTV7wsroF5 0xS+G8/RHlkHf5kz/38YLM66Aj6nfvdMe4Uqg= MIME-Version: 1.0 Received: by 10.229.221.131 with SMTP id ic3mr5492297qcb.152.1286829920802; Mon, 11 Oct 2010 13:45:20 -0700 (PDT) Received: by 10.229.232.19 with HTTP; Mon, 11 Oct 2010 13:45:20 -0700 (PDT) In-Reply-To: References: <001901cb5d34$92cef3b0$b86cdb10$@thetaphi.de> <004301cb5d9e$91a5cfd0$b4f16f70$@thetaphi.de> Date: Mon, 11 Oct 2010 16:45:20 -0400 Message-ID: Subject: Re: flushing index From: Erick Erickson To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=0016362841a450d82b04925d70a3 --0016362841a450d82b04925d70a3 Content-Type: text/plain; charset=ISO-8859-1 It's a good idea to start a new thread when asking a different question, see: http://people.apache.org/~hossman/#threadhijack I have to ask why you want to integrate the RAM directory. If you're using it to speed up indexing, you're probably making way more work for yourself than you need to. If you're trying to do something with Near Real Time, one suggestion is to just not bother. Add docs to the RAM directory AND your FSDirectory simultaneously. The data you index to FSDir won't be visible until you reopen the FSDir reader, so your flush could then be just reopen everything... Best Erick On Mon, Oct 11, 2010 at 1:34 PM, Yakob wrote: > On 9/29/10, Erick Erickson wrote: > > Nope, never used jNotify, so I don't have any code handy... > > > > Good luck! > > Erick > > > > so I did try JNotify but there is seems to be some bug in it that I > find it hards to integrate in my lucene source code.so I had to try a > looping option instead. > > > http://stackoverflow.com/questions/3840844/error-exception-access-violation-in-jnotify > > so anyway, I had another question now. I was trying to make a lucene > source code that can do indexing and store them first in a memory > using RAMDirectory and then flush this index in a memory into a disk > using FSDirectory. I had done some modifications of this code but to > no avail. maybe some of you can help me out a bit. > here is the source code again. > > import java.io.File; > import java.io.FileReader; > import java.io.IOException; > import org.apache.lucene.analysis.SimpleAnalyzer; > import org.apache.lucene.document.Document; > import org.apache.lucene.document.Field; > import org.apache.lucene.index.IndexWriter; > import org.apache.lucene.store.FSDirectory; > > > public class SimpleFileIndexer { > > > public static void main(String[] args) throws Exception { > > int i=0; > while(i<10) { > File indexDir = new > File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi"); > File dataDir = new > File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi"); > String suffix = "txt"; > > SimpleFileIndexer indexer = new SimpleFileIndexer(); > > int numIndex = indexer.index(indexDir, dataDir, suffix); > > System.out.println("Total files indexed " + numIndex); > i++; > Thread.sleep(10000); > > } > } > > > > private int index(File indexDir, File dataDir, String suffix) throws > Exception { > > IndexWriter indexWriter = new IndexWriter( > FSDirectory.open(indexDir), > new SimpleAnalyzer(), > true, > IndexWriter.MaxFieldLength.LIMITED); > indexWriter.setUseCompoundFile(false); > > indexDirectory(indexWriter, dataDir, suffix); > > int numIndexed = indexWriter.maxDoc(); > indexWriter.optimize(); > indexWriter.close(); > > return numIndexed; > > } > > private void indexDirectory(IndexWriter indexWriter, File dataDir, > String suffix) throws IOException { > File[] files = dataDir.listFiles(); > for (int i = 0; i < files.length; i++) { > File f = files[i]; > if (f.isDirectory()) { > indexDirectory(indexWriter, f, suffix); > } > else { > indexFileWithIndexWriter(indexWriter, f, > suffix); > } > } > } > > private void indexFileWithIndexWriter(IndexWriter indexWriter, File > f, String suffix) throws IOException { > if (f.isHidden() || f.isDirectory() || !f.canRead() || > !f.exists()) { > return; > } > if (suffix!=null && !f.getName().endsWith(suffix)) { > return; > } > System.out.println("Indexing file " + f.getCanonicalPath()); > > Document doc = new Document(); > doc.add(new Field("contents", new FileReader(f))); > doc.add(new Field("filename", f.getCanonicalPath(), > Field.Store.YES, > Field.Index.ANALYZED)); > > indexWriter.addDocument(doc); > } > > } > > so what's the best way for me to integrate RAMDirectory in that source > code before putting them in FSDirectory. any help would be appreciated > though. > thanks > > > -- > http://jacobian.web.id > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > > --0016362841a450d82b04925d70a3--