Lucene - Core
  1. Lucene - Core
  2. LUCENE-1923

Add toString() or getName() method to IndexReader

    Details

    • Type: Wish Wish
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0-ALPHA
    • Component/s: core/index
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      It would be very useful for debugging if IndexReader either had a getName() method, or a toString() implementation that would get a string identification for the reader.

      for SegmentReader, this would return the same as getSegmentName()
      for Directory readers, this would return the "generation id"?
      for MultiReader, this could return something like "multi(sub reader name, sub reader name, sub reader name, ...)

      right now, i have to check instanceof for SegmentReader, then call getSegmentName(), and for all other IndexReader types, i would have to do something like get the IndexCommit and get the generation off it (and this may throw UnsupportedOperationException, at which point i have would have to recursively walk sub readers and try again)

      I could work up a patch if others like this idea

      1. LUCENE-1923.patch
        6 kB
        Michael McCandless
      2. LUCENE-1923.patch
        8 kB
        Michael McCandless
      3. LUCENE-1923.patch
        3 kB
        Tim Smith

        Activity

        Hide
        Michael McCandless added a comment -

        +1

        Show
        Michael McCandless added a comment - +1
        Hide
        Tim Smith added a comment -

        I'll work up a patch that will do the following:

        add getName() method to IndexReader (and all subclasses (SegmentReader, DirectoryReader, MultiReader, any others i'm not currently aware of that i track down)

        have toString() return "indexreaderclassname(getName())"

        so, toString for a SegmentReader will look something like:
        "org.apache.lucene.index.SegmentReader(_ae)"

        for a DirectoryReader, it'll look like:
        "org.apache.lucene.index.DirectoryReader(segments_7)"

        Show
        Tim Smith added a comment - I'll work up a patch that will do the following: add getName() method to IndexReader (and all subclasses (SegmentReader, DirectoryReader, MultiReader, any others i'm not currently aware of that i track down) have toString() return "indexreaderclassname(getName())" so, toString for a SegmentReader will look something like: "org.apache.lucene.index.SegmentReader(_ae)" for a DirectoryReader, it'll look like: "org.apache.lucene.index.DirectoryReader(segments_7)"
        Hide
        Michael McCandless added a comment -

        That sounds like a good approach.

        Though maybe getName() for DirectoryReader should state segments_7 plus the names of the segments?

        Show
        Michael McCandless added a comment - That sounds like a good approach. Though maybe getName() for DirectoryReader should state segments_7 plus the names of the segments?
        Hide
        Mark Miller added a comment -

        Hows that patch coming

        Show
        Mark Miller added a comment - Hows that patch coming
        Hide
        Tim Smith added a comment -

        i won't have the time till after the new year.

        if someone else wants to work up a patch, go for it (this seems simple enough and adds some nice info capabilities for logging/etc), otherwise, i'll get to it when i can

        Show
        Tim Smith added a comment - i won't have the time till after the new year. if someone else wants to work up a patch, go for it (this seems simple enough and adds some nice info capabilities for logging/etc), otherwise, i'll get to it when i can
        Hide
        Tim Smith added a comment -

        Here's a simple patch to get the ball rolling

        This adds a "getName() method to IndexReader

        the default implementation will be:
        SimleClassName(subreader.getName(), subreader.getName(), ...)

        SegmentReader will return same value as getSegmentName()

        DirectoryReader will return:
        DirectoryReader(segment_N, segment.getName(), segment.getName(), ...)

        ParallelReader will return:
        ParallelReader(parallelReader1.getName(), parallelReader2.getName(), ...)

        this currently does not have a toString() implementation return getName()

        do with this patch as you will

        Show
        Tim Smith added a comment - Here's a simple patch to get the ball rolling This adds a "getName() method to IndexReader the default implementation will be: SimleClassName(subreader.getName(), subreader.getName(), ...) SegmentReader will return same value as getSegmentName() DirectoryReader will return: DirectoryReader(segment_N, segment.getName(), segment.getName(), ...) ParallelReader will return: ParallelReader(parallelReader1.getName(), parallelReader2.getName(), ...) this currently does not have a toString() implementation return getName() do with this patch as you will
        Hide
        Michael McCandless added a comment -

        Is there any reason not to simply use toString()? Why create getName?

        Show
        Michael McCandless added a comment - Is there any reason not to simply use toString()? Why create getName?
        Hide
        Tim Smith added a comment -

        added getName() in case anyone is currently relying on current (default) output from toString() on index readers

        feel free to rename the getName() methods to toString()

        Show
        Tim Smith added a comment - added getName() in case anyone is currently relying on current (default) output from toString() on index readers feel free to rename the getName() methods to toString()
        Hide
        Michael McCandless added a comment -

        OK new patch attached, cutting over to toString, and also moving SegmentInfo's segString -> toString.

        Show
        Michael McCandless added a comment - OK new patch attached, cutting over to toString, and also moving SegmentInfo's segString -> toString.
        Hide
        Michael McCandless added a comment -

        Thanks Tim!

        Show
        Michael McCandless added a comment - Thanks Tim!
        Hide
        Michael McCandless added a comment -

        A few things still to fix.... a RODirReader doesn't toString right; the SR's should add a * (eg) if they have pending changes; the SR's should also reflect accurate delCount when they have pending deletes. I'll work on this...

        Show
        Michael McCandless added a comment - A few things still to fix.... a RODirReader doesn't toString right; the SR's should add a * (eg) if they have pending changes; the SR's should also reflect accurate delCount when they have pending deletes. I'll work on this...
        Hide
        Michael McCandless added a comment -

        New patch fixing above issues...

        Show
        Michael McCandless added a comment - New patch fixing above issues...

          People

          • Assignee:
            Michael McCandless
            Reporter:
            Tim Smith
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development