You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Erick Erickson <er...@gmail.com> on 2006/04/07 16:28:05 UTC
Exception in WildCardQuery
So I'm trying to do silly stuff, just to poke a bit at wildcard queries. So
sue me... But I ran across this....
And yes, I know that creating a wildcard query is dangerous and downright
silly when you don't have a wildcard in the term, but this still seems like
a case should, say, default to a simple query rather than throw an
exception....
Lucene 1.9.1
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)
FWIW
Erick
Re: Exception in WildCardQuery
Posted by karl wettin <ka...@snigel.net>.
8 apr 2006 kl. 19.04 skrev Erick Erickson:
> I have to disagree.
> Optimization where it really doesn't count is, in my experience, bad.
> Period.
My intent was not to ephasise on optimization. The waste of
clockticks is just a side effect from what I consider bad design.
WildcardQuery and TermQuery do diffrent things. If I want to
encapsulate the functions of both in one class I write a factory.
class TermOrWildcardQuery implements Query {
private Query factory(Term t) {
if (t.termText.endsWith("*")) return new WildcardQuery(t); else
return new TermQuery(t);
}
}
I have never used such a factory, but my guess is that
programmatically I would always know If I wanted to use a wildcard or
not. So only when writing a primitive query parser for human entered
text could I see the use for such a thing. Perhaps then it is then
better to write a real parser/lexer using Antlr or JavaCC?
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Exception in WildCardQuery
Posted by Erick Erickson <er...@gmail.com>.
I have to disagree. Nowhere in the javadoc is this condition noted. There is
no way for a user to know that this is a restriction, and forcing developers
to find this by having a program fail, even with a better error message,
is...er...unfortunate. Even if this were in the javadoc, I still have to
remember it. And my memory isn't what it used to be....
Optimization where it really doesn't count is, in my experience, bad.
Period. I'm making the assumption that setting up the query is a tiny
fraction of the time spent in a search. I'm perfectly willing to lose those
"very few clockticks" in code that accounts for a tiny, tiny fraction of my
search time than I am willing to be surprised by behavior that I have no way
of anticipating. And spending the developer/customer/company time chasing
such a problem down. So the notion of a library forcing me to optimize where
*the library writers* think I should raises a red flag right away.
Of course it's a balancing act. I'd also not like the library to get so
concerned with being idiot-proof that it gets noticeably slower. Given all
the time and energy that I expect Lucene to save me, I'm content to let the
Lucene folks make that determination. They are in a far better place to
judge whether this would be worth it or not.
So, I'll put in the bug report and be happy with whatever decision is made
by the Lucene folks.
As you can probably tell, I've spent faaaarrrr too much of my professional
life looking at code that was efficient, complicated, and wrong in some
subtle or not-so-subtle way and caused failures of one sort or another. And
improved execution time by, say, .0001%. I don't accept the efficiency
argument unless it can be shown to matter. The eXtreme Programming folks
have it right, "Make it work, make it right, make it fast". I'd change it a
bit to "make it fast if it matters". Those times it has mattered, my guesses
as to where the time was being wasted have been wrong most of the time.
Ok, now you know where one of my buttons is. I'll get off my soap-box now...
Erick
P.S. I'll be glad to exchange a few e-mail with you if you want to try to
persuade me. We probably shouldn't turn this into a philosophical debate
over optimization, since it *is* a Lucene forum.......
Re: Exception in WildCardQuery
Posted by Erick Erickson <er...@gmail.com>.
OK, I get it now. Obviously I didn't read your response as you meant it and
was focusing on the optimization part.
I'd also agree that using the most specific tool for the task is better
design. There's also an argument that "I'd rather have a library fail than
do something non-obvious". I'll leave it to Erik whether this would be an
'obvious' behavior <G>...
Thanks for clarifying.
Best
Erick
Re: Exception in WildCardQuery
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
I don't mean literally that WildcardQuery would morph into a
TermQuery, but rather "behave" like it by simply doing what it
currently does but without the string index exception that currently
is thrown. It wouldn't take any additional clockticks, per se, I
don't think - it'd just behave as most would expect.
Erik
On Apr 8, 2006, at 11:57 AM, karl wettin wrote:
>
> 8 apr 2006 kl. 13.06 skrev 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
>
> Even though very few, it is a waste of clockticks. I belive that
> any lib always should try to force the developer to write optimized
> code. If you for some reason need to autotedetect wildcard/term
> query, the developer should write a facade.
>
> Another error message could be good though.
>
> ---------------------------------------------------------------------
> 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
Re: Exception in WildCardQuery
Posted by karl wettin <ka...@snigel.net>.
8 apr 2006 kl. 13.06 skrev 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
Even though very few, it is a waste of clockticks. I belive that any
lib always should try to force the developer to write optimized code.
If you for some reason need to autotedetect wildcard/term query, the
developer should write a facade.
Another error message could be good though.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Exception in WildCardQuery
Posted by Erick Erickson <er...@gmail.com>.
It took me a couple of days, but this is added to JIRA
Erick
Re: Exception in WildCardQuery
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
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.
Erik
On Apr 7, 2006, at 10:28 AM, Erick Erickson wrote:
> So I'm trying to do silly stuff, just to poke a bit at wildcard
> queries. So
> sue me... But I ran across this....
>
> And yes, I know that creating a wildcard query is dangerous and
> downright
> silly when you don't have a wildcard in the term, but this still
> seems like
> a case should, say, default to a simple query rather than throw an
> exception....
>
> Lucene 1.9.1
>
> 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)
>
>
>
> FWIW
> Erick
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org