Lucene - Core
  1. Lucene - Core
  2. LUCENE-543

Wildcard query with no wildcard characters in the term throws StringIndexOutOfBounds exception

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: None
    • Component/s: core/search
    • Labels:
      None
    • Environment:

      linux and windows, JRE 1.4.2_06 Lucene 1.9.1

      Description

      Query q1 = new WildcardQuery(new Term("Text", "a"));
      Hits hits = searcher.search(q1);

      Caught Exception
      java.lang.StringIndexOutOfBoundsException : String index out of range: -1
      at java.lang.String.substring(Unknown Source)
      at org.apache.lucene.search.WildcardTermEnum.<init>(WildcardTermEnum.java:65)
      at org.apache.lucene.search.WildcardQuery.getEnum (WildcardQuery.java:38)
      at org.apache.lucene.search.MultiTermQuery.rewrite(MultiTermQuery.java:54)
      at org.apache.lucene.search.IndexSearcher.rewrite(IndexSearcher.java:137)
      at org.apache.lucene.search.Query.weight (Query.java:92)
      at org.apache.lucene.search.Hits.<init>(Hits.java:41)
      at org.apache.lucene.search.Searcher.search(Searcher.java:44)
      at org.apache.lucene.search.Searcher.search(Searcher.java:36)
      at QuickTest.main(QuickTest.java:45)

      From Erik Hatcher

      Feel free to log this as a bug report in our JIRA issue tracker. It
      seems like a reasonable change to make, such that a WildcardQuery
      without a wildcard character would behave like TermQuery.

      1. lucene543.patch
        2 kB
        Michael Busch

        Activity

        Hide
        Erik Hatcher added a comment -

        I owed you one! And besides, I should have done this myself months ago when this was initially reported.

        Show
        Erik Hatcher added a comment - I owed you one! And besides, I should have done this myself months ago when this was initially reported.
        Hide
        Michael Busch added a comment -

        Wow that was quick, Erik!

        Show
        Michael Busch added a comment - Wow that was quick, Erik!
        Hide
        Erik Hatcher added a comment -

        Committed - thanks Michael!

        Show
        Erik Hatcher added a comment - Committed - thanks Michael!
        Hide
        Michael Busch added a comment -

        Overwrites rewrite() in WildcardQuery so that it returns a TermQuery if and only if the term does not contain a wildcard character. I also added a new test to TestWildcard that fails with the old version and passes with the patch.

        All units tests pass and the patch compiles with a 1.4 JVM

        Show
        Michael Busch added a comment - Overwrites rewrite() in WildcardQuery so that it returns a TermQuery if and only if the term does not contain a wildcard character. I also added a new test to TestWildcard that fails with the old version and passes with the patch. All units tests pass and the patch compiles with a 1.4 JVM

          People

          • Assignee:
            Michael Busch
            Reporter:
            Erick Erickson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development