About the author.

Welcome to The blog of whall

Come on in and stay a while… laugh a little. Maybe even think. Read more...

Hi, This is Wayne. This is my site, my stuff, my blog, blahblahblah. The site itself is powered by WordPress and the Scary Little theme. I thought it was cool, and I still do.

I love our little set up.  We pay a consultant to come here and fix SharePoint stuff for us, and since we paid for his time, we own the resulting work.  And then *I* get to blog about it.  I figure it’s a fair trade – he does the work, I get the credit.  Isn’t that the way life is supposed to work?

By the way, if you need SharePoint help, consider engaging Catapult Systems – top notch help, let me tell you.  In particular, Matt McDermott has been a fantastic resource many times for our company.  I think his full name is Matthew, but he goes by Matt.  I keep forgetting to ask him where he keeps the excess “hew”. 

Catapult Systems Logo
Use them.  Really.

So maybe we’ll change our relationship to this: HE does the work but *I* explain it to the masses.   That’s what this entry is – a technical explanation of something we solved in SharePoint – namely, how to do something really cool with search.

First, a quick introduction.  SharePoint is a Microsoft product that gives companies a great intranet tool, collaboration platform, document search, a portal, and a ton of other great things.  I depend on it daily, as do many groups at our company.

One of the recent projects we engaged Matt for was to help us with the technical side of rebranding our intranet.  There are many things you can do out-of-the-box, but some of the ones we wanted to do weren’t so easy.  And one of the things that kept eluding me was how to get a better “Search” web part on our main home page.  We didn’t want the generic search that it includes at the top of the typical SharePoint area:

sharepoint generic search

And we didn’t want the overkill “Advanced search web part” that is on the main built-in search page:

Sharepoint Advanced Search Web Part
(click to enlarge) 

But instead, we wanted something between the two and that could fit nicely on the right side in its own Web Part Zone, plus give employees two main functions: an easy and smart Employee Lookup and a quick search of documents both in SharePoint and on the file shares throughout the company: 

Intranet Mockup with semi-advanced search web part 
(click to enlarge)

So Matt helped us out.  I’ll put the rest of the technical details in the extended entry below for those of you who want to know the solution.  And get a few laughs.  And it might cure acne, but I haven’t told the FDA about that yet.

For those of you not familiar with the Content Editor Web Part, let me do a cursory introduction.  This little gem (aka CEWP) lets you put any HTML source in a web part and stick it anywhere on the page.  Mostly this is good for putting static text, colors, or generic HTML somewhere, but it can be far more powerful.  You can use CSS, javascript, and other tools to really accomplish a ton of things.

If you want to know more about CEWP, take a look at one of many blog postings by Todd Bleeker.  Great stuff there by a very talented guy.

The first piece to tackle for this more intelligent search part is to have a Better Employee Lookup Tool or BELT for short.  That way I can tell our end users to BELT our employees.  HAHA.  Anyway, when you use the built-in SharePoint search tool to look for people, the results mix up both people and documents unless you manually pick the “People” content source, which — let’s face it, most users aren’t going to go around and customize their search parameters.  They just want to find what they’re looking for, thankyouverymuch.

So your normal search for people using the built-in search might look something like this:

typical people search results using built-in sharepoint search
(click to enlarge)

What I’ve found is that it will put a nice little star (indicating it’s a best bet) if it’s an exact match of the name of someone (or alias), but this doesn’t help much if you only know the first name.  Or how to spell the last name.  I don’t want all that clutter.  I just want to find a specific person.  Quickly.  Heaven help the poor soul who tries to search with just a first name.

So we started with the “People Finder”.   

People Finder sharepoint search

It’s a CEWP that just takes a single line as input, and people can type in a first name, last name, nickname/alias and it gives ONLY people objects in the result.  This is sooo much better.  Now when I search for just “Wayne” I only get two results, and they’re both people objects:

sharepoint people finder search results wayne

One of them is not me, so the other guy’s gotta go.  Can only have one “Wayne” at my company, you know. 

So, how’d we* do it?

Here’s a dirty little secret about SharePoint search – you can pass parameters to it via the URL.

Now, all the parameters are not documented (as far as I can tell) but you can use something like Fiddler or other development tools to reverse engineer what parameters are being sent, and then you can craft a nifty url that looks like a form post.

What does this mean?  It means you can structure a custom SQL query, pass it along to search.aspx in URL parameters instead of form values, and it all works awesomelike!  BWUAAHAHAHAHAHA!

