Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 97446 invoked from network); 11 Dec 2007 23:11:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Dec 2007 23:11:20 -0000 Received: (qmail 78850 invoked by uid 500); 11 Dec 2007 23:11:03 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 78814 invoked by uid 500); 11 Dec 2007 23:11:03 -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 78803 invoked by uid 99); 11 Dec 2007 23:11:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2007 15:11:03 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rsivak@istandfor.com designates 72.32.36.243 as permitted sender) Received: from [72.32.36.243] (HELO mx0.istandfor.com) (72.32.36.243) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2007 23:11:04 +0000 Received: from [192.168.1.42] (pool-70-18-194-158.ny325.east.verizon.net [70.18.194.158]) (authenticated bits=0) by mail.istandfor.com (8.12.11.20060308/8.12.11) with ESMTP id lBBNAgKZ009135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 11 Dec 2007 17:10:43 -0600 Message-ID: <475F18F4.90602@istandfor.com> Date: Tue, 11 Dec 2007 18:10:44 -0500 From: Ruslan Sivak User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: java-user@lucene.apache.org Subject: Re: Refreshing RAMDirectory References: <475F1134.6050402@istandfor.com> <359a92830712111459o620d76c9kb6f4ea3f897f6d41@mail.gmail.com> In-Reply-To: <359a92830712111459o620d76c9kb6f4ea3f897f6d41@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org The on-disk index gets updated. Something like this: The second indexDoc function is what does the actual indexing, but this should have the relevant content. public void indexDoc(int userId) throws ClassNotFoundException, SQLException, CorruptIndexException, IOException { IndexWriter iw=new IndexWriter(indexName, analyzer, false); deleteDoc(userId, iw); ResultSet rs=sg.getSomeData(userId); indexDoc(iw,rs); iw.close(); } Russ Erick Erickson wrote: > I can't speak to the errors, but how is the index being updated? An > indexwriter buffers changes and periodically flushes them out to > disk. So the writer may not have flushed your data, depending > upon how it's written. > > Best > Erick > > On Dec 11, 2007 5:37 PM, Ruslan Sivak wrote: > > >> I have an index of about 10mb. Since it's so small, I would like to >> keep it loaded in memory, and reload it about every minute or so, >> assuming that it has changed on disk. I have the following code, which >> works, except it doesn't reload the changes. >> >> protected String indexName; >> protected IndexReader reader; >> private long lastCheck=0; >> ... >> protected IndexReader getReader() throws CorruptIndexException, >> IOException >> { >> if (reader==null || System.currentTimeMillis() > lastCheck+60000) >> { >> lastCheck=System.currentTimeMillis(); >> if (reader==null || !reader.isCurrent()) >> { >> if (reader!=null) >> reader.close(); >> >> Directory dir = new RAMDirectory(indexName); >> reader = IndexReader.open(dir); >> searcher = new IndexSearcher(reader); >> } >> } >> return reader; >> } >> >> >> Apparently reader.isCurrent() won't tell you if the underlying >> FSDirectory has changed. >> >> I also had the following code before: >> instead of >> if (reader==null || !reader.isCurrent()) >> I had >> if (reader==null || reader.getVersion() != >> IndexReader.getCurrentVersion(indexName)) >> >> >> I was getting a bunch of this indexreader is closed errors, and I'm not >> sure why there's no method like reader.isClosed(). >> >> Am I going about things the right way? Is there a better implementation >> of what I'm looking to do? Is there perhaps some function I'm not >> seeing which will let me know if the indexreader is closed? >> >> Russ >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >> For additional commands, e-mail: java-user-help@lucene.apache.org >> >> >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org