Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7D346F6E1 for ; Thu, 4 Apr 2013 06:38:24 +0000 (UTC) Received: (qmail 14919 invoked by uid 500); 4 Apr 2013 06:38:22 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 14742 invoked by uid 500); 4 Apr 2013 06:38:22 -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 14733 invoked by uid 99); 4 Apr 2013 06:38:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Apr 2013 06:38:22 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lewis.mcgibbney@gmail.com designates 209.85.215.49 as permitted sender) Received: from [209.85.215.49] (HELO mail-la0-f49.google.com) (209.85.215.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Apr 2013 06:38:17 +0000 Received: by mail-la0-f49.google.com with SMTP id fs13so2139360lab.8 for ; Wed, 03 Apr 2013 23:37:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=pw6K4SjeKKjYP/YImjmZ2Nv38jUB1n3t4Et2+TMbcAU=; b=zyrKL2irC7UOM4zxk51MPE8fiYeGf/X7/58RklKxt5cO0zJ3axWT8xvDW47/laxJNw dndpM/pVA9YM7I2/H3qpkukVuDo9Hyur2yoZofw8BZrPxXh97Lq9lANd4pjUwZ6fNI6g 8vXfPze2/SGpkrzWjS92Wl4+CNKGxHvXhXkjZ2AJXEFNASm1AAZHvEbGFJ82dCVl2juY GAB6sXhYyahZj7Th90vl+q1EZjpzrv8qYZBwpINdwQK8rEnIYd5hv7H5zZ9fPutFRN+m RyVjJZoRXm5BXwJCr5lsvBcfGWePIbigTURUOn63XBqWWyMaKy6f1ae2SEpOwjsxO6oJ R1JA== MIME-Version: 1.0 X-Received: by 10.112.104.103 with SMTP id gd7mr2627650lbb.54.1365057476392; Wed, 03 Apr 2013 23:37:56 -0700 (PDT) Received: by 10.112.2.161 with HTTP; Wed, 3 Apr 2013 23:37:56 -0700 (PDT) In-Reply-To: <02e701ce30fe$812a1bd0$837e5370$@thetaphi.de> References: <02e701ce30fe$812a1bd0$837e5370$@thetaphi.de> Date: Wed, 3 Apr 2013 23:37:56 -0700 Message-ID: Subject: Re: Upgrading Lucene 2.0.0 TermQuery to 4.2 QueryParser From: Lewis John Mcgibbney To: "java-user@lucene.apache.org" Content-Type: multipart/alternative; boundary=14dae9d68298fa84db04d983357f X-Virus-Checked: Checked by ClamAV on apache.org --14dae9d68298fa84db04d983357f Content-Type: text/plain; charset=ISO-8859-1 Hi Uwe, This is dynamite and makes much more sense now when Iook back at the numerous occasions where I've been upgrading this. Plenty of work tomorrow! Your feedback is great, thank you Lewis On Wednesday, April 3, 2013, Uwe Schindler wrote: > Hi, > > You can use TermQuery and BooleanQuery in Lucene 4.x in exactly the same way like in 2.0. No need to use QueryParser (and it's not a good idea to use QP for non-analyzed fields like product IDs). TermQuery is the way to go. > > ----- > Uwe Schindler > H.-H.-Meier-Allee 63, D-28213 Bremen > http://www.thetaphi.de > eMail: uwe@thetaphi.de > > >> -----Original Message----- >> From: Lewis John Mcgibbney [mailto:lewis.mcgibbney@gmail.com] >> Sent: Thursday, April 04, 2013 3:39 AM >> To: java-user@lucene.apache.org >> Subject: Upgrading Lucene 2.0.0 TermQuery to 4.2 QueryParser >> >> Hi, >> I'm currently embarking upon a non trivial upgrade of some legacy 2.0.0 code >> and encounter the following >> >> IndexSearcher searcher = null; >> try { >> searcher = new IndexSearcher(indexFilePath); >> Term productIdTerm = new Term("product_id", productId); >> org.apache.lucene.search.Query query = new >> TermQuery(productIdTerm); >> Hits hits = searcher.search(query); >> >> // should be exactly 1 hit >> if (hits.length() == 0) { >> throw new CatalogException("Product: [" + productId + "] NOT found >> in the catalog!"); >> } else if (hits.length() > 1) { >> throw new CatalogException("Product: [" + productId+ "] is not >> unique in the catalog!"); >> } >> >> Document productDoc = hits.doc(0); >> >> So far I've got here >> >> try { >> DirectoryReader reader = DirectoryReader.open(indexFilePath); >> IndexSearcher searcher = new IndexSearcher(reader); >> org.apache.lucene.search.Query query = new QueryParser >> (Version.LUCENE_42, productId, new >> StandardAnalyzer(Version.LUCENE_42)).parse(productIdTerm.toString()); >> TopDocs topd = searcher.search(query, 10); >> ScoreDoc[] docs = topd.scoreDocs; >> // should be exactly 1 hit >> if (topd.totalHits == 0) { >> throw new CatalogException("Product: [" + productId + "] NOT found >> in the catalog!"); >> } else if (topd.totalHits > 1) { >> throw new CatalogException("Product: [" + productId+ "] is not >> unique in the catalog!"); >> } >> Document productDoc = searcher.doc(docs[0].doc); >> >> So I hope this is fine. Please someone call me out where I am going wrong >> here. >> >> The issue I have is what if I wish to to a BooleanQuery like >> >> try { >> searcher = new IndexSearcher(indexFilePath); >> >> // construct a Boolean query here >> BooleanQuery booleanQuery = new BooleanQuery(); >> TermQuery tq = new TermQuery(new Term("myfield", "myvalue")); >> booleanQuery.add(tq, BooleanClause.Occur.MUST); >> >> Sort sort = new Sort(new SortField("CAS.ProductReceivedTime", >> SortField.STRING, true)); >> >> How do I represent this in the new 4.x syntax? >> >> Thank you for taking the time to read through this code. I will not be >> surprised if it is not correct. >> Thank you >> Lewis >> >> -- >> *Lewis* > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > > -- *Lewis* --14dae9d68298fa84db04d983357f--