Closed (fixed)
Project:
Apache Solr Search
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Mar 2009 at 00:43 UTC
Updated:
18 Mar 2011 at 20:58 UTC
I am trying to workout how to change the names in the Filter by author block to Real Names ( http://drupal.org/project/realname ).
I think it has something to do with the apachesolr_search_get_username function:
/**
* Callback function for the 'Filter by name' facet block.
*/
function apachesolr_search_get_username($facet) {
if ($facet == 0) {
return variable_get('anonymous', t('Anonymous'));
}
else {
return db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $facet));
}
}
But it may not as I am getting out of my depth!
Comments
Comment #1
pwolanin commentedHmm, well this should probably be a theme function or call a theme function.
Comment #2
stopbox commentedYes, if it uses the theme function, the Real Name module will automatically format the user name correctly (it already is in the Solr search results). I am just struggling to work out to change the code so it calls a theme function.
Comment #3
janusman commentedI guess the actual request is to have more hooks in the module.
How about having the callback function inside apachesolr_facet_block() [optionally?] be calls to theming functions? E.g. instead of calling locale_language_name() to get the locale name, it could try to call theme('locale_language_name')
Another would be renaming apachesolr_facet_block() to theme_apachesolr_facet_block()? This might be overkill though =) I guess theming functions are just the ones "that return HTML" and this module is returning an block array, of which only the "content" element is HTML.
Comment #4
JacobSingh commentedI don't have a good architectural idea here...
Perhaps we just make that particular block provide an option?
I'm not sure what we want to do here, we certainly don't want to call user_load on every facet.
-J
Comment #5
rjbrown99 commentedI don't know about 1.x, but at least in 2.x you can do this at the theme layer. The module uses hook_theme for theme_apachesolr_breadcrumb_uid. Head on over to your template.php for your theme, and start with:
Then you can take over the function and theme it however you like. I'm using content profiles with CCK fields for firstname and lastname.
Works for me. You will need to adjust the content_profile_load call appropriately for $type to match the content type of your profiles.
Comment #6
jpmckinney commentedSeems to be the case in 1.x, too. Follow instructions in #5. Marking #704238: Real name to appear in author filter block duplicate.
Comment #7
rockwright commented#5—I’m using core’s profile along with the RealName module. I don’t allow anonymous users to submit content so there won’t be any anonymous authors in the filter block. Can you please help by rewriting the snippet?
Comment #8
jpmckinney commented#7 - the snippet will still work.
Comment #9
3dloco commented#5 is not working for me...instead of getting the author's realname I am getting the realname of the user that is browsing the search results.
Below is the modification I did to make it work...+1 for adding this (if possible) ;)
apachesolr_search.module
Comment #10
pwolanin commentedComment #11
geerlingguy commentedI'm having trouble getting the names for anyone besides user 1 loaded... If I use either snippets, in #5 or #9, the first user listed (user 1) has that user's realname... but any other authors underneath are not listed. Also, in each search snippet, other users' usernames (not their real names) are listed as well.
Is that theme function used both for the 'Filter by author' block and the Search Results snippet metadata?
[Edit:] Nevermind, it looks like I had some content that was published by a blocked user... and Solr didn't reindex the content, so the uid was wrong... Here's the code I ended up using (I was going to do a user_load(), but found that realname_get_user() performs a bit better for our purposes:
Follow-up issue created in Realname's issue queue: #989908: Add ApacheSolr Search Facet uid's to Realname
Comment #12
imDhaval commented+1
Comment #13
dave reidDoes the code in #11 work? It would have been nice to have that posted in #989908: Add ApacheSolr Search Facet uid's to Realname. :)
Comment #14
geerlingguy commentedCode in #11 seems to work well, and I've posted it into #989908: Add ApacheSolr Search Facet uid's to Realname as well.
Comment #15
pwolanin commentedseems fixed