Introducing Document Link Handler for MOSS 2007 Enterprise Search
Posted
Friday, October 31, 2008 1:30 PM
by
CoreyRoth
Since, I have started working with Enterprise Search, I have received many requests looking for ways to improve what we can do with documents. The search results screen in MOSS, as flexible as it is, has always been lacking in features compared to search results of other ECM systems. Common feature requests I have seen from clients include: editing the document, viewing properties, linking to the folder or document library, linking to the site the document is in, zip and download, view version history, and more. Today I am pleased to announce a simple solution which can handle many (but not all) of these common requests.
So how do we accomplish this? I decided to build a simple ASP.NET Handler (.ashx) file to parse the URL from a document on the search results page and redirect a user to the page that he or she wanted. Links to the handler can easily be added by modifying the XSL of the CoreResultsWebPart.
The code of the handler is pretty simple. I take the URL passed via query string, split it to get the filename and the path and then I open an SPWeb object that references that site. Once I have access to an SPFolder and SPFile object for the document, I can determine URLs for the document library and folder. Take a look at the code if you are interested. It might need some optimization, but it is a good starting point.
Installation is simple. Install the included .wsp file contained in the package folder. The syntax is listed in the readme.txt file if you need it. This will copy the DocumentLink.ashx file into your layouts folder. To add the links to your search results, go to the results page of your search center and edit your CoreResultsWebPart. In the Data View Properties, click on the XSL Editor button. Replace the XSL in the window with the contents of the included SampleCoreResults.xslt file. If you have already made customizations to this file or you only want certain links, you may copy just the lines you need from the readme.txt file.
After you have changed the XSLT, apply the changes and execute a search query. If you receive an error, then your XSL is probably malformed. Open the XSL with Visual Studio if necessary to help find the error. If all goes well, you should have search results that look like the one below. Note, that these links will only show up for search results that are documents (IsDocument:1). This works together in conjunction with my post earlier this week on adding an edit document link to search results.
The binaries and source code are available at CodePlex. If you have any issues, please log them there on the Issue Tracker. If you have any idea of other kinds of links we can provide off of a document library, please leave a comment. This can also be used with the Wildcard Search web part. Hopefully this will help many others out there deliver even richer search solutions to their customers. Thanks.
Document Link Handler for MOSS 2007 Enterprise Search