Thanks for a detailed answer. //Daniel
2010/7/6 Nicholas Paldino [.NET/C# MVP] <[email protected]> > Daniel, > > Given the way Lucene works, it's incorrect to shape your app in this > manner. > > Lucene revolves around the index, and the index is managed by the > IndexWriter. You should have one IndexWriter per index (in your case, it > would seem you have different indexes in different directories). This is > open for the life of your app; as your units of work (UOW) are completed, > you call Commit to commit the changes you have made back to the index. > > Now, when you need to perform searches on an index, you call > GetReader on the IndexWriter to get an IndexReader which you will use to > prime your searcher. There is no need for notifications of when a reader > is > updated. Readers (and searchers) are meant to be lightweight and > constructed on-the-fly and disposed of when the request is complete. > > I know it seems a little paradoxical to have a relationship between > the reader and the writer where a writer is the factory for the reader. > Ideally, the abstraction is that you would have an "index" abstraction and > then you would get readers and writers from that. > > That's just not how Lucene works, unfortunately (although I don't > disagree with the abstraction of having some sort of "Index" abstraction be > a factory for readers and writers). > > - Nick > > -----Original Message----- > From: Daniel Wertheim [mailto:[email protected]] > Sent: Tuesday, July 06, 2010 6:18 AM > To: [email protected] > Subject: Re: Problems with IndexSearcher > > Never heard of the XY-prob before but I'll keep it in mind. > > I'm still learning/getting started with Lucene and just got the book > "Lucene > in Action" hence my questions.... > > Scenario: > There's a unit of work (UOW) that can be adding, removing and updating > documents in an index. Each UOW can work with multiple IndexWriters, where > each writer is designated it's own directory to hold indexes. When the UOW > is "done" changes are committed. > > A long side there's one searcher per directory. These searchers are > longlived and not directly tied to the UOWs, hence I don't know if a writer > ever have created an index in the directory. Whenever a UOW is committed, > affected searchers are notified so that they can refresh themselves. But to > be able to create instances of the searchers I know must ensure that an > index exists in the directory and not just create them and let them sit > there waiting to provide their services as a searchers. As a newbie I just > looked at the "Directory" that is being passed to the Searcher and thought > "well it exists, hence no problems"..... > > //Daniel > > 2010/7/5 Digy <[email protected]> > > > Sorry, this is how lucene works. I can not think of a case where a > > IndexSearcher is needed on an not-existing-index. Could that be a XY > > problem? (http://www.perlmonks.org/index.pl?node_id=542341) > > > > > > > > "The XY problem is when you need to do X, and you think you can use Y to > do > > X, so you ask about how to do Y, when what you really should do is state > > what your X problem is. There may be a Z solution that is even better > than > > Y, but nobody can suggest it if X is never mentioned." > > > > > > > > DIGY. > > > > > > > > > > > > -----Original Message----- > > From: Daniel Wertheim [mailto:[email protected]] > > Sent: Tuesday, July 06, 2010 12:27 AM > > To: [email protected] > > Subject: Re: Problems with IndexSearcher > > > > > > > > I get that a searcher needs an index to search, but why not let us create > > an > > > > instance of the searcher which doesn't blow up untill consumed? It takes > an > > > > Directory as dependency, not a writer... The LuceneDirectory could be > > > > responsible for initializing the dir so that the searcher doesn't have a > > > > direct dependency on the writer. The dir should then notify dependent > > > > searcher(s), "hey, the indexed changed"... That way the searcher can be > > > > created and Or maybe return null as result of searches when no index > > exists. > > > > > > > > //Daniel > > > > > > > > 2010/7/5 Digy <[email protected]> > > > > > > > > > No. To make a search, you have to have an index > > > > > and Indexes are created with IndexWriter. > > > > > (creating an empty index with IndexReader(or IndexSearcher) would be > > weird) > > > > > DIGY > > > > > > > > > > -----Original Message----- > > > > > From: Daniel Wertheim [mailto:[email protected]] > > > > > Sent: Monday, July 05, 2010 10:03 PM > > > > > To: [email protected] > > > > > Subject: Re: Problems with IndexSearcher > > > > > > > > > > Hi, > > > > > Why? Doesn't that create an unclear coupling from the Searcher to the > > > > > Writer? > > > > > > > > > > Does this mean that they should be seen as one "unit"? > > > > > > > > > > //Daniel > > > > > > > > > > 2010/7/5 Digy <[email protected]> > > > > > > > > > > > No. You have to initialize it with an IndexWriter. > > > > > > DIGY > > > > > > > > > > > > -----Original Message----- > > > > > > From: Daniel Wertheim [mailto:[email protected]] > > > > > > Sent: Monday, July 05, 2010 7:59 PM > > > > > > To: [email protected] > > > > > > Subject: Fwd: Problems with IndexSearcher > > > > > > > > > > > > ---------- Forwarded message ---------- > > > > > > From: Daniel Wertheim <[email protected]> > > > > > > Date: 2010/7/5 > > > > > > Subject: Problems with IndexSearcher > > > > > > To: [email protected] > > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > Isn't it possible to create an instance of an IndexSearcher for a > > > > > directory > > > > > > that is empty? Note, I don't consume it, just create it, still > there's > > an > > > > > > exception thrown: > > > > > > > > > > > > "no segments* file found in Lucene.Net.Store.SimpleFSDirectory" > > > > > > > > > > > > If I create an writer first, everything works fine. > > > > > > > > > > > > //Daniel > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
