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 Stefan Schütz <sc...@neoconcept.de> on 2006/12/13 19:01:52 UTC
Problems with Queries which contain '_' and wildcards
Hi,
first let me explain the situation:
We have to index an document, which contains a field "file" to store
filenames.
Sometimes filenames contain an underscore or an minus (_ or -). =>
e.g. foo_bar.doc
Indexing is'nt the problem so far.
But if we now try to search for "foo_b*" the QueryParser crashes with
following exception:
org.apache.lucene.queryParser.ParseException: Cannot build
PrefixQuery with analyzer class
org.apache.lucene.analysis.de.GermanAnalyzer - token was consumed
Same problem occurs if i use the StandardAnalyzer.
To replace underscores in filenames is not a solution because we have
many other fields
which can contain underscores. :(
Is there anybody who knows this problem or knows a solution for this?
thx in advance.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Problems with Queries which contain '_' and wildcards
Posted by Ronnie Kolehmainen <ro...@ub.uu.se>.
I recognize that error message ;) You're using AnalyzingQueryParser
<http://lucene.apache.org/java/docs/api/org/apache/lucene/queryParser/analyzing/AnalyzingQueryParser.html> -
yes?
These are imo the two most obvious options:
1. Revert to standard QueryParser - it won't analyze prefix- and
wildcardqueries.
2. Keep AnalyzingQueryParser together with different analyzers for
different fields (wrapped in
org.apache.lucene.analysis.PerFieldAnalyzerWrapper).
With option #2 you could use Standard- or GermanAnalyzer for text
fields, and for filenames etc. a better choice would be something like
KeywordAnalyzer, which doesn't add or consume tokens. Remember to
always use the same analyzer(s) for indexing AND search though.
/Ronnie
Quoting Stefan Schütz <sc...@neoconcept.de>:
> Hi,
>
> first let me explain the situation:
>
> We have to index an document, which contains a field "file" to store
> filenames.
> Sometimes filenames contain an underscore or an minus (_ or -). => e.g.
> foo_bar.doc
> Indexing is'nt the problem so far.
>
> But if we now try to search for "foo_b*" the QueryParser crashes with
> following exception:
>
> org.apache.lucene.queryParser.ParseException: Cannot build PrefixQuery
> with analyzer class org.apache.lucene.analysis.de.GermanAnalyzer -
> token was consumed
>
>
> Same problem occurs if i use the StandardAnalyzer.
> To replace underscores in filenames is not a solution because we have
> many other fields
> which can contain underscores. :(
>
> Is there anybody who knows this problem or knows a solution for this?
>
> thx in advance.
> Stefan
>
> ---------------------------------------------------------------------
> 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