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 9CF07200BBB for ; Thu, 10 Nov 2016 13:31:38 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9B428160B01; Thu, 10 Nov 2016 12:31:38 +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 5EAE3160AF6 for ; Thu, 10 Nov 2016 13:31:37 +0100 (CET) Received: (qmail 31670 invoked by uid 500); 10 Nov 2016 12:31:36 -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 31648 invoked by uid 99); 10 Nov 2016 12:31:36 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2016 12:31:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 8EBE41A9E6F for ; Thu, 10 Nov 2016 12:31:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.18 X-Spam-Level: * X-Spam-Status: No, score=1.18 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id Z6QfihmIM4Gz for ; Thu, 10 Nov 2016 12:31:33 +0000 (UTC) Received: from mail-it0-f41.google.com (mail-it0-f41.google.com [209.85.214.41]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id D24085F23B for ; Thu, 10 Nov 2016 12:31:32 +0000 (UTC) Received: by mail-it0-f41.google.com with SMTP id e187so264088080itc.0 for ; Thu, 10 Nov 2016 04:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=9j/i00hoSphc44SFPxAVWhWs87r1Ioj0T8d5oWcatdc=; b=i6e7IFV+S5Rr+7GackwbT78cz+0JtPvTfgrX1hXkKnJ9vJTT0vc8lFEq/9COPeCbyp XKFQpOWwsyeFMk1iKph+qT7BCLX8rYtQESRL66G0hSmTupx+EcEPNVnNvwyXOGjMhul+ s7r5hV28vKoPWaQbBJq7Z2ORj0ZAksRnmqDMCdRq6vDebqcrqzZpagPxzcPJxAqRW16C 5ajof+nssegadjOK5xfqEllCHV7JqHr8CVvlp3HQk5Yst37fVrVAcTsER83DLvbo+VGu k+Oi/rBJ6JlOqaBvGgrvK2cdXf9Uy0BNrjKGcsI/oxAPayCpNmmkLuU95Jc6+Wg+PFvR Cgpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=9j/i00hoSphc44SFPxAVWhWs87r1Ioj0T8d5oWcatdc=; b=XG3JEc4a/zHKY4qMSUCdhPjKKYugxgX8nocLmCNqeLvh1jIMmkUepuZ+KT/fcVpnFe XBspfaiCLij/vMwvSgHWb05YbQp6BoojkkyPWo2dD3JpRw/gjBy8racbrd1iayJXSrX8 0oM0MC5jP5VhKun74M7besv/FrJQreZ6vBmhy5SZJS22Hkkad2gkUm0+IAdV5Fd8pUNL p3AqqB2yDSC43lKf6aCgLyY1O2AznZYhiRYatF9Vnt9glJP7FvvxWVksbmZqW8jzJ7ME oHscgyVuIMDpV0RUXaO1n0ACUyAx/vYaDjMIAYLixyAsnYIR0M1IIOapdyrfvAqjbPh+ oUtg== X-Gm-Message-State: ABUngvfgQiuVd3Zm9thN3+MOWlHcV3r5j86LjD4i2r6PolQQdcah91EgZJ6TBiNZihimrTJc+gDXzKZB1yo+7Q== X-Received: by 10.36.26.21 with SMTP id 21mr3633807iti.64.1478781078321; Thu, 10 Nov 2016 04:31:18 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.119.2 with HTTP; Thu, 10 Nov 2016 04:30:47 -0800 (PST) In-Reply-To: References: From: Dawid Weiss Date: Thu, 10 Nov 2016 13:30:47 +0100 Message-ID: Subject: Re: Query parser and default operator To: java-user@lucene.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable archived-at: Thu, 10 Nov 2016 12:31:38 -0000 This does look odd. I filed this issue to track it: https://issues.apache.org/jira/browse/LUCENE-7550 But I can't promise you I'll have the time to look into this any time soon. Feel free to step down through the source and see why the difference is there (patches welcome!). On Wed, Nov 9, 2016 at 11:26 PM, Pawel Rog wrote: > 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": "an= d" > } } , "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 b= y >> >> 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 on= ly >> >> 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 >> >> --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org