Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 137CE200BB7 for ; Wed, 9 Nov 2016 23:26:41 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 11FF5160AFA; Wed, 9 Nov 2016 22:26:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 31448160AEB for ; Wed, 9 Nov 2016 23:26:40 +0100 (CET) Received: (qmail 35251 invoked by uid 500); 9 Nov 2016 22:26:39 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 35235 invoked by uid 99); 9 Nov 2016 22:26:38 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Nov 2016 22:26:38 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 36C6BC65F7 for ; Wed, 9 Nov 2016 22:26:38 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.679 X-Spam-Level: * X-Spam-Status: No, score=1.679 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id iuCoaTeoA8Ym for ; Wed, 9 Nov 2016 22:26:36 +0000 (UTC) Received: from mail-lf0-f46.google.com (mail-lf0-f46.google.com [209.85.215.46]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id A0BD45FC5F for ; Wed, 9 Nov 2016 22:26:30 +0000 (UTC) Received: by mail-lf0-f46.google.com with SMTP id t196so176146025lff.3 for ; Wed, 09 Nov 2016 14:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=N2ezhHZvlspNgYvthf8Lm0PryHdlNTj+P87AwJM2Xcw=; b=Q4jNhmX6j1aHPsb9bdy1AcMKR33KRX9E7kcV7GqTpVzYNW/IsKxFQFvb7J2C4LEGp2 q6Mu518ea4KwzqLgSuoeiGERrjq4IY/5i6vWW3JYZiY4QMyErVfBRdybniSDWqGuuOB5 0n3aD9KMrS2SLnR9TG9KV93XeqNTDLue2bRx0+CbvACHvNiroAbcQ04fxFmaPWFVhVrt hI4fbNjP3fu84TQhZRz1m0qJRIEtTLoLain9FW9esBc1OMmzGGhIDITn9bsfewDRLckF 3zHDSDX1FwImLmxh2K2/cuIm87trc5YuRh6nEgKAjj1rD2cmE7d755r2WIjepGn4CIbC oMAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=N2ezhHZvlspNgYvthf8Lm0PryHdlNTj+P87AwJM2Xcw=; b=By0pqtKjxJWDSEWrO2jj0NugZ0DZq6asScaPa1zqCeujR+fM4XkzD4BSg+qyORmx9D dxBdB7qgULEckF2+v0PLdCvSFLRgWEJ44dElyKP5+snByXUemgZkIYj/LlPNnsQxN0Nt RswFQDI2yrHQXrhRh8+RONup4nxDXWnm5sz6Y/3ADXCdK4vM8tXxSm175ifZ8ZEzSK8A At7ONbO0M/nP9owOc1je4pHzglAKAWq1tPSomYW23+I3s3M1B0ZFRTyDQuMZdiVwb+R1 Cec1TVlNGKjl/oIsQKQ2pai7109k5/5S3X+PDltJm2gqt4ufendHm2pt1FBhvXSCosLB Md6A== X-Gm-Message-State: ABUngvdOKe1OxIsDQ5zgg5bX9reDfelg0Xeq62EGdvEv0NAkfodSEJqKLwxhoIs/BDwNQwp1nOwNe6Qm7JRedA== X-Received: by 10.25.37.134 with SMTP id l128mr804208lfl.120.1478730389136; Wed, 09 Nov 2016 14:26:29 -0800 (PST) MIME-Version: 1.0 Sender: ppp.pawelrog@gmail.com Received: by 10.114.57.243 with HTTP; Wed, 9 Nov 2016 14:26:28 -0800 (PST) In-Reply-To: References: From: Pawel Rog Date: Wed, 9 Nov 2016 23:26:28 +0100 X-Google-Sender-Auth: zJHGRpUee_dGQ_PMGfAhDkjNT1E Message-ID: Subject: Re: Query parser and default operator To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=001a11401dc6902c4a0540e5bf55 archived-at: Wed, 09 Nov 2016 22:26:41 -0000 --001a11401dc6902c4a0540e5bf55 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Dawid, Thanks for your email. It seems StandardQueryParser is free from this unexpected behavior. I used the code below with Lucene 6.2.1 (org.apache.lucene.queryparser.classic.QueryParser) QueryParser parser =3D new QueryParser("test", new WhitespaceAnalyzer()= ); parser.setDefaultOperator(QueryParser.Operator.AND); Query query =3D parser.parse("foo AND bar OR baz "); System.out.println(query.toString()); parser.setDefaultOperator(QueryParser.Operator.OR); query =3D parser.parse("foo AND bar OR baz "); System.out.println(query.toString()); I can also reproduce it on Elasticsearch 2.2 which uses Lucene 5.4.0 $ curl -s 'localhost:9200/test/_search?pretty' -d '{ "query": { "query_string": { "query": "foo AND bar OR baz" , "default_operator": "and" } } , "profile" : true}' | grep luce "lucene" : "+_all:foo _all:bar _all:baz", ... $ curl -s 'localhost:9200/test/_search?pretty' -d '{ "query": { "query_string": { "query": "foo AND bar OR baz" , "default_operator": "or" } } , "profile" : true}' | grep luce "lucene" : "+_all:foo +_all:bar _all:baz", ... Elasticsearch uses class called MapperQueryParser which extends org.apache.lucene.queryparser.classic.QueryParser -- Pawe=C5=82 R=C3=B3g On Wed, Nov 9, 2016 at 6:10 PM, Dawid Weiss wrote: > Which Lucene version and which query parser is this? Can you provide a > test case/ code sample? > I just tried with StandardQueryParser and for: > > sqp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); > dump(sqp.parse("foo AND bar OR baz", "field_a")); > sqp.setDefaultOperator(StandardQueryConfigHandler.Operator.OR); > dump(sqp.parse("foo AND bar OR baz", "field_a")); > > I get the same result: > > BooleanQuery: +field_a:foo +field_a:bar field_a:baz > > Dawid > > On Wed, Nov 9, 2016 at 6:04 PM, Pawel Rog wrote: > > Hi Eric, > > Thank you for your email. > > I understand that Lucene queries are not in boolean logic. My point is > only > > that I would expect identical Lucene queries build from the same input > > string. My intuition says that default operator should not matter in 2 > > examples I presented in previous email. > > > > -- > > Pawe=C5=82 R=C3=B3g > > > > On Wed, Nov 9, 2016 at 4:32 PM, Erick Erickson > > wrote: > > > >> Lucene queries aren't boolean logic. You can simulate boolean logic by > >> explicitly parenthesizing, here's an excellent blog on this: > >> > >> https://lucidworks.com/blog/why-not-and-or-and-not/ > >> > >> Best, > >> Erick > >> > >> On Wed, Nov 9, 2016 at 1:37 AM, Pawel Rog > wrote: > >> > Hello , > >> > I have a query `foo AND bar OR baz`. When I use "AND" as a default > >> operator > >> > this is the resulting Lucene query: > >> > > >> > `+test:foo test:bar test:baz` > >> > > >> > When I use "OR" this is the resulting query > >> > > >> > `+test:foo +test:bar test:baz` > >> > > >> > > >> > I expected these two return exactly the same Lucene query because I > used > >> > operator explicitly. I thought that the default operator is used onl= y > >> when > >> > operator is not explicitly mentioned in the query. Am I missing > something > >> > or this is not expected behavior (bug)? > >> > > >> > -- > >> > Pawe=C5=82 R=C3=B3g > >> > >> --------------------------------------------------------------------- > >> 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 > > --001a11401dc6902c4a0540e5bf55--