Re: How to make 'fq' optional?

2013-07-11 Thread Mikhail Khludnev
https://lucene.apache.org/solr/4_2_0/solr-core/org/apache/solr/search/SwitchQParserPlugin.html

Hoss cares about you!


On Wed, Jul 10, 2013 at 10:40 PM, Learner bbar...@gmail.com wrote:

 I am trying to make a variable in fq optional,

 Ex:

 /select?first_name=peterfq=$first_nameq=*:*

 I don't want the above query to throw error or die whenever the variable
 first_name is not passed to the query instead return the value
 corresponding
 to rest of the query. I can use switch but its difficult to handle each and
 every case using switch (as I need to handle switch for so many
 variables)... Is there a way to resolve this via some other way?



 --
 View this message in context:
 http://lucene.472066.n3.nabble.com/How-to-make-fq-optional-tp4077042.html
 Sent from the Solr - User mailing list archive at Nabble.com.




-- 
Sincerely yours
Mikhail Khludnev
Principal Engineer,
Grid Dynamics

http://www.griddynamics.com
 mkhlud...@griddynamics.com


How to make 'fq' optional?

2013-07-10 Thread Learner
I am trying to make a variable in fq optional, 

Ex: 

/select?first_name=peterfq=$first_nameq=*:* 

I don't want the above query to throw error or die whenever the variable
first_name is not passed to the query instead return the value corresponding
to rest of the query. I can use switch but its difficult to handle each and
every case using switch (as I need to handle switch for so many
variables)... Is there a way to resolve this via some other way? 



--
View this message in context: 
http://lucene.472066.n3.nabble.com/How-to-make-fq-optional-tp4077042.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-29 Thread bbarani
Hoss, for some reason this doesn't work when I pass the latlong value via
query..

This is the query.. It just returns all the values for fname='peter'
(doesn't filter for Tarmac, Florida).

fl=*,scorerows=10qt=findpersonfps_latlong=26.22084,-80.29fps_fname=peter

*solrconfig.xml*

lst name=appends
str name=fq{!switch case='*:*' default=$fq_bbox
v=$fps_latlong}/str
/lst
lst name=invariants
str name=fq_bbox_query_:{!bbox pt=$fps_latlong sfield=geo
d=$fps_dist}/str
/lst

*Works when used via custom component:*

This works fine when the latlong value is passed via custom component. We
have a custom component which gets the location name via query, calculates
the corresponding lat long co-ordinates stored in TSV file and passes the
co-ordinates to the query.


*Custom component config:*

 searchComponent name=geo class=com.customcomponent
str name=placenameFilecentroids.tsv/str
str name=placenameQueryParamfps_where/str
str name=latQueryParamfps_latitude/str
str name=lonQueryParamfps_longitude/str
str name=latlonQueryParamfps_latlong/str
str name=distQueryParamfps_dist/str
float name=defaultDist48.2803/float
float name=boost1.0/float
  /searchComponent

*Custom component query:*
fl=*,scorerows=10*fps_where=new york,
ny*qt=findpersonfps_latlong=26.22084,-80.29fps_dist=.10fps_fname=peter

Is it a bug?



--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066862.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-29 Thread Chris Hostetter

: Hoss, for some reason this doesn't work when I pass the latlong value via
: query..
...
: fl=*,scorerows=10qt=findpersonfps_latlong=26.22084,-80.29fps_fname=peter

Hmmm, are these appends  invariants on your findperson requestHandler?

What does debugQuery=true show you the pplied filters are?

: lst name=invariants
: str name=fq_bbox_query_:{!bbox pt=$fps_latlong sfield=geo
: d=$fps_dist}/str
: /lst

Why do you have the _query_ hack in there?  i haven't had a chance to test 
this, but perhaps that hack doesn't play nicely with localparam variable 
substitution? it should just be...

   str name=fq_bbox{!bbox pt=$fps_latlong sfield=geo d=$fps_dist}/str

: This works fine when the latlong value is passed via custom component. We
: have a custom component which gets the location name via query, calculates
: the corresponding lat long co-ordinates stored in TSV file and passes the
: co-ordinates to the query.


Ok wait a minute -- all bets are off about this working if you have a 
custom component in the mix adding/removing params.  you need to provide 
us with more details about exactly how your component works, where it's 
configured in the component list, and how it is adding the fps_latlong 
param it generates to the query, becuase my guesses are one of two things 
are happening:

1) your component is doing it's logic after the query parsing has already 
happened and the variables have been evaluated -- at which point 
fps_latlong isn't set yet, so you get the case='*:*' behavior

2) your component is doing it's logic before the query parsing happens, 
but it is setting the value of fps_latlong in a way that the query parsing 
code doens't see it hen resolving the local variables.


