I have the RealName module install on my site and noticed it wasn't successfully modifying the name of the author with the Guided Search block. Digging into the code revealed that it was directly referring to the 'name' column within the user table in the database rather than using the user object. The RealName module and potentially other modules made adjustments to the user object, not the database, so with two lines I was able to modify the Author Facet module to get the author name from the object instead. This is done by including the follow code on line 232 before $this->_name = $name; within the author_facet_category function.

	$account = user_load(array('uid' => $uid));
	$name = $account->name;

Here's the completed new function.

  function author_facet_category($uid, $name, $count = NULL) {
    parent::faceted_search_category($count);
    $this->_uid = $uid;
    $account = user_load(array('uid' => $uid));
    $name = $account->name;
    $this->_name = $name;
  }

I've also attached a patch file.

CommentFileSizeAuthor
author_facet.module.patch313 bytespianomansam
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David Lesieur’s picture

Calling user_load() for each user name appearing in the guided search will add significant overhead. I am not convinced that supporting modules that alter user names is worth that extra overhead... Do you know many other modules that do such thing? My feeling is that the extra overhead would be a waste for 99% of the sites out there.

We can't really afford to slow down a module that's already performing very costly queries.

pianomansam’s picture

Point well made. I'm not sure of any other modules that would do such a thing. And I can see how this introduces some extra overhead. However, I do have two points to make of my own. First, the current way of finding out the username, i.e. direct DB access, while having low overhead, is not very Drupal like. Second, the default amount of terms to display for other facets is ten. Is ten calls to user_load() too much overhead? I completely understand if this patch doesn't make it to the actual module, but having it here in the issue list will help others who have the same situation that I do.

David Lesieur’s picture

The overhead will vary from site to site. user_load() runs at least two SQL queries per call, and then other modules may add queries of their own through implementations of hook_user(). If your site is using node profiles, then node_load() is likely to get called too, adding more queries and invoking hook_nodeapi()...

But yes, your patch might be useful to others, thanks for sharing it!

pianomansam’s picture

David Lesieur,

Your comments about the unnecessary overhead got me thinking about how to reduce that but still support other modules. After being inspired by #387840: Embedding forms & alternative for node_load(), I figured I could make a stripped down user object that would have just enough information so the function would work sufficiently. Here's my new code.

  function author_facet_category($uid, $name, $count = NULL) {
    parent::faceted_search_category($count);
    $this->_uid = $uid;
    // $account = user_load(array('uid' => $uid));
    // $name = $account->name;
    $account = new stdClass;
    $account->name = $name;
    $account->uid = $uid;
    $name = {name of function to be called}($account);
    $this->_name = $name;
  }
David Lesieur’s picture

Yes, this will have much less overhead. You could even wrap your account manipulation code in a if (module_exists('realname')) block, thus preserving the normal behavior for sites that don't have that module.

NancyDru’s picture

Did you try a theme('username',...)?

pianomansam’s picture

NancyDru,

Yes I did. Problem with theme('username',...) is that it creates a link to that user's page, rather than applying that facet to the search.

NancyDru’s picture

That problem will be fixed in 6.x shortly.

pianomansam’s picture

Glad to hear. Unfortunately I'm stuck in 5.x land

NancyDru’s picture

theme('username', $account, array('plain' => TRUE))

pianomansam’s picture

NancyDru,

Tried that. Still outputs <a href="/users/{username}" title="View user profile.">{user real name}</a>. Works ok because it doesn't turn the link into the user account link, but still doesn't just output the real name.

NancyDru’s picture

Did you use the current -dev?

pianomansam’s picture

Nope, this is going to be on a production server, so I try to avoid -dev versions...

NancyDru’s picture

Well, I'm waiting for some feedback on some issues and then will roll an official release; it will probably be within a week or so.

pianomansam’s picture

Thanks for all the hard work, NancyDru! I'll be sure to upgrade once the official release comes out.

AndyThornton’s picture

Version: 5.x-1.0-beta4 » 6.x-1.x-dev

Would anyone else find this useful for D6 branch? I changed my local copy but not sure if my changes are 'patch worth'.

Is Faceted Search still actively maintained? Doesn't appear to have been a release for a while ...

grasmash’s picture

I would definitely find this useful for the 6.x branch.