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 9441D17D64 for ; Sat, 9 Jan 2016 21:32:21 +0000 (UTC) Received: (qmail 46554 invoked by uid 500); 9 Jan 2016 21:32:17 -0000 Delivered-To: apmail-lucene-solr-user-archive@lucene.apache.org Received: (qmail 46480 invoked by uid 500); 9 Jan 2016 21:32:17 -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 46468 invoked by uid 99); 9 Jan 2016 21:32:17 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Jan 2016 21:32:17 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id E9181C0CFE for ; Sat, 9 Jan 2016 21:32:16 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.881 X-Spam-Level: ** X-Spam-Status: No, score=2.881 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, WEIRD_PORT=0.001] autolearn=disabled Authentication-Results: spamd4-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 (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id nrFOFxgJ8jNg for ; Sat, 9 Jan 2016 21:32:10 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 1CD8E20511 for ; Sat, 9 Jan 2016 21:32:10 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id l65so20766865wmf.3 for ; Sat, 09 Jan 2016 13:32:10 -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=rrly1FrCRKWIT7rwu6kwyAM5CvttDnShRLaLtvokHoQ=; b=mrDzUmXCbNv2DOoVGMcWqUiRRnQ0JLjrnzjAdHB+vrxoTUS9a2R9xcQWvCd8BMEfqr ppWTzvLZ1Yhw07/7aNWSRgguhZShtzh6KgkEZgCO6i5FNDuu7t6J2c4aJV3w5dFpNzuf LQzCYzsdcxoP1F88fh1ayPFLqIOICktcip4VjfqDloWb9NwgPu+NnKL4I6pFtlyZ0/wv YAAq2SvqEffqANOODCT2tRVquwX5i3RK6smQOcC/c6Y+wVnd9ONxNVckIDo53awyNeLT S/tYgPDjlugzD6NdzzLek4pl+bGz2gwil/75BC8a5iM7joYlCb2pec2FgGth8mfdbBfC KCKw== MIME-Version: 1.0 X-Received: by 10.28.128.215 with SMTP id b206mr6052000wmd.52.1452375129611; Sat, 09 Jan 2016 13:32:09 -0800 (PST) Received: by 10.27.178.224 with HTTP; Sat, 9 Jan 2016 13:32:09 -0800 (PST) In-Reply-To: <80B41740-F2F5-4A4B-8E0F-1E1357F0D02E@gmail.com> References: <1777145888.2064964.1452359338234.JavaMail.yahoo@mail.yahoo.com> <80B41740-F2F5-4A4B-8E0F-1E1357F0D02E@gmail.com> Date: Sat, 9 Jan 2016 16:32:09 -0500 Message-ID: Subject: Re: Dynamically Adding query parameters in my custom Request Handler class From: Mark Robinson To: solr-user@lucene.apache.org Content-Type: multipart/alternative; boundary=001a1141ef62ae673b0528ed6ff1 --001a1141ef62ae673b0528ed6ff1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks Eric! Appreciate your valuable suggestions. Now I am getting the concept of a search-component better! So my custom class is just this after removing the SOLRJ part, as I just need to modify the query by adding some parameters dynamically before the query actually is executed by SOLR:- public void process(ResponseBuilder builder) throws IOException { SolrParams *params *=3D builder.req.getParams(); String q =3D params.get(CommonParams.Q); ModifiableSolrParams *params1* =3D new ModifiableSolrParams(*params*); *params1.add*("fl", "id"); //Added this line * builder.req.setParams(params1);* System.out.println("q is ### "+q); } Note:- Nothing inside prepare() method, In my /select RH added the following in solrconfig.xml just bef close of the tag:- exampleComponent Still it is not restricting o/p fields to only fl. The console output shows the following:- q is ### *:* 16140 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore =C3=BB [collection1] we bapp=3D/solr path=3D/select params=3D{q=3D*:*} hits=3D4 status=3D0 QTime=3D= 4 Note:- the "###" proves that it accessed the custom class. But the ModifiableSolrParams params1 =3D new ModifiableSolrParams(params); params1.add("fl", "id"); did not take effect. I think I am near to developing my first dynamic query component. Could some one please tell me where I am going wrong this time. Appreciate any help.I am very eager to see my first dynamic query implemented using a customized Search Component!! Thanks! Mark. On Sat, Jan 9, 2016 at 3:38 PM, Erik Hatcher wrote= : > Woah, Mark=E2=80=A6. you=E2=80=99re making a search request within a sea= rch component. > Instead, let the built-in =E2=80=9Cquery=E2=80=9D component do the work f= or you. > > I think one fix for you is to make your =E2=80=9Ccomponents=E2=80=9D be = =E2=80=9Cfirst-components=E2=80=9D > instead (allowing the other default search components to come into play). > You don=E2=80=99t need to search within your component, just affect param= eters, > right? > > > =E2=80=94 > Erik Hatcher, Senior Solutions Architect > http://www.lucidworks.com > > > > > On Jan 9, 2016, at 3:19 PM, Mark Robinson > wrote: > > > > Hi, > > > > Ahmet, Jack, Thanks for the pointers. > > My requirement is, I would not be having the facets or sort fields or i= ts > > order as static. > > For example suppose for a particular scenario I need to show only 2 > facets > > and sort on only one field. > > For another scenario I may have to do facet.field for a different set o= f > > fields and sort on again another set of fields. > > Consider there are some sort of user preferences for each query. > > > > So I think I may not be able to store my parameters like facet fields, > sort > > fields etc preconfigured in solrconfig.xml. > > Please correct me if I am wrong. > > > > Based on Ahmet's reply I created a CustomSearchComponent with help from > the > > net. > > I created a dummy RH and added this as the searchComponent in > > SolrConfig.xml:- > > > > > > exampleComponent > > > > > > > > > class=3D"org.ExampleSearchComponent"> > > > > > > ..invoked it using:- > > http://localhost:8984/solr/myexample?q=3D*:* > > The o/p gave me that one record will ALL FIELDS fully in xml format. > > *It did not give only the "id" field which was what I was trying as a > test!* > > > > > > my code for the custom Search Component shared below please:- > > Before that I have these queries:- > > 1. In my code,Instead of hitting the server AGAIN using SolrJ to enforc= e > my > > params (just "fl" newly added) , is there any way the query can = be > > executed with my additional fl param. > > 2. Just adding the input additional params is what I want to achieve. I > > dont want to do anything on the response. > > Currently I am doing it:- > > --> builder.rsp.add( "example", doc.getFields()); > > Note:- I removed this line and again when I ran this query NO OUTPUT > came. > > So suppose I used it along with any of my existing RH by adding in > > searchcomponent, I want it to only affect the input querying by addin= g > > additional params and should not influence the rendering of the o/p in > any > > way. How do I add this to one of my existing Request Handlers only to > > influence the input for querying and NOT o/p format in any way. > > 3. Why is all fields being rendered for the one doc I selected to come > back > > in my "example" variable, when I am actually restricting the fields to > > only &fl=3Did > > > > Any help is greatly appreciated. > > > > > > My console shows the following ie ... looks like the filtering happens > but > > what is /select doing here when I am calling > > /myexample:- > > > > 154956 [qtp1856056345-18] INFO org.apache.solr.core.SolrCore =C3=BB > > [collection1] w > > ebapp=3D/solr path=3D*/select* params=3D*{q=3D*:*&fl=3Did&wt=3Dxml&vers= ion=3D2.2}* > hits=3D4 > > status=3D0 > > QTime=3D16 > > > [stored,indexed,tokenized,omitNorms,indexOptions=3DDOCS_ONLY,numericType= =3DINT,numer > > icPrecisionStep=3D16, > > org.apache.lucene.document.LazyDocument$LazyFi > > eld@38585de9, org.apache.lucene.document.LazyDocument$LazyField@1b3edb9= 6 > , > > org.ap > > ache.lucene.document.LazyDocument$LazyField@9692beb, > > org.apache.lucene.document. > > LazyDocument$LazyField@683f4dad, > > org.apache.lucene.document.LazyDocument$LazyFie > > ld@12f2e256, org.apache.lucene.document.LazyDocument$LazyField@7ffd69f5= ] > > 155080 [qtp1856056345-21] INFO org.apache.solr.core.SolrCore =C3=BB > > [collection1] w > > ebapp=3D/solr path=3D*/myexample* params=3D{*q=3D*:**} status=3D0 QTime= =3D299 > > > > > > rough java class:- > > > > public class ExampleSearchComponent extends SearchComponent { > > > > @Override > > public void prepare(ResponseBuilder builder) throws IOException { > > > > } > > > > @Override > > public void process(ResponseBuilder builder) throws IOException { > > SolrParams params =3D builder.req.getParams(); > > String q =3D params.get(CommonParams.Q); > > ModifiableSolrParams params1 =3D new ModifiableSolrParams(params); > > params1.add("fl", "id"); > > System.out.println("q is "+q); > > > > QueryResponse response=3Dnull; > > > > HttpSolrServer server =3D new HttpSolrServer( " > > http://localhost:8984/solr/collection1" ); > > server.setParser(new XMLResponseParser()); > > > > try{ > > response =3D server.query( params1 ); > > }catch(Exception e){} > > > > SolrDocumentList results =3D new SolrDocumentList(); > > SolrIndexSearcher searcher =3D builder.req.getSearcher(); > > Document doc=3Dsearcher.doc(0); > > System.out.println(doc.getFields()); > > > > > > builder.rsp.add( "example", doc.getFields()); > > } > > > > > > @Override > > public String getDescription() { > > return "ExampleSearchComponent"; > > } > > > > @Override > > public String getSource() { > > return ""; > > } > > > > //@Override > > public String getSourceId() { > > return ""; > > } > > > > @Override > > public String getVersion() { > > return "1.0"; > > } > > } > > > > > > > > > > > > Thanks and Rgds, > > Mark. > > > > On Sat, Jan 9, 2016 at 12:38 PM, Jack Krupansky < > jack.krupansky@gmail.com> > > wrote: > > > >> Sure, you CAN do this, but why would you want to? I mean, what exactly > is > >> the motivation here? If you truly have custom code to execute, fine, > but if > >> all you are trying to do is set parameters, a custom request handler i= s > >> hitting a tack with a sledge hammer. For example, why isn't setting > >> defaults in solrconfig sufficient for your needs? At least then you ca= n > >> change parameters with a simple text edit rather than require a Java > build > >> and jar deploy. > >> > >> Can you share what some of the requirements are for your custom reques= t > >> handler, including the motivation? I'd hate to see you go off and inve= st > >> significant effort in a custom request handler when simpler techniques > may > >> suffice. > >> > >> -- Jack Krupansky > >> > >> On Sat, Jan 9, 2016 at 12:08 PM, Ahmet Arslan > > >> wrote: > >> > >>> Hi Mark, > >>> > >>> Yes this is possible. Better, you can use a custom SearchComponent fo= r > >>> this task too. > >>> You retrieve solr parameters, wrap it into ModifiableSolrParams. Add > >> extra > >>> parameters etc, then pass it to underlying search components. > >>> > >>> Ahmet > >>> > >>> > >>> On Saturday, January 9, 2016 3:59 PM, Mark Robinson < > >>> mark123learns@gmail.com> wrote: > >>> Hi, > >>> When I initially fire a query against my Solr instance using SOLRJ I > pass > >>> only, say q=3D*:*&fq=3D(myfield:vaue1). > >>> > >>> I have written a custom RequestHandler, which is what I call in my > SolrJ > >>> query. > >>> Inside this custom request handler can I add more query params like s= ay > >> the > >>> facets etc.. so that ultimately facets are also received back in my > >> results > >>> which were initially not specified when I invoked the Solr url using > >> SolrJ. > >>> > >>> In short, instead of constructing the query dynamically initially in > >> SolrJ > >>> I want to add the extra query params, adding a jar in Solr (a java co= de > >>> that will check certain conditions and dynamically add the query para= ms > >>> after the initial SolrJ query is done). That is why I thought of a > custom > >>> RH which would help we write a java class and deploy in Solr. > >>> > >>> Is this possible. Could some one get back please. > >>> > >>> Thanks! > >>> Mark. > >>> > >> > > --001a1141ef62ae673b0528ed6ff1--