$node->name is the value stored in the users table and what people use to log into their Drupal site. Some sites however choose to have a different name for their user (e.g. by using the realname module), in that case $node->name becomes irrelevant for searches, and format_username() is what the end user expects to hit with keyword search or author sorting.

Comments

scor’s picture

Status: Active » Needs review
StatusFileSize
new664 bytes
scor’s picture

and note that with this format_username value stored in solr, it might become possible to save a call to theme('username') while rendering search results.

pwolanin’s picture

Status: Needs review » Needs work

Hmm, so $user->name is a unique string, possibly suitable for multi-site faceting, etc.

I'd almost rather add an additional field for the formatted username. I'm also not sure exactly how this would be implemented for a 6.x-3.x backport.

jpmckinney’s picture

I prefer having an additional field. Calling theme('username') means the themed username will never be stale. (If a user does something to cause their themed name to change, or the themer changes the theme, all format_username's will be stale).

scor’s picture

Status: Needs work » Needs review
StatusFileSize
new750 bytes

added an additional field for the formatted username.

jpmckinney’s picture

Status: Needs review » Needs work

Why is there:

+    $document->uid = $node->uid;

We already have that in $document->is_uid.

scor’s picture

to align with the usual variables contained in a user account object (some modules altering the username might expect to find the 'uid' in the object). Would cloning $document into an $account object and adding the ->uid value in it make more sense?

jpmckinney’s picture

Aha. I think creating a fake $account object from scratch is best, like:

$account = (object) array('uid' => $node->uid, 'name' => $node->name);
pwolanin’s picture

I agree with James - we don't support a 'uid' field in the schema, use the 'is_uid' that's already indexed.

We already have fixed code to copy fields if needed, like:

function apachesolr_search_node_result($doc, &$result, &$extra) {
  $doc->uid = $doc->is_uid;
  $result += array(
    'type' => node_type_get_name($doc->bundle),
    'user' => theme('username', array('account' => $doc)),
    'date' => isset($doc->changed) ? $doc->changed : 0,
    'node' => $doc,
    'uid' => $doc->is_uid,
  );

  if (isset($doc->is_comment_count)) {
    $extra['comments'] = format_plural($doc->is_comment_count, '1 comment', '@count comments');
  }
}
scor’s picture

Title: Index format_username($account) rather than plain $node->name » Index format_username($account)
Status: Needs work » Needs review
StatusFileSize
new791 bytes

now with fake $account object.

nick_vh’s picture

Status: Needs review » Reviewed & tested by the community

Looking good, tested and appears to be working well.

scor’s picture

Status: Reviewed & tested by the community » Postponed

I'm still carrying this functionality in my custom solr helper module.

Let's get #966796: Separate indexer for multiple entity types committed first since it's rather a beast compared to this issue. I will reroll once the multiple entity indexing has been committed.

nick_vh’s picture

StatusFileSize
new834 bytes

New one, bit more readable

nick_vh’s picture

Status: Postponed » Fixed

Committed

nick_vh’s picture

Status: Fixed » Closed (fixed)
nick_vh’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
StatusFileSize
new1.47 KB
dwightaspinwall’s picture

Status: Closed (fixed) » Active

I'm not seeing the patch in #17 in 6.x-3.x-dev. Could it have been inadvertently dropped in a D7 backport?

scor’s picture

Status: Active » Needs review

That's normal, @Nick_vh didn't claim to have committed this to 6.x-3.x, he only upload a patch at #17. Now that you've reopened the issue he will hopefully get to it.

Status: Needs review » Needs work

The last submitted patch, 1161608-17.patch, failed testing.

dwightaspinwall’s picture

@scor, understood, but CHANGELOG.txt in 6.x-3.x-dev shows the feature as added FWIW.

nick_vh’s picture

Status: Needs work » Closed (fixed)

In 6.x-3.x it is added as such :

// Index formatted username so it can be searched and sorted on.
  $account = (object) array('uid' => $node->uid, 'name' => $node->name);

  $username = check_plain($account->name);

  $document->ss_name_formatted = $username;

Format_username does not exist in 6.x afaik so closing again