Sharepoint - how to customize search results:
August 28th, 2006 by Gavin Clabaugh
I’ve always been frustrated with SharePoint’s search results. Why go to all the trouble of using Metadata — especially having a document title that is different from the filename — and then not expose it in search results. Stupid.
Unfortunately, it’s not that easy to change. Fact is, if there is one failing to SPS2003, it’s the missing ability to customize the search results. There are lots of replacement engines out there, but OOTB, it should be easy to customize the search results.
So I set out to do it. Here’s how.
First lets make sure you have all the prerequisites:
1. You’ve created an SPS portal site. Let’s be clear, I am NOT talking WSS.
2. You’ve got documents in document libraries, and they have metadata of sorts — since we’re talking titles, your documents should probably have titles.
3. You’ve installed/configured all the necessary ifilters to include additional content like pdf’s.
4. Sharepoint search is configured, and is working, but the results are not to your liking.
Getting a copy of the SearchResults.DWP file
With all that done, you need to modify a copy of the SearchResults webpart. You can be brave and do the OEM copy in the 60-hive, or you can do this:
In your browser, go to the following path (substitute YOUR SPS site name where it says <yourportalsitename>) : http://<yourportalsitename>/search.aspx?mode=edit&view=shared
1. From the "Modify My Page’; select ‘Shared View’
2. From the ‘Modify Shared Page’ menu; select ‘Design This Page’
3. Your search page is now in design mode. On the Search Results web part, click the down arrow and select ‘Export…’
4. Save the file. It will create a .dwp file (this is a web part file extension). The contents are XML. You can change this file. Before you do, make a copy. You may break things. (d’oh!) I keep all my OEM copies as OEM_filename. Hence, I made a copy and called it OEM_SearchResults.dwp.
Making Changes
Now you are ready. We’re going to modify your copy of SearchResults.dwp. Here are a few changes and how to make them:
———————–
Item 1 Open search results in a new window — by default, links open in the same window. I hate this.
Action - Add line: <OpenNewWindowForMatchingItems xmlns="urn:schemas-microsoft-com:sharepoint:DataResultBase">true
</OpenNewWindowForMatchingItems>
Location Before: "<GroupByList xmlns= …" in the SearchResults.dwp file
———————–
Item 2 Change the number of returned search results — by default, SPS returns 40 items.
Action – Change #: Change "40" to whatever you want
Location <MaxMatchingItemsNumber>
—————————-
Changing the filename to title is slightly more complicated. It takes two changes:
Item 3 Change the link description from Filename to Title on the search results — by default, SPS shows the filename and not the metadata "Title." To do this we have to change both the data that is displayed, and the actual search query so that query returns the information stored in the metadata field in SharePoint. This is what (eventually) worked.
Action - replace Replace the string: urn:schemas.microsoft.com:fulltextqueryinfo:displaytitle;
With a string:: urn:schemas-microsoft-com:office:office#Title;
Location Right after the line that reads:
<ColumnURIs xmlns="urn:schemas-microsoft-com:sharepoint:DataResultBase">
Action - Add Add to the query "urn:schemas-microsoft-com:office:office#Title",
Location in the SELECT statement
The SELECT statement begins with:
<QueryTemplateSelectPart xmlns="urn:schemas-microsoft-com:sharepoint:QueryResultBase">SELECT
You can insert the URN anywhere after that tag. I recommend putting it near some of the other OFFICE tags, like below. Remember to include all the proper quotes and commas.
"urn:schemas-microsoft-com:office:office#Author",
"urn:schemas-microsoft-com:office:office#Title",
"urn:schemas.microsoft.com:fulltextqueryinfo:description
———————–
Item 4 Change the TITLE of the web part — do this so that your new web part has a different title than the OEM webpart.
Action - Alter Node: Change the "Search Results" to whatever you want, eg: <Title>Custom Search Results</Title>
Location <Title>Search Results</Title>
———————–
Saving the Changes
Save the modified .dwp file. Don’t forget to change the Title. Then follow the steps above to make sure you are in "Design Mode" and looking at the SearchResults page. Then:
- Remove/Delete the current Search Results web part. To do this, just right-click the dropdown on the part.
- Select the "Add Web Parts" from the "Modify Shared Page" menu and choose "Import" from its list of options.
- Browse for your .dwp file and import it
- Drag&Drop the new .dwp onto the page under the Advanced Search web part
- Open a new window and try a search. See what you get.
Fallout:
After making these changes, there is one negative result. "People" searches now seem to return the name of the ASPX file, and not the actual person’s name. For me this was not an issue — I just eliminated "People" from all search results. Since this is a system for managing documents (for me) and I don’t care about all the ability to fine/see people’s profiles (in fact it bugged me), I just excluded people from the search context. I’ll post that in a separate item.
Gavin Clabaugh - August 2006.
Hi Gavin,
I have a situation with a customer regarding SPS search results. The customer does not want the title of any content source to appear during a search query. This is because the title field is not edited during a file upload and cannot be made mandatory like other metadata. I can map the WSS “ows_basename” attribute to title but cannot map the other content sources such as the SPS doclibs. They want the filename to replace the title for all content. Any ideas?
Thanks,
Greg
Hi Gavin,
Can please tell me, how can we cure the fall out..
Regards,
Abbas
Has anyone of you tried to display only the title of the results items and remove all the other stuff like created by, created date etc..
Looking for information and found it at this great site…ÿ