MOSS2007 – Using the Search API (Part 2)
转自:http://www.thesug.org/Blogs/helotslim/archive/2009/5/6/MOSS2007–UsingtheSearchAPI(Part2).aspx
In my last post we looked at some basic Search API code using our forms application. As a response to this Daniel from "Zevenseas" he has a tool, if you haven't already got it, go get it from here: http://mosssearchcoder.codeplex.com
This application will allow you to create all the Search Queries and even generates the C# code that you may need. Recommend you go get it!!
In this post I wanted to look at changing the code we wrote last time and turn it into a web part. So let's begin. Create a new Web Part project and call it the following:
The code will be the same for our search etc and also our "PublishingRollupImage" CAML Query. The only change is that instead of passing the URL to perform the search query, we use the following:
The code from this point down is more of less the same.
In the previous post we had a checkbox that enabled the "PublishingRollupImage" check. In the web part I wanted to change this to check if this field had been added to the list of fields and then only run of it was.
The user interface for this is simply a set of labels and boxes that are rendered using the following syntax for each item.
Now we have our web part built it should render as the following (Ignore the layout etc, just showing functionality):
When we run this without the "PublishingRollupImage" field it shows as below:
When we run this with the "PublishingRollupImage" field it shows as below:
As you can see this is now functioning as in the previous post. In the next post we will look at changing this and using the Search Core Results Web Part and using our custom CAML code we created previously. J
This posting is provided "AS IS" with no warranties, and confers no rights.
浙公网安备 33010602011771号