Still won't work (same as before).

 @Test
    public void testUpdate() throws IOException,
ParserConfigurationException, SAXException, ParseException {
        Analyzer analyzer = getAnalyzer();
        QueryParser parser = new QueryParser(Version.LUCENE_32, content,
analyzer);
        Query allQ = parser.parse("*:*");

        IndexWriter writer = getWriter();
        final IndexReader indexReader = IndexReader.open(writer, true);

        IndexSearcher searcher = new IndexSearcher(indexReader);
        TopDocs docs = searcher.search(allQ, 10);
        assertEquals(0, docs.totalHits); // empty/no index

        Document doc = getDoc();
        writer.addDocument(doc);
        writer.commit();

    *    indexReader.reopen();
        searcher = new IndexSearcher(indexReader);
        docs = searcher.search(allQ, 10);*
        assertEquals(1,docs.totalHits);
    }

  private Document getDoc() {
        Document doc = new Document();
        doc.add(new Field("id", "0", Field.Store.YES,
Field.Index.NOT_ANALYZED));
        return doc;
    }

 private IndexWriter getWriter() throws IOException {            // 2
        return new IndexWriter(directory, new WhitespaceAnalyzer(), // 2
                IndexWriter.MaxFieldLength.UNLIMITED); // 2
    }

On Tue, Jul 5, 2011 at 8:15 PM, Michael McCandless <
luc...@mikemccandless.com> wrote:

> Sorry, you must reopen the underlying IndexReader, and then make a new
> IndexSearcher from the reopened reader.
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> On Tue, Jul 5, 2011 at 2:12 PM, Gabriele Kahlout
> <gabri...@mysimpatico.com> wrote:
> > and how do you do that? There is no reopen method
> >
> > On Tue, Jul 5, 2011 at 8:09 PM, Michael McCandless <
> > luc...@mikemccandless.com> wrote:
> >
> >> After your writer.commit you need to reopen your searcher to see the
> >> changes.
> >>
> >> Mike McCandless
> >>
> >> http://blog.mikemccandless.com
> >>
> >> On Tue, Jul 5, 2011 at 1:48 PM, Gabriele Kahlout
> >> <gabri...@mysimpatico.com> wrote:
> >> >    @Test
> >> >    public void testUpdate() throws IOException,
> >> > ParserConfigurationException, SAXException, ParseException {
> >> >        Analyzer analyzer = getAnalyzer();
> >> >        QueryParser parser = new QueryParser(Version.LUCENE_32,
> content,
> >> > analyzer);
> >> >        Query allQ = parser.parse("*:*");
> >> >
> >> >        IndexWriter writer = getWriter();
> >> >        IndexSearcher searcher = new
> >> IndexSearcher(IndexReader.open(writer,
> >> > true));
> >> >        TopDocs docs = searcher.search(allQ, 10);
> >> > *        assertEquals(0, docs.totalHits); // empty/no index*
> >> >
> >> >        Document doc = getDoc();
> >> >        writer.addDocument(doc);
> >> >        writer.commit();
> >> >
> >> >        docs = searcher.search(allQ, 10);
> >> > *        assertEquals(1,docs.totalHits); //it fails here.
> docs.totalHits
> >> > equals 0*
> >> >    }
> >> > What am I doing wrong here?
> >> >
> >> > If I initialize searcher with new IndexSearcher(directory) I'm told:
> >> > org.apache.lucene.index.IndexNotFoundException: no segments* file
> found
> >> in
> >> > org.apache.lucene.store.RAMDirectory@3caa4blockFactory
> >> =org.apache.lucene.store.SingleInstanceLockFactory@ed0220c:
> >> > files: []
> >> >
> >> > --
> >> > Regards,
> >> > K. Gabriele
> >> >
> >> > --- unchanged since 20/9/10 ---
> >> > P.S. If the subject contains "[LON]" or the addressee acknowledges the
> >> > receipt within 48 hours then I don't resend the email.
> >> > subject(this) ∈ L(LON*) ∨ ∃x. (x ∈ MyInbox ∧ Acknowledges(x, this) ∧
> >> time(x)
> >> > < Now + 48h) ⇒ ¬resend(I, this).
> >> >
> >> > If an email is sent by a sender that is not a trusted contact or the
> >> email
> >> > does not contain a valid code then the email is not received. A valid
> >> code
> >> > starts with a hyphen and ends with "X".
> >> > ∀x. x ∈ MyInbox ⇒ from(x) ∈ MySafeSenderList ∨ (∃y. y ∈ subject(x) ∧ y
> ∈
> >> > L(-[a-z]+[0-9]X)).
> >> >
> >>
> >
> >
> >
> > --
> > Regards,
> > K. Gabriele
> >
> > --- unchanged since 20/9/10 ---
> > P.S. If the subject contains "[LON]" or the addressee acknowledges the
> > receipt within 48 hours then I don't resend the email.
> > subject(this) ∈ L(LON*) ∨ ∃x. (x ∈ MyInbox ∧ Acknowledges(x, this) ∧
> time(x)
> > < Now + 48h) ⇒ ¬resend(I, this).
> >
> > If an email is sent by a sender that is not a trusted contact or the
> email
> > does not contain a valid code then the email is not received. A valid
> code
> > starts with a hyphen and ends with "X".
> > ∀x. x ∈ MyInbox ⇒ from(x) ∈ MySafeSenderList ∨ (∃y. y ∈ subject(x) ∧ y ∈
> > L(-[a-z]+[0-9]X)).
> >
>



-- 
Regards,
K. Gabriele

--- unchanged since 20/9/10 ---
P.S. If the subject contains "[LON]" or the addressee acknowledges the
receipt within 48 hours then I don't resend the email.
subject(this) ∈ L(LON*) ∨ ∃x. (x ∈ MyInbox ∧ Acknowledges(x, this) ∧ time(x)
< Now + 48h) ⇒ ¬resend(I, this).

If an email is sent by a sender that is not a trusted contact or the email
does not contain a valid code then the email is not received. A valid code
starts with a hyphen and ends with "X".
∀x. x ∈ MyInbox ⇒ from(x) ∈ MySafeSenderList ∨ (∃y. y ∈ subject(x) ∧ y ∈
L(-[a-z]+[0-9]X)).

Reply via email to