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 Maksym Krasovskiy <ma...@ciklum.com> on 2013/08/16 16:55:50 UTC
Wrong documents in results
Hi!
I have documents with two fields id and name. I create index with code:
Document doc = new Document();
doc.add(new TextField("id", id), Store.YES));
doc.add(new TextField("name", QueryParser.escape(name), Store.YES));
indexWriter.addDocument(doc);
When I try to search with query with code:
QueryParser qp = new QueryParser(LUCENE_VERSION, "name", new WhitespaceAnalyzer(LUCENE_VERSION));
getIndexSearcher().search(qp.parse(“id:( 134586 or 134583 )”), 10);
I got only 2 results as expected
But when I try to search with query:
(name:test) and id:( 134586 or 134583 )
I got many results, but I expect only documents with id = 134586 or 134583 which have test in name field. Why lucene add to search results additional documents which not match search criteria?
--
Krasovskiy Maxim
Re: Wrong documents in results
Posted by Ian Lea <ia...@gmail.com>.
and != AND? http://lucene.apache.org/core/4_4_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#AND
It works for or rather than OR because that is the default. If you
had a doc with id="or" you'd find that too, I think.
It looks odd to be escaping the value when you are storing it. That
may not be necessary, but if it's what you want, fine.
--
Ian.
On Fri, Aug 16, 2013 at 3:55 PM, Maksym Krasovskiy <ma...@ciklum.com> wrote:
> Hi!
> I have documents with two fields id and name. I create index with code:
> Document doc = new Document();
> doc.add(new TextField("id", id), Store.YES));
> doc.add(new TextField("name", QueryParser.escape(name), Store.YES));
> indexWriter.addDocument(doc);
>
> When I try to search with query with code:
> QueryParser qp = new QueryParser(LUCENE_VERSION, "name", new WhitespaceAnalyzer(LUCENE_VERSION));
> getIndexSearcher().search(qp.parse(“id:( 134586 or 134583 )”), 10);
> I got only 2 results as expected
>
> But when I try to search with query:
> (name:test) and id:( 134586 or 134583 )
> I got many results, but I expect only documents with id = 134586 or 134583 which have test in name field. Why lucene add to search results additional documents which not match search criteria?
>
>
> --
> Krasovskiy Maxim
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org