Closed (fixed)
Project:
Apache Solr Search
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Apr 2009 at 09:16 UTC
Updated:
10 Jun 2009 at 16:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
aufumy commentedThis patch is against current dev branch.
Moved code inside apachesolr_search_search() to
* apachesolr_search_params($query) which returns $params
* apachesolr_search_query($keys, $query, $params) which contains $solr->search() and returns $results;
So that when returning custom search results, can create a hook_apachesolr_modify_query with a custom caller (e.g. mytest_caller):
Comment #2
aufumy commentedComment #3
aufumy commentedChanged the function name from apachesolr_search_query to apachesolr_search_results for more clarity.
Comment #4
aufumy commentedMoved $_GET variables to the top, and passed it to _apachesolr_search_search, such as $filters, $solrsort, $page.
So that when other modules would like to return results from apache solr module can call on
_apachesolr_search_search($keys, $filters, $solrsort, $page);e.g.
$results = _apachesolr_search_search('test', 'type:blog', '', 3);Comment #5
pwolanin commentedIf this is supposed to be a public API function, then it should not have a leading _
Comment #6
aufumy commentedThis patch, the function name is
function apachesolr_search_searchresults($keys, $filters = '', $solrsort = '', $page = 0, $caller = 'apachesolr_search')Comment #7
pwolanin commentedThis approach doesn't seem to me to be maximizing re-usability of the code. hook_search should be calling 3 or 4 functions that each do a subset of the current monster code, so that each piece could be reused or substituted, I think.
Comment #8
pwolanin commentedLike this - just moving code around, no functional changes.
Comment #9
aufumy commentedHow about hook_search calling one function which does some processing/validation and calls the 3 or 4 functions.
inside function apachesolr_search_searchresults() is the try/catch block with
as well as apachesolr_drupal_query(), apachesolr_current_query(), apachesolr_modify_query(), $solr->search(), apachesolr_static_response_cache(), apachesolr_has_searched() and finally returning apachesolr_process_response()
On the note of all this moving around, as well how about the use of >module_load_include() to move the search code, which is only used on search pages out of the apachesolr_search.module file, to reduce the overall load to drupal pages.
Likely, the increase in performance of drupal will be minimal for this type of change in only one module, but it might add up with more modules.
Comment #10
Scott Reynolds commentedI looked at the latest patch (#8) and I love it. This is great stuff. Big huge +1. Patch looks solid to me. Im excited for this one
Comment #11
Scott Reynolds commentedNeed to examine the functions and the params passed into each one. for instance apachesolr_search_params_basic($query, $solr) doesn't use the $solr object. The only one that uses the solr object is the boost function, and that doesn't use the query object. So a lil more refactoring is probably required.
Consider declaring the variable type for the query object in the functions as well? I.E.
Comment #12
pwolanin commented@Scott - yes, $solr is not needed in all, but thought in terms of having these functions as an APi there is not harm in requiting it so that we can change the implementation of each function more readily.
@afumy - yes, once the refactoring is working, I'd expect to move a bunch of this code into an include file.
Comment #13
Scott Reynolds commentedI would urge you not to move this to an include file
If another module needs these functions it should note be put in a separate file (/me glares at pathauto)
Re: passing in extra params
- readability
- clarity
I have really no strong arguments other then Im sure CS professors would be offended. I think its wrong, and I wouldn't commit it with the $solr objects.
Comment #14
pwolanin commented@Scott - moving code to an include file to not is really that bad, really a trade-off in terms of how often it's needed.
Comment #15
Scott Reynolds commentedThen create a way to lazy load it thats not _pathauto_include(). Basically, don't require the 'other' module to know that I have to include a file.
Comment #16
pwolanin commentedThis is closer to what afumy is suggesting, but I think it makes sense for the try/catch to be outside to an external caller could handle the Exception differently.
Comment #17
pwolanin commentedslightly better abstraction - pass in $base_path too. Also, make sorting work...
Comment #18
pwolanin commentedcommitted this last patch to CVS - please test before marking fixed so I can roll a release.
Comment #19
pwolanin commentedok, well it's in beta10
Comment #20
aufumy commentedAwesome Peter, thank you.
This really helps, as I had some people using the pre-dismax style of returning custom search results, by calling apachesolr_search_search('search', "keywords type:blog"), now can call apachesolr_search_execute('keywords', 'type:blog')
Comment #21
aufumy commentedI am of the opinion that CS professors would be offended to learn that only ~1% or less of code being loaded into each and every page load is used. Possibly a couple of megabytes worth of memory could be freed up.
Functions that other modules are likely to use might make sense to be inside the .module file, otherwise there is no point imo.
Comment #22
Scott Reynolds commentedhttp://drupal.org/project/apachesolr_views
http://drupal.org/project/localsolr
http://drupal.org/project/apachesolr_ubercart
http://drupal.org/project/apachesolr_rdf
4 immature modules that are using apache solr intergration as an api. Seems to me these api functions could be pretty useful.