SharePoint 2007 search - custom keyword search

Chris O'Brien - MVP
  • SharePoint 2007 search - custom keyword search Chris O'Brien - MVP

    I'm writing some code against the search API in SharePoint 2007, and am seeing some interesting behaviour. I'm using the KeywordQuery 'model' rather than FullTextSqlQuery, since this matches the advanced search form our client wants.

    I'm using the following code to execute the search - this builds a keyword search query in the same format as the OOTB web parts:

            ResultTableCollection resultTables = null;
    
            using (KeywordQuery keywordQuery = new KeywordQuery(SPContext.Current.Site))
            {
                string fullQuery = string.Empty;
    
                // TODO: refactor..
                string allWords = HttpUtility.UrlDecode(queryString[AllWordsQsParam]);
                string exactWords = HttpUtility.UrlDecode(queryString[ExactPhraseParam]);
                string excludeWords = HttpUtility.UrlDecode(queryString[NoneWordsQsParam]);
                string anyWords = HttpUtility.UrlDecode(queryString[AnyWordsQsParam]);
    
                if (!string.IsNullOrEmpty(allWords))
                {
                    fullQuery += getFormattedTermString(' ', '+', allWords);
                }
                if (!string.IsNullOrEmpty(exactWords))
                {
                    fullQuery += exactWords;
                }
                if (!string.IsNullOrEmpty(anyWords))
                {
                    fullQuery += anyWords;
                }
                if (!string.IsNullOrEmpty(excludeWords))
                {
                    fullQuery += getFormattedTermString(' ', '-', excludeWords);
                }
    
                keywordQuery.QueryText = fullQuery;
                keywordQuery.ResultTypes = ResultType.RelevantResults;
    
                resultTables = keywordQuery.Execute();
            }
    

    After this, I load into a DataTable and eventually get XML to transform. Currently I'm using the default XSL from the CoreResultsWebPart, but I'm finding the produced XML is not what this XSL is expecting:

    • element names are not all lowercase (not too difficult to amend the XSL to match up, but curious)
    • the hit highlighting properties are in a different format, possibly due to an encoding issue somewhere. As an example, HitHighlightingSummary does not contain child XML elements as it does in an OOTB search - instead, there is one text node as a child which effectively contains an 'InnerXml' of the child elements. Effectively all of the angled brackets have been encoded e.g. '<' to 'ampersand lt semi-colon' (had to write it that way due to SO encoding, but you hopefully get my drift).

    This latter means the xsl:apply-templates for the hit highlighting stuff is not able to process the XML, since it's really a string rather than a tree.

    I've verified that it isn't the later steps of loading into a DataTable/obtaining XML/transforming which is the issue - it's coming back from the search API like this.

    Any ideas why?? I'm not immediately seeing something I'm doing wrong with the KeywordQuery class, but could it be something there?

  • Regarding your second point, you are saying that the HitHighlightingSummary column in the ResultTable you get from SharePoint contains HtmlEncoded values? Perhaps this is by design, and it's your responsibility to HtmlDecode these values when you turn it into XML?

Tags
2007 search
Related questions and answers
  • as far as I can see. The result is: xsum //Distance = 2. Update 3: This works. Had some problems with the selection of the start node but that should be fixed now. &lt;xsl:decimal-format name="da-DK...I have this (an attempt to solve the task): &lt;xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes...:internal"> &lt;xsl:output method="html" indent="no"/> &lt;xsl:decimal-format NaN=""/> &lt;xsl:template match="/"> &lt;xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row

  • I'm have some trouble using the GetList web service. It does work sometimes but not at the start of the day!?! Here is my code: public static void ListSurveys(string serverName...); System.Console.WriteLine(meta.Title); } } } As you can see, I fetch all the lists using GetListCollection and then, if it is a survey, I try to get the List information using GetList. I use the List GUID as the list name. An exception is thrown. The SOAP body is shown below. &lt;?xml version="1.0" encoding="utf-8"?> &lt;soap:Envelope xmlns:soap="http

  • I am working on MOSS 2007 and trying to order the results returned by the people search alphabetically by name across all pages. Currently the results are sorted alphabetically on each page rather than across all pages. I have read the way to order the results is by passing parameters to the search via the URL query string rather than by the XSL. I have tried passing the following to the URL by using this page as a reference: k=Department%3A%22Legal%22&start1=52&v1=LastName But the results are still sorted by last name on each page rather than across all pages. This looks

  • Hello I really need help with this... , I am using Sharepoint 2007. I have the 'collect data from user' action in a workflow - which generates a custom form within the workflow folder. The form uses a DataFormWebPart which contains xsl stylesheet. It has a 'Complete Task' button as below: &lt;td>&lt;input type="button" name="btnMarkSubmited" value="Complete Task" onclick="javascript: {ddwrt...://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> &lt;xsl:output method="html" indent

  • where I'm programmatically trying to add it using the "Upload Web Part" feature. This is the code I'm using to add the web part: function addWebPart(serverRelativeUrl) { //var webPartXml = "&lt...()); } UPDATE: Based on feedback from Wictor, I tried the following: &lt;?xml version="1.0" encoding="utf-8"?> &lt;webParts> &lt;webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> &lt...I'm trying to add a custom web part (that is one I have written myself) using the new Javascipt OM available with SharePoint 2010. My solution is also running within the Sandbox. I have it working

  • , the only Neat way I can see through it is some sort of "Configuration" page, which then does it via the Web Services. But this is a pain, with the user having "Activate" the feature and then "Activate" again on my configuration page. Anyway, it may just be that I'm missing something obvious. Been a while between XML fiddling on SharePoint for me, and this is my first Sandbox solution. Really hope someone else has cracked this nut. &lt;?xml version="1.0" encoding="utf-8"?> &lt;Elements xmlns="http://schemas.microsoft.com/sharepoint/"> &lt;Module Name="Pages"> &lt;File Path="" Url

  • I can create a CQWP for the Announcement content type, but when I export the .webpart and add &lt;property name="CommonViewFields" type="string">Expires,Date;Body,text</property> In my ItemStyles.xsl I have added this to show all the returned fields &lt;xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle"> &lt;xsl:for-each select="@*"> &lt;br /> Name: &lt;xsl:value-of select="name()" /> &lt;br />Value:&lt;xsl:value-of select="." disable-output-escaping="yes"/> &lt;/xsl:for-each> &lt;/xsl:template>

  • I am trying to connect from BCS directly to Oracle, but there is an error: Keyword not supported: 'connect timeout'. I think that the connection string formed for Oracle is in an incorrect format for the method: protected virtual string CreateConnectionString(INamedPropertyDictionary lobSystemInstanceProperties){} Type: Microsoft.SharePoint.BusinessData.SystemSpecific.Db.DbConnectionManager Assembly: Microsoft.SharePoint, Version=14.0.0.0. Has anyone encountered a similar problem? Are there any solutions?

  • I am using Microsoft Search Server 2008 (based on SharePoint Server 2007) + C# + .Net 3.5 + VSTS 2008 + ASP.Net to develop a web application which invokes Search Server 2008 Web Services when a button in the html page is pressed. I am using the following code to query content from Microsoft Search Server 2008. My question is how to display the search results from the DataSet retrieved? I did not find a very good sample from Google. protected void Button1_Click(object sender, EventArgs e) { //The string containing the keyword to use in the search string keywordString

Data information