Lucy
  1. Lucy
  2. LUCY-184

Exception is thrown when searching an empty index.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.2.1 (incubating)
    • Fix Version/s: None
    • Component/s: Index
    • Labels:
      None

      Description

      It would be very useful if Lucy didn't throw an exception on an empty index.

      Uncaught exception from user code:
      	Index doesn't seem to contain any data
      	lucy_IxReader_do_open at /Users/trygvis/.cpan/build/Lucy-0.2.1-ApxzAL/core/Lucy/Index/IndexReader.c line 41
      	at lib/Hackeriet/Links/Index.pm line 118
              [snipped]
      

        Activity

        Hide
        Marvin Humphrey added a comment -

        This behavior is by design. The alternative to throwing an exception when
        attempting to open an index that doesn't exist is silent failure, which would
        be bad in the event that someone e.g. misspells the index directory name.

        There may be other ways of addressing the issue, such as supplying a routine
        to test whether an index exists and allowing the creation of dummy searcher.
        If you want to push the issue forward, please send email to the
        developer's list so that
        we can hammer out a design and build consensus.

        Show
        Marvin Humphrey added a comment - This behavior is by design. The alternative to throwing an exception when attempting to open an index that doesn't exist is silent failure, which would be bad in the event that someone e.g. misspells the index directory name. There may be other ways of addressing the issue, such as supplying a routine to test whether an index exists and allowing the creation of dummy searcher. If you want to push the issue forward, please send email to the developer's list so that we can hammer out a design and build consensus.
        Hide
        Trygve Laugstøl added a comment -

        I'd like some way around it at least, because I need to check to see if the item already is in the index before indexing it (I'm adding extra info to the document if it's already there).

        What are the options for proper ways? A flag that allows the user to search the index? A separate "index" object that represents the index on disk which can be queried for existence before creating the searcher?

        Show
        Trygve Laugstøl added a comment - I'd like some way around it at least, because I need to check to see if the item already is in the index before indexing it (I'm adding extra info to the document if it's already there). What are the options for proper ways? A flag that allows the user to search the index? A separate "index" object that represents the index on disk which can be queried for existence before creating the searcher?
        Hide
        Marvin Humphrey added a comment -

        For a workaround that works right now, you can simply wrap the IndexSearcher
        constructor in an eval:

            my $searcher = eval { Lucy::Search::IndexSearcher->new(index => $index) };
            return unless $searcher;
            ...
        

        This is similar to one of the library-level options, which is adding an open()
        class method to IndexSearcher which returns false and sets Lucy->error instead
        of throwing an exception.

        Show
        Marvin Humphrey added a comment - For a workaround that works right now, you can simply wrap the IndexSearcher constructor in an eval: my $searcher = eval { Lucy::Search::IndexSearcher->new(index => $index) }; return unless $searcher; ... This is similar to one of the library-level options, which is adding an open() class method to IndexSearcher which returns false and sets Lucy->error instead of throwing an exception.
        Hide
        Trygve Laugstøl added a comment -

        That's exactly what I did, but that turns into a PITA when i actually do fail something (which happen all the time when I'm developing ). It is possible to throw two different kinds of exceptions?

        Show
        Trygve Laugstøl added a comment - That's exactly what I did, but that turns into a PITA when i actually do fail something (which happen all the time when I'm developing ). It is possible to throw two different kinds of exceptions?
        Hide
        Nick Wellnhofer added a comment -

        Here's a way to test for an empty index without catching exceptions:

        my $reader = Lucy::Index::PolyReader->open( index => $index );
        my $is_empty = ! @{ $reader->seg_readers };
        
        Show
        Nick Wellnhofer added a comment - Here's a way to test for an empty index without catching exceptions: my $reader = Lucy::Index::PolyReader->open( index => $index ); my $is_empty = ! @{ $reader->seg_readers };

          People

          • Assignee:
            Unassigned
            Reporter:
            Trygve Laugstøl
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development