From solr-user-return-119424-apmail-lucene-solr-user-archive=lucene.apache.org@lucene.apache.org Sun Jan 3 10:52:55 2016 Return-Path: X-Original-To: apmail-lucene-solr-user-archive@minotaur.apache.org Delivered-To: apmail-lucene-solr-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CD59B18AD7 for ; Sun, 3 Jan 2016 10:52:55 +0000 (UTC) Received: (qmail 41668 invoked by uid 500); 3 Jan 2016 10:52:52 -0000 Delivered-To: apmail-lucene-solr-user-archive@lucene.apache.org Received: (qmail 41589 invoked by uid 500); 3 Jan 2016 10:52:52 -0000 Mailing-List: contact solr-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: solr-user@lucene.apache.org Delivered-To: mailing list solr-user@lucene.apache.org Received: (qmail 41577 invoked by uid 99); 3 Jan 2016 10:52:52 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Jan 2016 10:52:52 +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 D40821A0B2C for ; Sun, 3 Jan 2016 10:52:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.902 X-Spam-Level: ** X-Spam-Status: No, score=2.902 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, URIBL_BLOCKED=0.001, WEIRD_PORT=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-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id tfkeeafEKVaN for ; Sun, 3 Jan 2016 10:52:43 +0000 (UTC) Received: from mail-yk0-f175.google.com (mail-yk0-f175.google.com [209.85.160.175]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 2E35020C6A for ; Sun, 3 Jan 2016 10:52:42 +0000 (UTC) Received: by mail-yk0-f175.google.com with SMTP id x67so224025228ykd.2 for ; Sun, 03 Jan 2016 02:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=CW4FEu5vpaOcgm25SPb+pPFV3U+SXeG5LwcwzK7jnfU=; b=I3l8uZGVXiOemvfFJacXGJv5dusUhcAQlwFdXt2Xspva46dYdI20oyTxLvpbcm8nYt AEnTQOYuvphusP63K6K3B0ze04TgoujEjs7mcsL/JQs4vjOazu1lOPXAKgWkiFJ7xkzl naRHy68mtnQwlAmXNcF+TBhBJW8DY/5KkenkPZlXrYP/htnyRTXTA4P7FYMxTeieiIkM KofUReOK2qk1GSto7cj6ppYiL6PYK92RNQ9v+nynZWy7T0d62zXZYizrU0i/Rf3v7D2S jUbghkMcEEVqwKEbDsNY/f4RtbBMqTwSKUtO8O/ppiv9BPPxOQ3XhirYhzph/S5aODX9 dTRg== MIME-Version: 1.0 X-Received: by 10.129.17.66 with SMTP id 63mr52204155ywr.122.1451818355467; Sun, 03 Jan 2016 02:52:35 -0800 (PST) Received: by 10.129.145.75 with HTTP; Sun, 3 Jan 2016 02:52:35 -0800 (PST) In-Reply-To: <1451736197.77676.480927114.5B4E9A4A@webmail.messagingengine.com> References: <1451679343.4095886.480639330.30B1020E@webmail.messagingengine.com> <1451686118.4116104.480686570.3FC0E109@webmail.messagingengine.com> <1451736197.77676.480927114.5B4E9A4A@webmail.messagingengine.com> Date: Sun, 3 Jan 2016 03:52:35 -0700 Message-ID: Subject: Re: Issue with if() statement From: William Bell To: "solr-user@lucene.apache.org" Content-Type: multipart/alternative; boundary=001a11429e1e5b2eab05286bcd70 --001a11429e1e5b2eab05286bcd70 Content-Type: text/plain; charset=UTF-8 OK. I was able to get it to work by looking at {!switch} code. I had a heck of a time trying to get parse() to work as a separate class. q.add(new TermQuery(new Term("state", "CO"), Occur.MUST); return q; That never did anything. Here is some code that worked... http://localhost:8983/solr/providersearchfull/select?wt=json&state1=state:NY&fl=ss,score&df=state&q={!orquery}$state,$state1 Notice $state was not sent... It works. Thoughts? package hg.parsers; import org.apache.commons.lang.StringUtils; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.solr.common.params.CommonParams; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.BooleanClause; import org.apache.solr.parser.QueryParser; import org.apache.lucene.search.Query; import org.apache.lucene.search.spans.SpanTermQuery; import org.apache.solr.common.params.SolrParams; import org.apache.solr.search.QueryParsing; import org.apache.solr.common.util.NamedList; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.search.QParser; import org.apache.solr.search.QParserPlugin; import org.apache.solr.search.SyntaxError; /** * Created by bbell on 1/3/16. */ public class OrQueryParserPlugin extends QParserPlugin { //public static String NAME = "lucene"; @Override public void init(NamedList args) { } @Override public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { return new QParser(qstr, localParams, params, req) { QParser subParser; @Override public Query parse() throws SyntaxError { String v = localParams.get(QueryParsing.V); if (v == null || v.length() == 0) return null; String subQ = null; String[] arr = v.split(","); System.out.println("parse arr:" + arr.length + "," + v); if (arr != null && arr.length == 2) { System.out.println("parse arr[0].length:" + arr[0].length()); System.out.println("parse arr[1].length:" + arr[1].length()); if (arr[0].trim().length() > 0) { System.out.println("parse arr[0] params:" + params.get(arr[0].trim())); if (arr[0].trim().substring(0, 1).equals("$")) { String val = params.get(arr[0].trim().substring(1)); if (val != null && val.length() > 0) { subQ = val; System.out.println("parse arr[0]:" + arr[0].trim() + "," + subQ); } } else { subQ = arr[0].trim(); System.out.println("parse arr[0]:" + subQ); } } if (subQ == null && arr[1].trim().length() > 0) { System.out.println("parse arr[1] params:" + params.get(arr[1].trim())); if (arr[1].trim().substring(0, 1).equals("$")) { String val = params.get(arr[1].trim().substring(1)); if (val != null && val.length() > 0) { subQ = val; System.out.println("parse arr[1]:" + arr[1].trim() + "," + subQ); } } else { subQ = arr[1].trim(); System.out.println("parse arr[1]:" + subQ); } } } else { subQ = null; } subParser = subQuery(subQ, null); return subParser.getQuery(); } @Override public String[] getDefaultHighlightFields() { return subParser.getDefaultHighlightFields(); } @Override public Query getHighlightQuery() throws SyntaxError { return subParser.getHighlightQuery(); } @Override public void addDebugInfo(NamedList debugInfo) { subParser.addDebugInfo(debugInfo); } }; } } . On Sat, Jan 2, 2016 at 5:03 AM, Upayavira wrote: > Hrmph. I've got an Ant based codebase for building custom components > against Solr. I've been asked on numerous occasions to publish this > codebase. It is now at: > > https://github.com/upayavira/custom-solr-components > > There's no sample code in there yet. I'll see if I can stick one in > there now, but I'm not sure how much time I have today to pull it all > together (making it look nice and clear takes much more effort than > making it work!). > > Upayavira > > On Sat, Jan 2, 2016, at 02:15 AM, William Bell wrote: > > Sample code for a simple query parser? > > > > On Fri, Jan 1, 2016 at 3:08 PM, Upayavira wrote: > > > > > You've got to think of what the queries will be that you produce under > > > the bonnet - what you are talking about is either a (!func} or a > > > {!frange} query - both of which are inefficient as they must scan the > > > entire resultset. > > > > > > However, what you're trying to do is evaluate the length of the *input > > > value*, not a value in the documents being searched, so this doesn't > > > really apply - you're talking about doing some work before your query > > > happens. > > > > > > Again, I'm not sure of a way to do this on a stock Solr, but with a > > > little coding it should be achievable - you could extend the switch > > > query parser, or you could write your own - they're not that hard to > > > create. Or, you could create a search component that operates before > the > > > QueryComponent does. > > > > > > A simple queryparser of your own would seem like a pretty lightweight > > > thing - probably 20 lines of code or less. > > > > > > Upayavira > > > > > > On Fri, Jan 1, 2016, at 09:40 PM, William Bell wrote: > > > > Forgot last bit: > > > > > > > > fq={!switch case.gt.0=$state1 > > > > default=$state > > > > func=len($state1)} > > > > > > > > > > > > On Fri, Jan 1, 2016 at 2:39 PM, William Bell > > > wrote: > > > > > > > > > Maybe we can add function value on a switch? > > > > > > > > > > fq={!switch case.gt.0 > > > > > default=$state > > > > > func=len($state1)} > > > > > > > > > > > > > > > > > > > > We could add: gt, lt, eq, ge, le ? > > > > > > > > > > gt: greater than > > > > > lt: less than > > > > > eq: equal > > > > > ge: greater than or equal > > > > > le: less than or equal > > > > > > > > > > ?? > > > > > > > > > > > > > > > > > > > > On Fri, Jan 1, 2016 at 2:25 PM, William Bell > > > wrote: > > > > > > > > > >> This all started with me trying to use {!switch} to indicate with > CO > > > or > > > > >> NY to use. if we pass state1, that is supposed to take precedence, > > > but if > > > > >> nothing is returned, then use state.... Make sense now? > > > > >> > > > > >> I could not find a way to check for strlen($state1). Which is > what I > > > want > > > > >> in the case statement. This just does not work... > > > > >> Something like the following is what I am trying to do: > > > > >> > > > > >> > > > > >> fq={!switch case."anything"=$state1 > > > > >> default=$state > > > > >> v=$state1} > > > > >> > > > > >> So I tried the following to set all 50 states: > > > > >> > > > > >> > > > > >> fq={!switch case.all='*:*' > > > > >> case.CO='state:CO' > > > > >> case.NY='state:NY' > > > > >> v=$state1} > > > > >> > > > > >> > > > > >> Obviously Oregon (OR!) is an issue, and it won't work at all plus > > > > >> > > > > >> > > > > >> > > > > >> On Fri, Jan 1, 2016 at 2:15 PM, William Bell > > > > wrote: > > > > >> > > > > >>> Another weirdness: > > > > >>> > > > > >>> > > > > >>> > > > > http://localhost:8983/solr/providersearch/select?wt=json&state=state:CO&state1=state:NY&fl=*&q=*:*&tt=$state1&fq={!lucene%20v=$tt} > > > > >>> < > > > > http://localhost:8983/solr/providersearch/select?wt=json&state=state:CO&state1=state:NY&fl=*&q=*:*&tt=$state1&fq=%7B!lucene%20v=$tt%7D > > > > > > > > >>> > > > > >>> That does not return anything. > > > > >>> > > > > >>> But if I set v=$state1 I get results. > > > > >>> > > > > >>> Can I not set equivalent variables? > > > > >>> > > > > >>> > > > > >>> > > > > >>> On Fri, Jan 1, 2016 at 2:07 PM, William Bell < > billnbell@gmail.com> > > > > >>> wrote: > > > > >>> > > > > >>>> Example. > > > > >>>> > > > > >>>> > > > > >>>> > > > > http://localhost:8983/solr/providersearch/select?wt=json&state=state:%22CO%22&state1=state:%22NY%22&fl=ss,score&q=*:*&fq={!lucene%20v=$state1} > > > > >>>> < > > > > http://localhost:8983/solr/providersearch/select?wt=json&state=state:%22CO%22&state1=state:%22NY%22&fl=ss,score&q=*:*&fq=%7B!lucene%20v=$state1%7D > > > > > > > > >>>> > > > > >>>> This return 236,000 > > > > >>>> > > > > >>>> > > > > >>>> > > > > http://localhost:8983/solr/providersearch/select?wt=json&state=state:%22CO%22&state1=state:%22NY%22&fl=ss,score&q=*:*&fq={!lucene%20v=$state} > > > > >>>> < > > > > http://localhost:8983/solr/providersearch/select?wt=json&state=state:%22CO%22&state1=state:%22NY%22&fl=ss,score&q=*:*&fq=%7B!lucene%20v=$state%7D > > > > > > > > >>>> > > > > >>>> This returns 10,000 > > > > >>>> > > > > >>>> I want to put an IF statement around which v to use. > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> On Fri, Jan 1, 2016 at 1:52 PM, William Bell < > billnbell@gmail.com> > > > > >>>> wrote: > > > > >>>> > > > > >>>>> Sure. > > > > >>>>> > > > > >>>>> If the state:NY returns results filter by state:NY, if it does > not, > > > > >>>>> then use state:CO. If we have results in NY, use it, otherwise > use > > > CO. > > > > >>>>> > > > > >>>>> OK? > > > > >>>>> > > > > >>>>> On Fri, Jan 1, 2016 at 1:15 PM, Upayavira > wrote: > > > > >>>>> > > > > >>>>>> > > > > >>>>>> > > > > >>>>>> On Thu, Dec 31, 2015, at 11:50 PM, William Bell wrote: > > > > >>>>>> > We are getting weird results with if(exists(a),b,c). We are > > > getting > > > > >>>>>> b+c!! > > > > >>>>>> > > > > > >>>>>> > > > > > >>>>>> > > > > http://localhost:8983/solr/providersearch/select?q=*:*&wt=json&state=state:%22CO%22&state1=state:%22NY%22&fq=if(exists(query($state1)),{!lucene%20v=$state1},{!lucene%20v=$state}) > > > > >>>>>> < > > > > http://localhost:8983/solr/providersearch/select?q=*:*&wt=json&state=state:%22CO%22&state1=state:%22NY%22&fq=if(exists(query($state1)),%7B!lucene%20v=$state1%7D,%7B!lucene%20v=$state%7D) > > > > > > > > >>>>>> > > > > > >>>>>> > I am getting NY and CO! > > > > >>>>>> > > > > > >>>>>> > I only want $state1, which is NY. > > > > >>>>>> > > > > > >>>>>> > Any other ways to craft this? > > > > >>>>>> > > > > >>>>>> Does this work at all? > > > > >>>>>> > > > > >>>>>> The if() function is a function query that can be used to > sort, > > > boost > > > > >>>>>> and as calculated fields. I haven't seen them used in > filtering. > > > > >>>>>> > > > > >>>>>> Also, the query() function does *not* do a query, it just says > > > "what > > > > >>>>>> would this document score for this query?" > > > > >>>>>> > > > > >>>>>> Can you describe in English what you are trying to do? > > > > >>>>>> > > > > >>>>>> Upayavira > > > > >>>>>> > > > > >>>>> > > > > >>>>> > > > > >>>>> > > > > >>>>> -- > > > > >>>>> Bill Bell > > > > >>>>> billnbell@gmail.com > > > > >>>>> cell 720-256-8076 > > > > >>>>> > > > > >>>> > > > > >>>> > > > > >>>> > > > > >>>> -- > > > > >>>> Bill Bell > > > > >>>> billnbell@gmail.com > > > > >>>> cell 720-256-8076 > > > > >>>> > > > > >>> > > > > >>> > > > > >>> > > > > >>> -- > > > > >>> Bill Bell > > > > >>> billnbell@gmail.com > > > > >>> cell 720-256-8076 > > > > >>> > > > > >> > > > > >> > > > > >> > > > > >> -- > > > > >> Bill Bell > > > > >> billnbell@gmail.com > > > > >> cell 720-256-8076 > > > > >> > > > > > > > > > > > > > > > > > > > > -- > > > > > Bill Bell > > > > > billnbell@gmail.com > > > > > cell 720-256-8076 > > > > > > > > > > > > > > > > > > > > > -- > > > > Bill Bell > > > > billnbell@gmail.com > > > > cell 720-256-8076 > > > > > > > > > > > -- > > Bill Bell > > billnbell@gmail.com > > cell 720-256-8076 > -- Bill Bell billnbell@gmail.com cell 720-256-8076 --001a11429e1e5b2eab05286bcd70--