-Hoss


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-29 Thread bbarani
Ok..I removed all my custom components from findperson request handler..

  requestHandler name=findperson class=solr.SearchHandler
default=false
lst name=defaults
  str name=defTypelucene/str
  str name=echoParamsexplicit/str
  int name=rows10/int
  str name=q.opAND/str
  str name=qfperson_name_all_i/str
  int name=score_truncation_cliff50/int
  int name=fps_dist32/int
  str name=q
  *:*
  /str
  lst name=appends
str name=fq{!switch case='*:*' default=$fq_bbox
v=$fps_latlong}/str
/lst
lst name=invariants
str name=fq_bbox_query_:{!bbox pt=$fps_latlong sfield=geo
d=$fps_dist}/str
/lst
/lst
arr name=components
strquery/str
  strdebug/str
/arr
  /requestHandler


My query:
select?fl=*,scorerows=10qt=findpersonfps_latlong=42.3482,-75.1890

The above query just returns everything back from SOLR (should only return
results corresponding to lat and long values passed in the query)...

I even tried changing the below hack, but got the same results.

str name=fq_bbox{!bbox pt=$fps_latlong sfield=geo
d=$fps_dist}/str

Not sure if I am missing something...




--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066872.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-29 Thread Chris Hostetter

: lst name=defaults
...
:   lst name=appends
: str name=fq{!switch case='*:*' default=$fq_bbox
: v=$fps_latlong}/str
: /lst
: lst name=invariants
: str name=fq_bbox_query_:{!bbox pt=$fps_latlong sfield=geo
: d=$fps_dist}/str
: /lst
: /lst

...you have your appends and invariants nested inside your defaults -- 
they should be siblings...

 lst name=defaults
...
 /lst
 lst name=appends
...
 /lst
 lst name=invariants
...
 /lst

-Hoss


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-29 Thread bbarani
 I totally missed that..Sorry about that :)...It seems to work fine now...



--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066891.html
Sent from the Solr - User mailing list archive at Nabble.com.


SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread bbarani
I am using the SOLR geospatial capabilities for filtering the results based
on the particular radius (something like below).. I have added the below fq
query in solrconfig and passing the latitude and longitude information
dynamically..

select?q=firstName:johnfq={!bbox%20sfield=geo%20pt=40.279392,-81.85891723%20d=10}

str name=q
_query_:{firstName=$firstName}
/str

str name=fq
_query_:{!bbox pt=$fps_latlong sfield=geo d=$fps_dist}
/str

Now when I pass the latitude and longitude data, the query works fine but
whenever I dont pass the latitude / longitude data it throws exception.. Is
there a way to make fq optional? Is there a way to ignore spatial queries
when the co ordinates are not passed? Looking for something like dismax,
that doesnt throw any exceptions...





--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread David Smiley (@MITRE.org)
Your client needs to know to submit the proper filter query conditionally. 
It's not really a spatial issue, and I disagree with the idea to make bbox
(and all other query parsers for that matter) do nothing if not given an
expected input.

~ David


bbarani wrote
 I am using the SOLR geospatial capabilities for filtering the results
 based on the particular radius (something like below).. I have added the
 below fq query in solrconfig and passing the latitude and longitude
 information dynamically but I am hardcoding the dynamic query in
 solrconfig.xml..
 
 select?q=firstName:johnfq={!bbox%20sfield=geo%20pt=40.279392,-81.85891723%20d=10}
 
 
 str name=q
 _query_:{firstName=$firstName}
 
 /str
 
 str name=fq
 _query_:{!bbox pt=$fps_latlong sfield=geo d=$fps_dist}
 
 /str
 Now when I pass the latitude and longitude data, the query works fine but
 whenever I dont pass the latitude / longitude data it throws exception..
 Is there a way to make fq optional? Is there a way to ignore spatial
 queries when the co ordinates are not passed? Looking for something like
 dismax, that doesnt throw any exceptions...





-
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066604.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread bbarani
David, I felt like there should be a flag with which we can either throw the
error message or do nothing in case of bad inputs.. 



--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066610.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread Erik Hatcher
I imagine the new switch query parser could help here somehow.  

Erik

On May 28, 2013, at 16:43, David Smiley (@MITRE.org) dsmi...@mitre.org 
wrote:

 Your client needs to know to submit the proper filter query conditionally. 
 It's not really a spatial issue, and I disagree with the idea to make bbox
 (and all other query parsers for that matter) do nothing if not given an
 expected input.
 
 ~ David
 
 
 bbarani wrote
 I am using the SOLR geospatial capabilities for filtering the results
 based on the particular radius (something like below).. I have added the
 below fq query in solrconfig and passing the latitude and longitude
 information dynamically but I am hardcoding the dynamic query in
 solrconfig.xml..
 
 select?q=firstName:johnfq={!bbox%20sfield=geo%20pt=40.279392,-81.85891723%20d=10}
 
 
 str name=q
