Web Part: Most Popular Searches Relevant to Me
In my latest post called Your Site’s Most Popular Content: Web Analytics Web Part, I introduced the Web Analytics web part, and went over the basic settings. In this post, I’ll show you how to take that same set of results, and personalize it so that it applies to the person currently viewing the page, using SharePoint Designer 2010. Caveat: This solution works best when you have Kerberos implemented in your environment, so you may want to skip to the end to read about that part.
There are some complexities in this solution related to SharePoint authentication, but I’ll address that at the end.
As you saw in the previous post, you can add drop-down boxes to the web analytics web part, to allow the selection of a job title or department. In this post, I’ll show you how to customize a data view web part to show these results, tailored to the person currently looking at the page. This can only be done in the enterprise version, because it uses the current user filter web part, which is not available in other versions.
- Set up your Web Analytics web part with the following settings. You can put it on any page on your site:
- The most important part here is that very last check box Enable RSS Feed. Click OK.
- This is the RSS feed info, which you will use in order to create a new data view web part. Select the (very long) URL and copy it to the clipboard.
- Open your site n SharePoint Designer, and click Data Sources on the left.
- In the ribbon, click to create a new REST Service Connection
- In the box Enter the URL to a server-side script, paste the URL you copied at step 3.
- When you click the Tab button on the keyboard, you’ll notice that the parameters all fill in at the bottom. The ones you’ll need are: pageurl, partid, usertitle, and userdept. There will be another extra one in there, and you can remove it.
- Click the General tab, and type a name for this new data source:
- Click the Login tab. FOR NOW, choose Save this username and password… and type your own username and password. This is temporary, and I’ll address more about the authentication part at the end.
- Click OK. You’ll get a notification message: The selected authentication option saves the username and password as clear text in the data connection. Other authors of this web site can access this information. Click OK.
- Create a blank web part page on the same site, and open it in SharePoint Designer. Put your cursor in a web part zone (the big blue rectangle) in the middle of the page.
- On the Insert tab in the ribbon, click the Data Source button and choose your new Web Analytics RSS source.
- In the Data Source Details pane on the right, click to select the description field. Click Insert Selected Fields as, and choose Multiple Item View.
- This looks a little messy at first. Click the little grey chevron at the top right of the big ugly text box. Click the Format as drop-down box, and change it to Label.
- Select the word description in the top row, and change it to say Popular searches by people in:
Then, click the Split button at the bottom of the screen in SPD. Look in the code portion of the split view, to find the text you just typed. Right after people in: , paste this code:
- By default, the department parameter is “All”, so that’s the text you’ll see. Save the page, and click the F12 key to open this web part page in the browser.
- In the browser, add a current user filter web part to the page. In this web part’s settings, change the value to Department and click OK.
- Create a new web part connection from the current user filter to your data view web part. On the choose connection screen, select Get Parameters From. Click Configure.
- For the Consumer field name, choose userdept. Click Finish.
- Note that if the logged in user has no value in the department field of their profile, this web part will show an error. To avoid this, go to the properties of the current user filter web part again and expand the Advanced Filter Options. Uncheck the box to Send empty if there are no values. Exit edit mode.
- In my user profile, my department is “SharePoint”, so this is what I see now in the web part:
- Alrighty. Now you can export this web part, and then go cleanly import it onto your homepage or wherever it needs to be. When you click on each of the search keywords, it takes you to a search results page, just as if you had just performed a search for that word or term.
IMPORTANT: Do not delete the original web analytics web part from step 1. You can close it or hide it, just don’t delete it, or your new data view web part will be broken.
Now, about that whole authentication thing:
At step 9, ultimately you would want to select Use Windows Authentication. That is the best, most secure way. BUT, if you do not have Kerberos implemented on your domain, for your SharePoint environment, this option will not work. Here’s an article by Spencer Harbar that will let you know more about SharePoint 2010 and Kerberos. That method that I used at step 9, where I typed in my own username and password.. it means that anyone looking at this web part will be looking at the results in the web part as if they were me. It also means that the password is being passed as clear text, which is not exactly the best security practice. You would really want to show the search results using an account that has read access to everything in SharePoint, such as the same account you use for search crawls. Don’t worry, once the site visitors click on one of the search results, the results that they are taken to will still be security trimmed and will only show items that they have access to.
To reiterate… none of this is secure at all unless you have Kerberos in place.