In the last two part we discussed XSLT change in core search result webpart of SharePoint/Microsoft Search Server. Now some of us are facing another challenge: How to add your custom properties to the result?
Imagine the following scenario: In a bicycle factory, you have a product database table, which contains several columns of different items, for example, the model number of the bicycles, the picture link of them, the detail descriptions, the category...Everything. Now you want to make a search engine, when users search on this webpage, they will see the picture and the description of the bikes, not only boring model numbers...
Scenario III. Add custom properties to search results
Let's go over property mapping feature of MOSS/MSS. When MOSS/MSS do a crawl, it will automatically pick up every metadata by ifilters. These metadata can be anything in your documents, for example, Author field in word documents, Readers field in Lotus Notes databases, every columns in SQL/Oracle databases(through BDC)...
Yes, they are all metadata and they will be stored in the SQL database which MOSS/MSS uses. But, this is not enough to search through them. There're too many metadata, and they have too many names. When we create a Lotus Notes view in designer, we may use "DOC_Title" for the field which points to the title for our documents. But in HTML pages, title should be the strings inside <TITLE></TITLE> tag. When a end user want to search for a title, he simply doesn't care what are the difference between the two systems, he only want to use something like "title:HelloWorld" to query all things. So it's our job to manually map different types of metadata which have the same meaning to a single category. In MOSS/MSS, this category is called managed properties. Those metadata which are not mapped, are called unmanaged properties.
In the settings page of managed properties, you can create custom properties, and you can also add your newly crawled metadata(property) to existing managed properties. So you can map "DOC_Title" field of Notes databases to "Title" property to make sure they are correctly displayed in search results page.
Now we have another problem, yes, title is shown on result page by default, but how can I get other properties to be shown on it?
We need to modify core search result webpart again. This time, we have to modify XML in "Selected Columns". I can't remember the exactly name of this one for English, correct me if I'm wrong.
In this scenario, I created some custom properties like "xmltitle", "xmlcate", "xmlurl" and "xmlcont". We store lot of information in XML files. Each items in XML is a type of metadata, so I mapped them to the above four properties. Now we need to add the following before </Columns> .
Now, our search will return these four properties in XML. But they are not displayed by default, we need to modify XSLT to show them. Open XSL Editor, let's insert something after the template of select="write".
<xsl:with-param name="str" select="xmltitle" />
Do the same thing for each of the properties you want to show, and add some effect on them, bold size font, string processing... we already talked about that in Part I and II. You are smart enough to show a picture in your result by modifying XSLT, don't you?
Original XML file:
Search result displayed:
You may already noticed there's a "RANK" property in our XML selected columns. What's that?
The answer is simple, the rank of relevancy. By default, results are sorted by relevancy. These rank values determine how they would be sorted.
Here's a result table returned from query web service. You can see the higher the rank, the higher the position the item is placed. In another article we will discuss how this RANK value is calculated.
Btw, although I wrote these articles, I still hope that someone can develop a much simpler way to modify these XSLT for search result. May be a GUI based program? It's still boring to deal with XSL/XML if you are not a programmer.
That's all for today:)