FAQ
Hi

Can someone guide me please?

I have inherited a Lucene application and am attempting to update the
API from 2.0 to 2.4.
I note that the 2.4 CHANGELOG talks of opening an IndexReader with
read-only=true to improve performance. Does anyone know how to do this?
I have been combing my predecessor's fully working code, and cannot find
/anywhere/ where an IndexReader is actually opened! He seems to do this
sort of thing instead:

First he instantiates a DelayCloseIndexSearcher object, passing it a
Directory object. (I think he got DelayCloseIndexSearcher off the net -
according to the Javadoc, the author was Luc Vanlerberghe??).
He then accesses the IndexReader like so:

IndexReader reader = *searcher.getIndexReader()*;
TermEnum te = reader.terms();
...

So does that mean if you don't explicitly open an IndexReader, the
IndexSearcher will do it for you? Or what?

Thanks,

- Chris

Search Discussions

  • Mark Miller at Dec 8, 2008 at 12:33 pm

    Chris Bamford wrote:
    So does that mean if you don't explicitly open an IndexReader, the
    IndexSearcher will do it for you? Or what?
    Right. The IndexReader takes a Directory, and the IndexSearcher takes an
    IndexReader - there are sugar constructors though - An IndexSearcher
    will also accept a String file path, which will be used to create a
    Directory which is used to create an IndexReader. It will also take a
    Directory, which will be used to create an IndexReader. It will also
    just accept the IndexReader.

    So you have to find how that IndexReader is being created (or where) and
    change the code so that you get to create it, and when you do, do it
    read-only. It should be easier than that roundabout info sounds.

    - Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Chris Bamford at Dec 8, 2008 at 1:38 pm
    Thanks Mark.

    I have identified the spot where I need to do the surgery. However, I
    discover that IndexReader is abstract, but it seems crazy that I need to
    make a concrete class for which I have no need to add any of my own
    logic... Is there a suitable subclass I can use? The documented ones -
    FilterIndexReader, InstantiatedIndexReader, MultiReader, ParallelReader
    - all seem too complicated for what I need. My only requirement is to
    open it read-only!

    Am I missing something?

    Mark Miller wrote:
    Chris Bamford wrote:
    So does that mean if you don't explicitly open an IndexReader, the
    IndexSearcher will do it for you? Or what?
    Right. The IndexReader takes a Directory, and the IndexSearcher takes
    an IndexReader - there are sugar constructors though - An
    IndexSearcher will also accept a String file path, which will be used
    to create a Directory which is used to create an IndexReader. It will
    also take a Directory, which will be used to create an IndexReader. It
    will also just accept the IndexReader.

    So you have to find how that IndexReader is being created (or where)
    and change the code so that you get to create it, and when you do, do
    it read-only. It should be easier than that roundabout info sounds.

    - Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    --
    Chris Bamford
    Senior Development Engineer
    *Scalix*
    chris.bamford@scalix.com
    Tel: +44 (0)1344 381814
    www.scalix.com

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Mark Miller at Dec 8, 2008 at 1:53 pm
    Look for the static factory methods on IndexReader.

    - Mark

    Chris Bamford wrote:
    Thanks Mark.

    I have identified the spot where I need to do the surgery. However, I
    discover that IndexReader is abstract, but it seems crazy that I need
    to make a concrete class for which I have no need to add any of my own
    logic... Is there a suitable subclass I can use? The documented ones
    - FilterIndexReader, InstantiatedIndexReader, MultiReader,
    ParallelReader - all seem too complicated for what I need. My only
    requirement is to open it read-only!

    Am I missing something?

    Mark Miller wrote:
    Chris Bamford wrote:
    So does that mean if you don't explicitly open an IndexReader, the
    IndexSearcher will do it for you? Or what?
    Right. The IndexReader takes a Directory, and the IndexSearcher takes
    an IndexReader - there are sugar constructors though - An
    IndexSearcher will also accept a String file path, which will be used
    to create a Directory which is used to create an IndexReader. It will
    also take a Directory, which will be used to create an IndexReader.
    It will also just accept the IndexReader.

    So you have to find how that IndexReader is being created (or where)
    and change the code so that you get to create it, and when you do, do
    it read-only. It should be easier than that roundabout info sounds.

    - Mark

    ---------------------------------------------------------------------
    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
  • Chris Bamford at Dec 8, 2008 at 2:11 pm
    Mark
    Look for the static factory methods on IndexReader.
    I take it you mean IndexReader.open (dir, true) ?
    If so, how do I then pass that into DelayCloseIndexSearcher() so that I
    can continue to rely on all the existing calls like:

    IndexReader reader = contentSearcher.getIndexReader();

    Put another way, how do I associate the static IndexReader with an
    IndexSearcher object so I can use getIndexReader() to get it again?

    Thanks for your continued help with this :-)

    Chris

    Mark Miller wrote:
    Look for the static factory methods on IndexReader.

    - Mark

    Chris Bamford wrote:
    Thanks Mark.

    I have identified the spot where I need to do the surgery. However,
    I discover that IndexReader is abstract, but it seems crazy that I
    need to make a concrete class for which I have no need to add any of
    my own logic... Is there a suitable subclass I can use? The
    documented ones - FilterIndexReader, InstantiatedIndexReader,
    MultiReader, ParallelReader - all seem too complicated for what I
    need. My only requirement is to open it read-only!

    Am I missing something?

    Mark Miller wrote:
    Chris Bamford wrote:
    So does that mean if you don't explicitly open an IndexReader, the
    IndexSearcher will do it for you? Or what?
    Right. The IndexReader takes a Directory, and the IndexSearcher
    takes an IndexReader - there are sugar constructors though - An
    IndexSearcher will also accept a String file path, which will be
    used to create a Directory which is used to create an IndexReader.
    It will also take a Directory, which will be used to create an
    IndexReader. It will also just accept the IndexReader.

    So you have to find how that IndexReader is being created (or where)
    and change the code so that you get to create it, and when you do,
    do it read-only. It should be easier than that roundabout info sounds.

    - Mark

    ---------------------------------------------------------------------
    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

    --
    Chris Bamford
    Senior Development Engineer
    *Scalix*
    chris.bamford@scalix.com
    Tel: +44 (0)1344 381814
    www.scalix.com
  • Mark Miller at Dec 8, 2008 at 4:39 pm

    Chris Bamford wrote:
    Mark
    Look for the static factory methods on IndexReader.
    I take it you mean IndexReader.open (dir, true) ? Yeah.
    If so, how do I then pass that into DelayCloseIndexSearcher() so that
    I can continue to rely on all the existing calls like:

    IndexReader reader = contentSearcher.getIndexReader();

    Put another way, how do I associate the static IndexReader with an
    IndexSearcher object so I can use getIndexReader() to get it again?
    Find where that contentSearcher is being created. Use a different
    constructor to create the Searcher - use the one that takes an
    IndexReader. Now you control the IndexReader creation, and you can use
    the readonly constructor option when you create it. That Searcher is
    either using a constructor that takes an IndexReader, or a Directory, or
    a String. If its using a String constructor, instead, use the Directory
    factory that takes a String, make a Directory, and use it to make an
    IndexReader that you build the IndexSearcher with. If its using a
    Directory, use that directory to make the IndexReader that is used for
    you IndexSearcher.
    Thanks for your continued help with this :-)

    Chris

    Mark Miller wrote:
    Look for the static factory methods on IndexReader.

    - Mark

    Chris Bamford wrote:
    Thanks Mark.

    I have identified the spot where I need to do the surgery. However,
    I discover that IndexReader is abstract, but it seems crazy that I
    need to make a concrete class for which I have no need to add any of
    my own logic... Is there a suitable subclass I can use? The
    documented ones - FilterIndexReader, InstantiatedIndexReader,
    MultiReader, ParallelReader - all seem too complicated for what I
    need. My only requirement is to open it read-only!

    Am I missing something?

    Mark Miller wrote:
    Chris Bamford wrote:
    So does that mean if you don't explicitly open an IndexReader, the
    IndexSearcher will do it for you? Or what?
    Right. The IndexReader takes a Directory, and the IndexSearcher
    takes an IndexReader - there are sugar constructors though - An
    IndexSearcher will also accept a String file path, which will be
    used to create a Directory which is used to create an IndexReader.
    It will also take a Directory, which will be used to create an
    IndexReader. It will also just accept the IndexReader.

    So you have to find how that IndexReader is being created (or
    where) and change the code so that you get to create it, and when
    you do, do it read-only. It should be easier than that roundabout
    info sounds.

    - Mark

    ---------------------------------------------------------------------
    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

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Chris Bamford at Dec 15, 2008 at 3:41 pm
    Thanks Mark, worked a treat.

    Mark Miller wrote:
    Chris Bamford wrote:
    Mark
    Look for the static factory methods on IndexReader.
    I take it you mean IndexReader.open (dir, true) ? Yeah.
    If so, how do I then pass that into DelayCloseIndexSearcher() so that
    I can continue to rely on all the existing calls like:

    IndexReader reader = contentSearcher.getIndexReader();

    Put another way, how do I associate the static IndexReader with an
    IndexSearcher object so I can use getIndexReader() to get it again?
    Find where that contentSearcher is being created. Use a different
    constructor to create the Searcher - use the one that takes an
    IndexReader. Now you control the IndexReader creation, and you can use
    the readonly constructor option when you create it. That Searcher is
    either using a constructor that takes an IndexReader, or a Directory,
    or a String. If its using a String constructor, instead, use the
    Directory factory that takes a String, make a Directory, and use it to
    make an IndexReader that you build the IndexSearcher with. If its
    using a Directory, use that directory to make the IndexReader that is
    used for you IndexSearcher.
    Thanks for your continued help with this :-)

    Chris

    Mark Miller wrote:
    Look for the static factory methods on IndexReader.

    - Mark

    Chris Bamford wrote:
    Thanks Mark.

    I have identified the spot where I need to do the surgery. However,
    I discover that IndexReader is abstract, but it seems crazy that I
    need to make a concrete class for which I have no need to add any
    of my own logic... Is there a suitable subclass I can use? The
    documented ones - FilterIndexReader, InstantiatedIndexReader,
    MultiReader, ParallelReader - all seem too complicated for what I
    need. My only requirement is to open it read-only!

    Am I missing something?

    Mark Miller wrote:
    Chris Bamford wrote:
    So does that mean if you don't explicitly open an IndexReader,
    the IndexSearcher will do it for you? Or what?
    Right. The IndexReader takes a Directory, and the IndexSearcher
    takes an IndexReader - there are sugar constructors though - An
    IndexSearcher will also accept a String file path, which will be
    used to create a Directory which is used to create an IndexReader.
    It will also take a Directory, which will be used to create an
    IndexReader. It will also just accept the IndexReader.

    So you have to find how that IndexReader is being created (or
    where) and change the code so that you get to create it, and when
    you do, do it read-only. It should be easier than that roundabout
    info sounds.

    - Mark

    ---------------------------------------------------------------------
    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

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    --
    Chris Bamford
    Senior Development Engineer
    *Scalix*
    chris.bamford@scalix.com
    Tel: +44 (0)1344 381814
    www.scalix.com

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedDec 8, '08 at 12:18p
activeDec 15, '08 at 3:41p
posts7
users2
websitelucene.apache.org

2 users in discussion

Chris Bamford: 4 posts Mark Miller: 3 posts

People

Translate

site design / logo © 2022 Grokbase