Click here to Skip to main content
Click here to Skip to main content

Microsoft Content Management Server Search Controls (C#)

By , 27 Jun 2005
 

Sample Image - sample.gif

Introduction

This set of user controls gives Microsoft Content Management Server (MCMS) web sites search capability using SharePoint Portal Server (SPS) as the search engine. It uses SPS' Search web service to provide a simple key word search. A search option is provided to select specific Content Index. The search results are displayed in a customizable DataGrid.

A VB.NET version of this set of user controls is available here.

SharePoint Setup

Please reference Emmanuel Desigaud's article on how to set up SPS for search. Basically, you need to set up a Content Index and add a Content Source. Also, make sure users performing searches in your CMS site have access to the SPS Search web service.

Installation

  1. Copy SPSSearch.xml to your XML directory if you have one, or any location in your web site. If you like to include additional columns in your search results, add the additional fields to the select statement. You can also change the maximum number of search results returned, in <Count>500</Count>, if so desired.
  2. Copy user control SearchInput to your user controls directory. The default search button is a text button. If you like an image button instead, change the Visible attribute of SearchButton and SearchImageButton accordingly and update the ImageUrl of the SearchImageButton. Do not delete either button even if you are not using both.
  3. Copy user control SearchResults to your user controls directory. If you have added additional fields in SPSSearch.xml, customize SearchResult.ascx to include those fields. In SearchResults.aspx.cs, qualify namespace SPSSearch in line 18: using ProjectName.SPSSearch; with your project name.
  4. Copy QueryService.cs and SearchUtilities.cs to your class directory.
  5. Copy Search.css to your CSS directory.
  6. In your web.config, add the following keys to the appSettings:
    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" value="[Url to SPSSearch.xml]" />
        <add key="QuestechSystems.SPSSearchIndexesText" 
          value="[A comma delimited list of Content Indexes Display Name]" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="[A comma delimited list of Content Indexes]" />
    </appSettings>

    For example:

    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" 
          value="/<CMS Site Application Name>/Xml/SPSSearch.xml" />
        <add key="QuestechSystems.SPSSearchIndexesText" 
          value="All,Sub Site 1,Sub Site 2" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="All,Sub_Site_1_Content_Index,Sub_Site_2_Content_Index" />
    </appSettings>

    A drop down list for the Content Indexes specified will be added in the SearchInput user control. The "All" in SPSSearchIndexesValue is a special value that defines search to be performed on all Content Indexes defined in SPSSearchIndexesValue. If you only have one Content Index to search, add the following instead:

    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" 
          value="/<CMS Site Application Name>/Xml/SPSSearch.xml" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="Site_Content_Index" />
    </appSettings>

    No drop down list will be added for this case.

  7. Add user control SearchInput to your CMS site to where you want the search input box to show. The results page URL is specified via the SearchResultsUrl property. The search results page can be a CMS template page or a regular ASP.NET page. For example:
    <%@ Register TagPrefix="uc1" 
        TagName="SearchInput" Src="~/UserControls/SearchInput.ascx" %>
    . . . . . .
    <uc1:SearchInput id="SearchInput" 
        SearchResultsUrl="" DefaultSearchIndex="" runat="server">
    </uc1:SearchInput>

    If SearchResultsUrl is not specified, the current page will be used for the results page. If you have specified multiple Content Indexes, you can select the default Content Index to search using the DefaultSearchIndex property. Customize SearchInput.ascx to change the layout of the search input elements.

  8. Add user control SearchResult to your search results page. The control has two properties you can set:
    • DefaultPageSize: The number of search results per page. Default is 10.
    • FilterRights: [true|false]. By default, the search results will filter out any CMS page that you don't have access to see. If your search results do not contain any authorized content and/or if you would like to improve performance, set it to false. Use it with caution though.
  9. Include Search.css to all pages that reference the search controls.
  10. Include all new files to your CMS project. Rebuild your site in VS.NET.

Notes

  1. If SearchResults encounters any errors, it will mask the errors and return "No pages were found". To see the actual errors, add querystring "debug=true" to the search results page and reload the page.
  2. The search controls run in CMS Unpublished mode. The links returned in the search results are all published links, however.

History

  • V1.0 - 2004.07.26 - Base.
  • V1.1 - 2004.08.20 - Enabled search for meta Keywords and Description.
  • V1.2 - 2005.02.05 - Added option to search multiple Content Indexes.
  • V1.3 - 2005.02.13 - Added configurable SPS Search Web Service URL in web.config to facilitate deployment. (Please note: all Web.Config App Settings key names are now qualified with namespace.)
  • V1.4 - 2005.06.25 - Allows exact phrase search.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Stephen Huen
Web Developer Questech Systems
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralSharepoint portalmemberBrave_Gass4 Oct '07 - 21:41 
Where to write code in sharepoint designer?
Where should I add server side code(code behind C# code) on the page in sharepoint designer(MOSS 2007)





 
Thanks
Prakash
GeneralUserHasRightToBrowse syntaxmemberViracboy28 Jun '06 - 12:00 
I am using your code
CmsHttpContext.Current.UserHasRightToBrowse(resultRow("DAV%3ahref").ToString())
to filter postings returned by the search query. It always returns true when in fact the user has no right to browse this channel/posting.
 
I wonder if it has something to do with my navigation permission set-up. The
posting in question has this generic url:
https://company/dep1/sec1/area1/special/virtual
 
The special channel is restricted only to a particular group and so is the virtual channel, but the channels above special are accessible to all subscribers.
 
What shall I do to fix this? Thanks.

GeneralDefault web.config settingsmemberJames Coleman26 Apr '06 - 11:42 
Could someone tell me what my web.config would look like if I just used SearchSetup.exe cmd line to create my search. "CMSChannels" as my index doesn't return any results, but the MS search control on my site does, so I must be doing something wrong.
 
Thanks
~James
jcoleman@agency.com
 
___________________________
J A M E S C O L E M A N
Practice Director, Microsoft
AGENCY.COM
jcoleman@agency.com
http://www.agency.com
GeneralRe: Default web.config settingsmemberStephen Huen30 Apr '06 - 17:41 
Please check http://<sps-server>/_layouts/1033/ListIndexes.aspx for your list of content indexes.
GeneralThe Local Security Authority cannot be contactedmemberJeff Tsang18 Oct '05 - 11:27 
Hi Stephen,
 
I'm getting "The Local Security Authority cannot be contacted" every time when I try to do a search. Would you be able to shed some light? My SP server is in a VM environment, not sure if that makes any difference.
 
Thanks,
Jeff
GeneralRe: The Local Security Authority cannot be contactedmemberStephen Huen18 Oct '05 - 13:58 
>> Would you be able to shed some light? >>
 
Not really, I am afraid. It does look like it has something to do with the VM.
GeneralInternal Server Errormemberrush2@comcast.net14 Oct '05 - 10:05 
Stephen,
 
I was hoping you had some insight into this issue. I seem to pre-authenticate just fine, but get an Internal Server Error from this line from the queryservice.cs ->
 
object[] results = this.Invoke("QueryEx", new object[] {queryXml});
 
Everything looks correct, but I can't find out what the problem is. Any ideas? I haven't modified the query btw.
GeneralRe: Internal Server Errormemberrush2@comcast.net14 Oct '05 - 10:29 
btw both the CMS & SPS are running on different VPCs.
 
Here's the stack:
 
[SoapException: Server was unable to process request. --> Internal server error]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
www.wellmont.org.Classes.QueryService.QueryEx(String queryXml) in c:\inetpub\wwwroot\www.wellmont.org\classes\queryservice.cs:113
www.wellmont.org.controls.SearchResults.GetResultTable(QueryService queryWS) in c:\inetpub\wwwroot\www.wellmont.org\controls\searchresults.ascx.cs:310
www.wellmont.org.controls.SearchResults.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\www.wellmont.org\controls\searchresults.ascx.cs:187
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

GeneralRe: Internal Server ErrormemberStephen Huen18 Oct '05 - 14:23 
This usually means the query's syntax is incorrect. In SearchResults.ascx.cs:
 
string queryXML = String.Format(searchXml.InnerXml.ToString(), GetSearchSource(searchIndex), searchTerms);
DataSet resultData = queryWS.QueryEx(queryXML);
 
try setting an break point to find out what the value of queryXML is.
QuestionRe: Internal Server ErrormemberJames Coleman17 Apr '06 - 11:07 
I am getting the same error. I don't know exactly what to look for in the query's syntax that could be incorrect. This is the queryXML (within the Watch window because xml didn't paste too well in this forum - so I am leaving the escape characters) for when I typed in 'Featured'. Any help would be greatly appreciated.
 
queryXML "<Format>urn:Microsoft.Search.Response.Document.Document</Format><![CDATA[SELECT \"DAV:href\",\r\n\t\t\t\t\"urn:schemas.microsoft.com:fulltextqueryinfo:displaytitle\",\r\n\t\t\t\t\"urn:schemas.microsoft.com:fulltextqueryinfo:description\"\r\n\t\t\t\tFROM All..Scope()\r\n\t\t\t\tWHERE\r\n\t\t\t\tWITH (\r\n\t\t\t\t\"DAV:contentclass\"Blush | :O ,\r\n\t\t\t\t\"urn:schemas.microsoft.com:fulltextqueryinfo:description\"Blush | :O ,\r\n\t\t\t\t\"urn:schemas.microsoft.com:fulltextqueryinfo:sourcegroup\"Blush | :O ,\r\n\t\t\t\t\"urn:schemas.microsoft.com:fulltextqueryinfo:cataloggroup\"Blush | :O ,\r\n\t\t\t\t\"urn:schemas-microsoft-com:office:office#Keywords\":1.0,\r\n\t\t\t\t\"urn:schemas-microsoft-com:office:office#Title\"Blush | :O .9,\r\n\t\t\t\t\"DAV:displayname\"Blush | :O .9,\r\n\t\t\t\t\"urn:schemas-microsoft-com:publishing:Category\"Blush | :O .8,\r\n\t\t\t\t\"urn:schemas-microsoft-com:office:office#Subject\"Blush | :O .8,\r\n\t\t\t\t\"urn:schemas-microsoft-com:office:office#Author\"Blush | :O .7,\r\n\t\t\t\t\"urn:schemas-microsoft-com:office:office#Description\"Blush | :O .5,\r\n\t\t\t\t\"urn:schemas-microsoft-com:sharepoint:portal:profile:PreferredName\"Blush | :O .2,\r\n\t\t\t\tcontentsBlush | :O .1,\r\n\t\t\t\t*Blush | :O .05) AS #WeightedProps\r\n\t\t\t\tFREETEXT(#WeightedProps, 'Featured')\r\n\t\t\t\tORDER BY \"urn:schemas.microsoft.com:fulltextqueryinfo:rank\" DESC ]]>150" string
 


 
___________________________
J A M E S    C O L E M A N
Practice Director, Microsoft
AGENCY.COM
jcoleman@agency.com
http://www.agency.com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 27 Jun 2005
Article Copyright 2004 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid