lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Willnauer <simon.willna...@googlemail.com>
Subject Re: KeywordAnalyzer
Date Wed, 01 Jul 2009 18:18:20 GMT
Hi there,

On Wed, Jul 1, 2009 at 7:52 PM, John Seer<pulsphoto@yahoo.com> wrote:
>
> Hi,
>
> I have docs in my index like:
>
> name: open & close
> name water fall\
> name: play-end-go
>
> I am using KeywordAnalyzer to index docs and for querying
>
> term: play-end-go
>
> Query qp= new QueryParser("name", new KeywordAnalyzer()).parse(term);
>
> After I am doing this I am getting error about - and if my term contains &
> or \ no results
This is due to the lucene query syntax and its special chars (+ - &&
|| ! ( ) { } [ ] ^ " ~ * ? : \)
see http://lucene.apache.org/java/2_4_1/queryparsersyntax.html
>
> I tried to use QueryParser.escape(); before passing into parser. I am not
> getting error during quering but not result is found
There must be some problem somewhere else If you escape you
querystring "copy-n-paste" and you have KeywordAnalyzer for search and
indexing there should be a result.
try this:

RAMDirectory r = new RAMDirectory();
IndexWriter w = new IndexWriter(r, new KeywordAnalyzer(), true,
MaxFieldLength.UNLIMITED);
Document d = new Document();
d.add(new Field("f", "copy-n-paste", Store.NO,  Index.ANALYZED));
w.addDocument(d );
w.commit();
KeywordAnalyzer ana = new KeywordAnalyzer();
QueryParser p = new QueryParser("f", ana);
IndexSearcher s = new IndexSearcher(r, true);
TopDocs search = s.search(p.parse(QueryParser.escape("copy-n-paste")),10);
System.out.println(search.totalHits);

simon
>
>
>
>
>
>
> Simon Willnauer wrote:
>>
>> On Wed, Jul 1, 2009 at 7:27 PM, John Seer<pulsphoto@yahoo.com> wrote:
>>>
>>> Hello,
>>> I am using KeywordAnalyzer for one of the fields and have problem with
>>> it.
>>> When my original term has not English characters as well as - &  \  /.
>> What are you problems? Can you elaborate this a little :)
>>> Is there any alternative for this. Or how to solve the issue with
>>> characters?
>> see above.
>>
>>
>> simon
>>>
>>>
>>> Thanks
>>> --
>>> View this message in context:
>>> http://www.nabble.com/KeywordAnalyzer-tp24293913p24293913.html
>>> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/KeywordAnalyzer-tp24293913p24294301.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message