Searching with "1"
16 answers - 378 bytes -

I am managing a few Lucene searches in the application that I am building.
We have noticed that when a user searches with the string "1", this will
throw an exception. The search works fine until Lucene tries to build its
Hits. Is there any reason why this would be true? Also, what is a common
solution to this issue, so my users can search with "1"?
Thanks.
No.1 | | 1863 bytes |
| 
Well I am not authorized to give you the entire trace, but here is the
iimportant part
(BooleanQuery.java:79)
(BooleanQuery.java:71)
(PrefixQuery.java:50)
(IndexSearcher.java:166)
(Query.java:84)
(IndexSearcher.java:85)
(Hits.java:64)
org.apache.lucene.search.Hits.<init>(Hits.java:43)
(Searcher.java:33)
(Searcher.java:27)
Also, I forgot to mention, but the error is throwing a message implying it
cannot search on null.
Hope that helps. Thank you for the speedy responce.
Doron Cohen wrote:
What is the exception stack trace?
djd0383 <ddigmann (AT) formos (DOT) comwrote on 22/09/2006 16:07:53:
>>
>I am managing a few Lucene searches in the application that I am
building.
>We have noticed that when a user searches with the string "1", this will
>throw an exception. The search works fine until Lucene tries to build
its
>Hits. Is there any reason why this would be true? Also, what is a
common
>solution to this issue, so my users can search with "1"?
>>
>Thanks.
>--
>View this message in context: %
>221%22-tf2320552.html#a6456507
>Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>>
>>
>
>To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
>For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
>>
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.2 | | 487 bytes |
| 
9/22/06, djd0383 <ddigmann (AT) formos (DOT) comwrote:
Also, I forgot to mention, but the error is throwing a message implying it
cannot search on null.
The analyzer you are using is throwing away the "1" leaving nothing
left to search on.
-Yonik
Solr, the open-source Lucene search server
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.3 | | 652 bytes |
| 
And why would Lucene be doing that now? That just doesn't seem to be the
right thing to do.
Yonik Seeley wrote:
9/22/06, djd0383 <ddigmann (AT) formos (DOT) comwrote:
>Also, I forgot to mention, but the error is throwing a message implying
>it
>cannot search on null.
The analyzer you are using is throwing away the "1" leaving nothing
left to search on.
-Yonik
Solr, the open-source Lucene search
server
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.4 | | 911 bytes |
| 
9/22/06, djd0383 <ddigmann (AT) formos (DOT) comwrote:
And why would Lucene be doing that now? That just doesn't seem to be the
right thing to do.
It's often not the right thing to do, but it's all under your control.
It depends on exactly what your analyzer looks like (what tokenizers
and tokenfilters you are using).
-Yonik
Solr, the open-source Lucene search server
9/22/06, djd0383 <ddigmann (AT) formos (DOT) comwrote:
>Also, I forgot to mention, but the error is throwing a message implying
>it
>cannot search on null.
>
The analyzer you are using is throwing away the "1" leaving nothing
left to search on.
-Yonik
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.5 | | 914 bytes |
| 
: Well I am not authorized to give you the entire trace, but here is the
: iimportant part
:
: (BooleanQuery.java:79)
: (BooleanQuery.java:71)
: (PrefixQuery.java:50)
: (IndexSearcher.java:166)
1) where is the top of the stack trace showing the Exception class and the
exception message? those are just as important.
2) you need to clarify what you mean by 'Searching with "1"' that
stack trace indicates that your query is really a PrefixQuery (not a
simple TermQuery on "1") what is the query.toString() ? how did you
build it (ie: did you use QueryParser?)
3) can you clarify what version of Lucene you are using those line
numbers don't jive with the trunk.
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.6 | | 1454 bytes |
| 
The top of the stack was the stack I posted. I am not able to give the
entire stack, but this is the important part. The exception is something
about searching with null.
When I say that I am searching for '1', the user is phyisically entering '1'
into the search form and submitting. This search works just fine for, say,
2 or 12. Lucene has a class named Hits. The serach string which is passed
to this class is '1*'.
The version we are using is 1.4.3.
Chris Hostetter wrote:
: Well I am not authorized to give you the entire trace, but here is the
: iimportant part
:
: (BooleanQuery.java:79)
: (BooleanQuery.java:71)
: (PrefixQuery.java:50)
: (IndexSearcher.java:166)
1) where is the top of the stack trace showing the Exception class and the
exception message? those are just as important.
2) you need to clarify what you mean by 'Searching with "1"' that
stack trace indicates that your query is really a PrefixQuery (not a
simple TermQuery on "1") what is the query.toString() ? how did you
build it (ie: did you use QueryParser?)
3) can you clarify what version of Lucene you are using those line
numbers don't jive with the trunk.
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.7 | | 1283 bytes |
| 
My QueryParser looks like this:
query = QueryParser.parse("1*","allText",analyzer);
analyzer is predetermited for this class. Is there something special I
should be setting in this to allow for this search string?
Thanks again!
Doron Cohen wrote:
djd0383 <ddigmann (AT) formos (DOT) comwrote on 22/09/2006 17:01:47:
>>
>And why would Lucene be doing that now? That just doesn't seem to be the
>right thing to do.
>>
This would depend on the analyzer being used.
It puzzles me that you say the user query is "1" but the query that throws
the exception is PrefixQuery.
Do you create the Prefix query programmatically, or do you use
QueryParser?
QueryParser would create a prefix query for "1*" but not for "1".
If you list a short snippet of code that you use for the search this would
help, e.g. something like:
String qtxt = "1";
QueryParser qp = new QueryParser("fieldName", new StandardAnalyzer());
Query q = qp.parse(qtxt);
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.8 | | 1101 bytes |
| 
Those two message print the following:
For qtxt 1* the result query is allText:1*
and
The analyzer in use is:
-
I hope this helps. Thank you for all your help.
Doron Cohen wrote:
>My QueryParser looks like this:
>query = QueryParser.parse("1*","allText",analyzer);
>>
>analyzer is predetermited for this class. Is there something special I
>should be setting in this to allow for this search string?
Is it a custom analyzer or one of Lucene's analyzers?
Examining the result query will tell if the used analyzer is causing you
trouble: what would be printed by adding the following lines just after
you
create the query?
System.out.println("For qtxt 1* the result query is" + query);
System.out.println("The analyzer in use is:
"+analyzer.getClass().getName() + " - " + analyzer);
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.9 | | 1872 bytes |
| 
What are the Store and Index classes? It does not seem that my version of
Lucene is using them
Doron Cohen wrote:
djd0383 <ddigmann (AT) formos (DOT) comwrote on 25/09/2006 11:21:13:
>Those two message print the following:
>For qtxt 1* the result query is allText:1* and
>The analyzer in use is:
>
This output seems ok - the analyzer is standard and seems to me the result
query should be working. Are you able to modify this small stand-alone
program to create the exception you are seeing?
public static void main(String[] args) throws Exception {
// populate index with 2 docs
RAMDirectory dir = new RAMDirectory();
Analyzer anlzr = new StandardAnalyzer();
IndexWriter iw = new IndexWriter(dir,anlzr,true);
String fldName = "allText";
Document d1 = new Document();
d1.add(new Field(fldName,"This doc has no ones in
it.",Store.N,Index.TKENIZED));
iw.addDocument(d1);
Document d2 = new Document();
d2.add(new Field(fldName,"This doc has:
123.",Store.N,Index.TKENIZED));
iw.addDocument(d2);
iw.close();
String qtxt = "1*";
QueryParser qp = new QueryParser(fldName, anlzr);
Query query = qp.parse(qtxt);
System.out.println("For qtxt "+qtxt+" the result query is: " + query);
System.out.println("Analyzer: "+anlzr);
IndexSearcher searcher = new IndexSearcher(dir);
Hits hits = searcher.search(query);
if (hits==null || hits.length()==0) {
System.out.println(" N results.");
} else {
System.out.println(" RESULTS:");
for (int i = 0; i < hits.length(); i++) {
System.out.println(" "+hits.id(i)+" - "+hits.score(i));
}
}
}
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.10 | | 1676 bytes |
| 
: The top of the stack was the stack I posted. I am not able to give the
: entire stack, but this is the important part. The exception is something
: about searching with null.
when i say "the top of the stack trace" i mean what you just described:
"something about searching with null" what exactly does it say about
searching with null? What is the class of the exception?
This is an example of the "top" of a stack trace
Error parsing Lucene query
at (QueryParsing.java:87)
at ()
at (SolrCore.java:586)
equally important is if the stack trace contains any lines starting
with someling like "Caused by:" which would be much "lower" in the stack,
possibly after your own custom classes, but they show the root of the
problem. the example Solr exception i posted above is fairly useless for
understanding the root cause of the problem unless you look at the full
stack trace and see much farther down a "Caused by" line explaining what
really went wrong
Error parsing Lucene query
at (QueryParsing.java:87)
at ()
at (SolrCore.java:586)
at (SolrServlet.java:91)
at (HttpServlet.java:596)
Caused by: Cannot parse 'id:*1*': Lexical error at line 1, column 4. Encountered: "*" (42), after : ""
at (QueryParser.java:129)
at (QueryParsing.java:77)
these are just a few example why only posting "part" of a stack trace
isn't allways enough to help diagnose your problem.
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.11 | | 2626 bytes |
| 
A bit of progress on this post
First off, I got the go ahead from the higher ups to install and configure
v2.0. I have that installed, configured, indexed, and tested. That is the
good news.
We were hoping this would just fix this problem, but it didn't.
>Are you able to modify this small stand-alone
>program to create the exception you are seeing?
I did run your small script (minorly modified for try/catch). And here is
the output:
For qtxt 1* the result query is: allText:1*
Analyzer: @90cb03
RESULTS:
1 - 0.5
Alright now I am confused. Why would this work but our classes - which are
practically the same - not work? The only difference in your version and
mine is that you switch the IndexReader with RAMDirectory.
Any thoughts?
Doron Cohen wrote:
djd0383 <ddigmann (AT) formos (DOT) comwrote on 25/09/2006 11:21:13:
>Those two message print the following:
>For qtxt 1* the result query is allText:1* and
>The analyzer in use is:
>
This output seems ok - the analyzer is standard and seems to me the result
query should be working. Are you able to modify this small stand-alone
program to create the exception you are seeing?
public static void main(String[] args) throws Exception {
// populate index with 2 docs
RAMDirectory dir = new RAMDirectory();
Analyzer anlzr = new StandardAnalyzer();
IndexWriter iw = new IndexWriter(dir,anlzr,true);
String fldName = "allText";
Document d1 = new Document();
d1.add(new Field(fldName,"This doc has no ones in
it.",Store.N,Index.TKENIZED));
iw.addDocument(d1);
Document d2 = new Document();
d2.add(new Field(fldName,"This doc has:
123.",Store.N,Index.TKENIZED));
iw.addDocument(d2);
iw.close();
String qtxt = "1*";
QueryParser qp = new QueryParser(fldName, anlzr);
Query query = qp.parse(qtxt);
System.out.println("For qtxt "+qtxt+" the result query is: " + query);
System.out.println("Analyzer: "+anlzr);
IndexSearcher searcher = new IndexSearcher(dir);
Hits hits = searcher.search(query);
if (hits==null || hits.length()==0) {
System.out.println(" N results.");
} else {
System.out.println(" RESULTS:");
for (int i = 0; i < hits.length(); i++) {
System.out.println(" "+hits.id(i)+" - "+hits.score(i));
}
}
}
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.12 | | 695 bytes |
| 
: Alright now I am confused. Why would this work but our classes - which are
: practically the same - not work? The only difference in your version and
: mine is that you switch the IndexReader with RAMDirectory.
:
: Any thoughts?
My Guess: one of your assumptions is wrong. and there really seems to
only be one assumption you are making is that your code and this small
test case do the same thing.
Add more logging to your code, see exactly what is going on in *your*
code.
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.13 | | 1126 bytes |
| 
Fixed the issue
It turns out that I was going over TooManyClauses, and this decided to give
an exception.
I am not really sure of the reasoning behind this exception? It seems to us
that it might be better to throw an exception. This way the programmer can
handle this accordingly and will force them to do so.
Thank you for all your help guys. I really appreciate it!
Chris Hostetter wrote:
: Alright now I am confused. Why would this work but our classes - which
are
: practically the same - not work? The only difference in your version
and
: mine is that you switch the IndexReader with RAMDirectory.
:
: Any thoughts?
My Guess: one of your assumptions is wrong. and there really seems to
only be one assumption you are making is that your code and this small
test case do the same thing.
Add more logging to your code, see exactly what is going on in *your*
code.
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.14 | | 968 bytes |
| 
: It turns out that I was going over TooManyClauses, and this decided to give
: an exception.
:
: I am not really sure of the reasoning behind this exception? It seems to us
: that it might be better to throw an exception. This way the programmer can
: handle this accordingly and will force them to do so.
I'm not understanding your statement. TooManyClauses is a runtime
exception that can and will be thrown when a query like PrefixQuery is
rewriten to a BooleanQuery -- which happens when a search is executed.
so if your problem is that your prefix query was generating too many
clauses -- that exception should have in fact been throws what do you
mean by "this decided to give an exception." if the exception wasn't
thrown?
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.15 | | 1938 bytes |
| 
After thinking through what was happening in Hits, I decided to see if
catching a general exception would come back with anything. Although it can
be argued that the code should have been doing this all along, that is a
different story.
So, I added Exception to the catch clauses, and it in fact catch the
TooManyClauses which allowed me to solve to problem. My point though is
that if the code was to throw this exception and require me to catch it,
this problem would have fixed for me and potentially others as they are
writting the code. As an Eclipse user, it is nice when I create a try/catch
that it puts in all the required catches from the code within the try. If
you were to physically throw this exception, my try would have built the
catch when we created it, or at least errored that we needed it. I was just
curious why you were not throwing it?
Again thanks for your help.
Chris Hostetter wrote:
: It turns out that I was going over TooManyClauses, and this decided to
give
: an exception.
:
: I am not really sure of the reasoning behind this exception? It seems
to us
: that it might be better to throw an exception. This way the programmer
can
: handle this accordingly and will force them to do so.
I'm not understanding your statement. TooManyClauses is a runtime
exception that can and will be thrown when a query like PrefixQuery is
rewriten to a BooleanQuery -- which happens when a search is executed.
so if your problem is that your prefix query was generating too many
clauses -- that exception should have in fact been throws what do you
mean by "this decided to give an exception." if the exception wasn't
thrown?
-Hoss
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org
No.16 | | 1563 bytes |
| 
djd0383 wrote:
After thinking through what was happening in Hits, I decided to see if
catching a general exception would come back with anything. Although it can
be argued that the code should have been doing this all along, that is a
different story.
So, I added Exception to the catch clauses, and it in fact catch the
TooManyClauses which allowed me to solve to problem. My point though is
that if the code was to throw this exception and require me to catch it,
this problem would have fixed for me and potentially others as they are
writting the code. As an Eclipse user, it is nice when I create a try/catch
that it puts in all the required catches from the code within the try. If
you were to physically throw this exception, my try would have built the
catch when we created it, or at least errored that we needed it. I was just
curious why you were not throwing it?
My guess is that you are asking why TooManyClauses is not a checked
exception. I'm not really sure why the decision was made to make it
unchecked, but for a queries that will definitely not throw that
exception it reduces the amount of clutter/extra code that needs to be
written. There are, however, many debates about the merits of using
checked vs unchecked exceptions.
Hopefully this comment clarifies the question at least.
Ryan
To unsubscribe, e-mail: java-dev-unsubscribe (AT) lucene (DOT) apache.org
For additional commands, e-mail: java-dev-help (AT) lucene (DOT) apache.org