_query_:{firstName=$firstName}
 
 /str
 
 str name=fq
_query_:{!bbox pt=$fps_latlong sfield=geo d=$fps_dist}
 
 /str
 Now when I pass the latitude and longitude data, the query works fine but
 whenever I dont pass the latitude / longitude data it throws exception..
 Is there a way to make fq optional? Is there a way to ignore spatial
 queries when the co ordinates are not passed? Looking for something like
 dismax, that doesnt throw any exceptions...
 
 
 
 
 
 -
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
 --
 View this message in context: 
 http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066604.html
 Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread bbarani
Erik,

I am trying to enable / disable a part of fq based on a particular value
passed from the query.

For Ex: If I have the value for the keyword where in the query then I would
like to enable this fq, else just ignore it.. 

select?where=New york,NY

Enable only when where has some value. (I get the value passed in query
inside fq - using $where)

I need something like..

*if($where!=null){*
str name=fq
{!bbox pt=$fps_latlong sfield=geo d=$fps_dist}
/str 
*}*

 Is it possible to achieve this using the switch query parser?

Thanks,
BB



--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066624.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread Chris Hostetter

: David, I felt like there should be a flag with which we can either throw the
: error message or do nothing in case of bad inputs.. 

As erik alluded to in his response, you should be able to configure an 
appended fq using the switch QParserPlugin to get something like what you 
are 
describing, by taking advantage of the default behavior.

I think you'd want something along the lines of...

lst name=defaults
  int name=fps_dist50/int !-- or whatever default you want --
/lst
lst name=appends
  str name=fq{!switch case='*:*' default=$fq_bbox v=$fps_latlong}/str
/lst
lst name=invariants
  str name=fq_bbox{!bbox pt=$fps_latlong sfield=geo d=$fps_dist}/str
/lst

The result of something like that should be:

 * if a user specifies a non blank fps_latlong param, the the query will 
be filtered using a bbox based on that center and the specified  fps_dist 
is (or the default fps_dist if the user didn't specify one)
 * if the user does not specify an fps_latlong param, or the fpls_latlong 
param is blank, then no effective filtering is done (the filter matches 
all docs)

Here's an equivilent example using the Solr 4.2.1 examle data and 
configs...

fps_latlong specified, matches a single document in the radius..

http://localhost:8983/solr/select?q=*:*fps_dist=100fps_bbox={!bbox%20pt=$fps_latlong%20sfield=store%20d=$fps_dist}fq={!switch%20case=%27*:*%27%20default=$fps_bbox%20v=$fps_latlong}fps_latlong=35.0752,-97.032


fps_latlong not specified, or blank, matches all docs...

http://localhost:8983/solr/select?q=*:*fps_dist=100fps_bbox={!bbox%20pt=$fps_latlong%20sfield=store%20d=$fps_dist}fq={!switch%20case=%27*:*%27%20default=$fps_bbox%20v=$fps_latlong}fps_latlong=
http://localhost:8983/solr/select?q=*:*fps_dist=100fps_bbox={!bbox%20pt=$fps_latlong%20sfield=store%20d=$fps_dist}fq={!switch%20case=%27*:*%27%20default=$fps_bbox%20v=$fps_latlong}fps_latlong=+++
http://localhost:8983/solr/select?q=*:*fps_dist=100fps_bbox={!bbox%20pt=$fps_latlong%20sfield=store%20d=$fps_dist}fq={!switch%20case=%27*:*%27%20default=$fps_bbox%20v=$fps_latlong}


More info...

https://lucene.apache.org/solr/4_3_0/solr-core/org/apache/solr/search/SwitchQParserPlugin.html
http://searchhub.org/2013/02/20/custom-solr-request-params/


-Hoss


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread bbarani
Hoss, you read my mind Thanks a lott for your awesome
explanation! You rock!!!



--
View this message in context: 
http://lucene.472066.n3.nabble.com/SOLR-4-3-0-How-to-make-fq-optional-tp4066592p4066630.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: SOLR 4.3.0 - How to make fq optional?

2013-05-28 Thread Chris Hostetter

: As erik alluded to in his response, you should be able to configure an 
: appended fq using the switch QParserPlugin to get something like what you 
are 
: describing, by taking advantage of the default behavior.

I've updated the javadocs with 2 additiona examples inspired by this 
thread..

http://svn.apache.org/viewvc?view=revisionrevision=1487166


-Hoss