To use certain queryParsers like the new geofilt or JTeam's spatial parser, one passes something like:
fq={!geofilt sfield=coordinates pt=33.820354,-118.266182 d=10}
I set this in the HOOK_apachesolr_query_alter by using $query->addFilter('','',false,'geofilt sfield=coordinates pt=33.820354,-118.266182 d=10'); but the resulting URL still tries to be a key:value (note the trailing colon):
fq={!geofilt sfield=coordinates pt=33.820354,-118.266182 d=10}:
which is syntactically incorrect. I added some conditional logic to allow for the 'local' queryFilter parameter to pass through if value is null. I might be missing an alternative way to pass this, so feel free to push back on this.
Comments
Comment #1
orbiteleven commentedSuppose someone should review this.
Comment #2
marthinal commentedBut maybe the filter name could be _query_ because when you want to filter with other fields you need the name fq=_query_:"{!geofilt sfield=coordinates pt=33.820354,-118.266182 d=10}" filtername1:value1 filtername2:value2 ...
Comment #3
marthinal commentedAlso _query_ could be the name like i said in #2 but we need to put !geofilt into quotation marks to work correctly.so maybe?
return $prefix . $filter['#name'] . ': "' . $filter['#value'].'" ';
Comment #4
pwolanin commentedCan't quote generally, since you might have a paranthesized query, right?
Comment #5
marthinal commented@pwolanin yes ... because range fq doesnt work with quote for example.You have the reason, excuse.
Comment #6
marthinal commentedMaybe only when the name is _query_ ?
Comment #7
marthinal commentedwe don`t need nothing for double quotes because is implemented exuseme today i had time to check correctly the code.
Comment #8
jimijamesi commentedI have been trying to integrate SOLR3.2 proximity search with Drupal 6.x & apachesolr 1.5
would the adjustment be similar in 6.x, should I start a new issue thread
Comment #9
marthinal commented@jimijamesi Yes its similar you can try for example in you hook_apachesolr_modify_query something like $query->add_filter("_query_", '{!geofilt sfield=location pt=36.7344685,-6.43353209 d=10}');
like this you add parameters to q.alt in D6 case.
And about the current issue i think we dont need a patch here because we can add what we need in D7 also using the same query syntax.
Comment #10
jsenich commented#9 works for me with one correction: the value part needs to be surrounded by double quotes, so it should look like this:
Comment #11
jimijamesi commentedI have a site with multiple content types. Some are location enabled nodes as well as non-location nodes (articles/stories)
When implementing this solution solr only returns nodes that have location info.
How could the code be adjusted to return both location and non-location nodes
Has anyone experienced this problem?
Comment #12
pwolanin commentedSo using _query_ this works with no code change needed?
Comment #13
pwolanin commentedcan someone add this to documentation?
Comment #14
marthinal commentedAdded http://drupal.org/node/443986 .
Comment #15
nick_vhI guess I can close this since it is working as designed, correct me if I'm wrong and reopen when needed.
Comment #16
dstuart commentedI have reopened as I am having a similar but different problem.
When trying to add complex filters the addFilter strips my query
((bundle:(event) AND im_vid_99:123) OR (bundle:(exhibition) AND im_vid_23:989))
Ends up as
(:bundle:(event))
I can try to work around this with the _query_ suggestion above but I was trying to set this in the custom filters section of the apachesolr pages.
Could we look into adding a _raw_ keyword option that allows us to set whatever we like in the fq, this seems overly restrictive and other than removing the protected option from the $params field I can't see a work around
Regards,
Dave
Comment #17
nick_vhHow do you add this param? Using the UI or in code?
Comment #18
nick_vhComment #19
nick_vhSee if this solves it?
In the custom textfield you can add _query_: in front of your custom query so it will validate, and it will remove the _query_: part afterwards.
Comment #20
dstuart commentedTurns out the _query_ works it was apachesolr_search_conditions_default that needed some work it seems as though $search_page->settings['fq'] is stored as a array
Attached is a patch
Comment #21
nick_vhNow we check if $search_page_fq is not empty and if it is an array. We could do this in 1 if.
Also str_replace supports arrays
so the foreach should disappear I guess.
Comment #22
dstuart commentedsorry missed this. foreach could disappear for path_replacer but items need to be added individually to the fq else you get a nesting issue that is causing the query not to work
Comment #23
dstuart commentedis this ok can push this to dev?
Comment #25
nick_vhdstuart, please provide a valid patch file so at least the testbot is happy :-)