The CEWP allows us to use javascript, remember?  With fiddler, we* found out that the “w” parameter functions like a where clause.  So we* can put all that stuff together so it looks like this:
function DoWildPeopleSearch()
{
  var url = "http://mega/Search.aspx?w=CONTAINS(%22urn:schemas-microsoft-com:sharepoint:portal:profile:AccountName%22,%20'%22__searchterm__*%22')%20OR%20CONTAINS(%22urn:schemas-microsoft-com:sharepoint:portal:profile:FirstName%22,%20'%22__searchterm__*%22')%20OR%20CONTAINS(%22urn:schemas-microsoft-com:sharepoint:portal:profile:LastName%22,%20'%22__searchterm__*%22')%20OR%20CONTAINS(%22urn:schemas-microsoft-com:sharepoint:portal:profile:PreferredName%22,%20'%22__searchterm__*%22')%20AND%20(%22DAV:contentclass%22='urn:content-class:SPSPeople')";
url = url.replace(/__searchterm__/g, document.all["txtWildPeopleFinder"].value);
window.location=url;
}

(you would replace “mega” with your portal name)

See what we’re* doing?  We’re* making a url that consists of referencing the Search.aspx and then giving it a “where” clause (aka the “w” parameter).  We* look to see if the AccountName, FirstName, LastName *or* PreferredName contains the phrase entered.  Oh, and we* also say *AND* the class has to be SPSPeople, which is the class of objects in the Profile Database.

The rest of the CEWP is visible in the exported .dwp file that I’ll make available to you all.

Wildcard People Finder Web Part

Basically you can download this and import it onto one of your SharePoint pages and try it out.   Note that you WILL need to edit it to put in your portal server’s name where “mega” is.  Just go to Modify Web Part –> View HTML Source and make your changes. 

Well, this concludes Part 1.  I’ll put the document search section in another post for Part 2.  It was a little trickier because instead of just making a where clause, we* needed to reverse engineer more of the search form so we* could put in source, document types and a date search along with keywords:

sharepoint search document piece

So in that entry I’ll likely detail how we* reverse engineered the form. 

* And by “we” I mean Matt did the work and I watched.  And ate some breakfast.  It was good (the breakfast).

And lo, the people did comment thus:

9 Comments

  1. Absurdist says:

    When I come to Austin next week, I would like to see how you have set up sharepoint from a user perspective. I am setting up our sharepoint server, and I need to get best use case examples. Would that be okay?

  2. Ching Lin says:

    Will this work for SharePoint 2007?

  3. whall says:

    Ching Lin, I’m not on Sharepoint 2007 yet so I don’t know. But one could follow the same steps should be able to be followed to derive the same result. Does MOSS use Search.aspx? I’ve heard MOSS has a better “People Search” anyway, so you might not have need for something like this.

    We plan on going MOSS Q1 next year (it’s unbudgeted at this point, but elbow grease and a Spartan determination can work wonders).

  4. Albert says:

    Hi there, Love your “Employee Search”. Can you share the code for the “document Search” as well? Tried doing it on my own, but I keep getting an error reply – “This Web Part Page has been modified since you opened it. You must open the page again.”. Many thanks.

  5. sharepointnext says:

    Hello, I was wondering if there is a way to change the layout of the advanced search webpart. Like I want the scopes to be aligned horizontally rather than vertically and may be have dropdown instead of a list of checkboxes. Thanks for any ideas.

    • whall says:

      sharpointnext – I’m sure there’s a way, but I’ve been removed from SharePoint coding for a while now and would require more time than I’m ready to commit to it. Most of it should be changable via CSS, so I’d start there.

  6. kamal says:

    can you send me the link if you have posted a blog for
    Creating a “semi-advanced search” web part for SharePoint 2003, Part 2 (document search)

    • whall says:

      Kamal —

      I’m sorry, but part 2 never got written. I stopped doing a lot of direct SharePoint coding and so never got around to it. I wish you luck, though.

Want to comment?

Hey, we all want to share our voice. And I particularly love comments, especially if you took the time to read my blog entry. I'll take the time to read your comment, I swear! But due to spammers, robots, and the fact that I want my blog to be PG rated, I need to approve the comments. This should be same day, but please don't get mad if it takes me a while to approve the comment.







Comment:


PLEASE help keep this blog family-friendly by refraining from profanity and vulgarity.


CommentLuv badge


Admin
tsk tsk

Ajax CommentLuv Enabled 336ad6ab990e8080f1c0ad1f892428a0