A minor nit: When you search on a user name, it would be nice if it used the function "contains" rather than "is equal to". So if I search on "fred", I get "freddy", "fredericka", or whatever. Sometimes its hard to know exactly how someone has entered their user name.

Also, I like having the searched User's name result linked to the User profile page. I did that by going to Views and linking the User name to their id via a token: name-> user/[nid]

Possibly a better way to do it than that, I don't know.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpotter’s picture

In the Search API Field settings for the User Index, the Username, Email, and Display Name are set to Full Text search. You might want to check the Workflow settings to be sure the ignore case and tokenizer filters are set for those fields and then reindex your content.

But I believe the Full Text search is always going to just index full words. If you want to use partials, you should be able to change the Display Name field to a simple String field in the Search API Field settings and see if that helps.

Otherwise you'll probably need to switch to a SOLR search server and then tweak the schema.xml file to index the fields exactly how you need.

jbrundle’s picture

Thanks, Mike. Will try that.

nrackleff’s picture

Could you possibly post the content of the rewrite the output of this field? I am having trouble linking the user's name to their profile page.

mpotter’s picture

Category: Bug report » Support request
Status: Active » Fixed

Open Atrium generally uses theme templates for all markup and output. The user results template is in profiles/openatrium/modules/apps/oa_search/templates/views-view-fields--search-user-results.tpl.php

nrackleff’s picture

I found that template and I am trying to override it, but having trouble. I can get the link wrapped around the username and it looks fine in the view preview, but when I view the search results page, the link does not show up. Weird. I'm sure I will get it eventually. Can we turn this into a feature request to have the username automatically linked to the user profile in the future?

mpotter’s picture

Category: Support request » Feature request

Be sure to copy your template tpl file into your own custom theme and then clear cache. And yes, we can change this to a feature request as a link makes sense.

nrackleff’s picture

FileSize
703.19 KB
340.45 KB

I have done that and am sure it is using my template. Now I am finding that I am unable to add any fields to the user search and have them show up outside of the view admin interface. For example, I add "Indexed User: User ID (User ID)" and "Indexed User: Name (Name)" to the view. They show up in the view admin interface, but not in the finished search page. When I use dsm($variables) to show available variables, the ones I added show up in in the view preview, but not on the user search page. Is there something in the preprocessing of the views that is stripping out any added variables? See attached screenshots. I have checked and made sure that permissions are such that everyone can view user profiles. I am logged in as user 1 in all of the screenshots. This is why I am having trouble linking the username in my output template.

mpotter’s picture

Put your dsm() in your actual tpl file to make sure it's getting there. OA does preprocess views but just to make each field a simple variable name, so instead of $fields['fieldname']->content you can just use $fieldname in your tpl file.

Adding fields to views will never display those fields in OA because OA is using tpl files. You need to specifically print the variables in your tpl. So it still sounds like it's not using the correct tpl.

You might want to also check the Panels Pages for your search URL and go to the Content of the page to make sure the correct view is being displayed.

nrackleff’s picture

FileSize
526.39 KB

The dsm() is in the .tpl file. That is what was rendering in the screenshot that showed the dsm. I have added my name "NANCY" to the output and it is displaying, so I am sure it's using my template. Another screenshot attached. Still can't access the name or uid fields outside of the view admin interface.
Here is the tpl file:

<?php 
dsm($variables);
?>
<div class='oa-list well oa_search_row clearfix oa-list-header'>
  <div class="oa-pull-left">NANCY <?php print $field_user_picture; ?></div>
  <h3><a href=""><?php print $field_user_display_name; ?></a></h3>
  <div><?php print $mail; ?></div>
  <div>Name: <?php print $name; ?></div>
</div>
nrackleff’s picture

FileSize
237.12 KB
mpotter’s picture

OK, I can confirm this. The $uid variable isn't available to the template even though it's in the View. It must be something weird that Search API is doing with it's view type. Haven't really worked with that before. However, in my case I notice that the full $user variable is defined, so I can use $user->uid and $user->name to get the ID and name.

This would be better anyway since then you don't need to override the view (which would be lost in an upgrade unless you use Features Override to save it). Your template will be preserved in your theme.

nrackleff’s picture

We are thinking alike. I already tried that, but $user->name writes the name of the logged in user viewing the view, not the name of the user in the search view row. :-( So, at this point, would you recommend disabling the existing user search view/panel page page and creating my own page and view and placing it at the user search URL? It's a lot of work, but I can't think of any other option.

mpotter’s picture

Ahh, hrm, yeah that makes sense. I was searching for myself, lol.

I don't think using your own panels page will do anything. I think this is somehow related to the view being a Search Results view defined by Search API and it's doing some preprocessing of it's own somewhere. But that's going to take some pretty heavy debugging.

mpotter’s picture

OK, try this. There is a $row variable from the view results. In that there is $row->_entity_properties['uid'] and $row->_entity_properties['name']. In fact, there is a $row->_entity_properties['entity object'] with the full user record.

Pretty obscure, but should hopefully work.

nrackleff’s picture

It worked! :-)

My template now looks like this:
<?php
$link = url('user/'.$row->_entity_properties['entity object']->uid);
?>
<div class='oa-list well oa_search_row clearfix oa-list-header'>
  <div class="oa-pull-left"><?php print $field_user_picture; ?></div>
  <h3><a href="<?php print $link; ?>"><?php print $field_user_display_name; ?></a></h3>
  <div><?php print $mail; ?></div>
</div>

Thank you for helping me get this working. 
jbrundle’s picture

Hmmm-my solution was awhile back and several OA installs ago, and I can't reproduce it at the moment. Will try mpotters approach if I can't get my previous one working.

mpotter’s picture

nrackleff: Thanks for the code example. I've actually incorporated that into the e422f87 commit for oa_search and will be in the final 2.30 release. In addition to linking the users name, I also linked the image.

jbrundle’s picture

Thanks Mike.

jbrundle’s picture

Just implemented nrackleff's method on my site and it works well. thanks to you both!

nrackleff’s picture

You are welcome. I'm glad to have helped.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.