Home RSS 2.0 ATOM 1.0  CDF  
 
CodeSegment - Carlos Segura Sanz (blog)
 
Page 1 of 1 in the csegSearch category

This is a small update of my webpart csegSearch (for SPS 2003) that solves some issues with the custom results. Now are correctly displayed and you can short this.

For more info see:

 csegSearchWebPart15.zip (12,7 KB)

Prior to update this release, you need uninstall previous versions of csegSearch.

Monday, February 12, 2007 6:48:12 PM (Hora estándar romance, UTC+01:00)   #    Comments [1]   csegSearch | SharePoint  | 

This is other sample of how I am using Ajax in my SharePoint environment (see Using Ajax to query Exchange Server Part 1 and Part 2) , now I'm using it to improve my searches in SPS.



First I have added a new page to make the searches, this new page runs under SPS context and it is stored under Layouts directory. This is very basic search page that look at the "DAV:displayname" field to locate files that contains a keyword in the name. This page use a query string to get the keyword and the results are written in HTML. (You can use other queries here).
 

csegAjaxSearch.aspx

<%@ Page language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, 
Microsoft.SharePoint,Version=11.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" 
Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePointPortal" Namespace="Microsoft.SharePoint.Portal" 
Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %> 
<%@ Import Namespace="Microsoft.SharePoint.Portal" %>
<%@ Import Namespace="Microsoft.SharePoint.Portal.Topology" %>
<%@ Import Namespace="Microsoft.SharePoint.Portal.Search" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Text" %>
 
<%
    TopologyManager topology = new TopologyManager();
    PortalSite portal = topology.PortalSites[new Uri("<USE YOUR SERVER HERE>")];
    PortalContext context = PortalApplication.GetContext(portal);
    QueryProvider qp = new QueryProvider(context.SearchApplicationName);
 
    string keyword = Request["k"];
    
    if(keyword!=null && keyword.Trim()!="")
    {
        string queryTemplate = "SELECT \"DAV:href\", " +
                               "\"DAV:displayname\", " +
                               "\"urn:schemas.microsoft.com:fulltextqueryinfo:description\", " +
                               "\"urn:schemas-microsoft-com:office:office#ows_SiteName\" " +
                               "FROM ( TABLE Portal_Content..Scope() " +
                               "UNION ALL TABLE Non_Portal_Content..Scope() ) " +
                               "WHERE CONTAINS(\"DAV:displayname\", '\"*" + 
                               keyword.Replace("'", "''").Replace("\"", "\"\"") + "*\"') ";
        Response.Write(queryTemplate);
        
        DataSet ds = qp.Execute(queryTemplate);
 
        StringBuilder sb = new StringBuilder();
    
        if(ds != null)
        {
           sb.Append("<UL>");
           foreach(DataRow dr in ds.Tables[0].Rows)
           {
              sb.AppendFormat("<LI><A href='{0}'>{1}</A><BR/>{2}<BR/>{3}<BR/></LI>",
                 SPEncode.HtmlEncode(dr["DAV:href"].ToString()),
                 SPEncode.HtmlEncode(dr["DAV:displayname"].ToString()),
                 SPEncode.HtmlEncode(dr["urn:schemas.microsoft.com:fulltextqueryinfo:description"].ToString()),
                 SPEncode.HtmlEncode(dr["urn:schemas-microsoft-com:office:office#ows_SiteName"].ToString()));
           }
           sb.Append("</UL>");
        }
        else
        {
           sb.Append("<P>No results</P>");
        }
      
        Response.Write(sb.ToString());
    }
%>   

In a new area of my SPS server I have added a Html Form webpart, that use ajax to return the results. Here is the code.


<script language="javascript">
var xmlHttpReq;
 
function initHttpRequest()
{
    try 
    {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(ex)
    {
        xmlHttpReq = null;
    }    
}
 
function sendQuery(keywords)
{
    var serverUrl = "http://YOUR SERVER/_layouts/csegAjaxSearch.aspx?k=" + keywords;
    
    initHttpRequest();
   
    if (xmlHttpReq != null)
    {
        xmlHttpReq.onreadystatechange = checkState;
        xmlHttpReq.open("GET", serverUrl, true);
        xmlHttpReq.send(null);
    }    
}
 
function checkState()
{
    // Load completed
    if (xmlHttpReq.readyState == 4)  
    {
        // Status OK
        if (xmlHttpReq.status == 200)
        {
            document.getElementById("Results").innerHTML = xmlHttpReq.responseText;
        }
        // Error
        else
        {
           document.getElementById("Results").innerHTML = "<b>There is an error in the service</b>";
        }
    }
}
</script>
 
<form name="form">
  <input name="keyword" onKeyUp="sendQuery(this.value)" style="WIDTH:500px" autocomplete="off">
  <div align="left" id="Results" style="width:100%"></div>
</form>
Friday, April 28, 2006 7:44:30 PM (Hora de verano romance, UTC+02:00)   #    Comments [8]   csegSearch | SharePoint  | 

1.- Load your search.aspx with http://server/search.aspx&Mode=Edit?PageView=Shared

2.- Enter in design mode using "Modify Shared Page" menu

3.- Select the csegSearch Webpart and put it on page

4.- Go to the original "Search Results" webpart and modify properties, at the end there is a property called ResultListID, it has a list name, remember the name.

5.- Now delete the original "Search Results"

6.- Edit the csegSearch properties and locate the ResultListID, write the same name that the old webpart.

7.- Add your extended rsults and the colorize color.

8.- Apply changes.

Try to search anything...

Thursday, October 20, 2005 8:11:51 PM (Hora de verano romance, UTC+02:00)   #    Comments [0]   csegSearch  | 

Some users have reported some small errors with csegSearch, and some doubts,

- the colorize results only runs in the first set of results (fixed
- some extended results are in incorrect site (fixed)

Try this new version (with care this is not the 1.2 final), first uninstall previous version

csegSearchWebPart12.zip (11,45 KB)

stsadm –o deletewppack –name csegSearchWebPart.cab
iisreset

Stsadm –a addwppack –filename csegSearchWebPart.cab [-globalinstall –force]
iisreset

Plase use the forums to comment bugs and the doubts in foros.ideseg.com

TIPO: To add a custom property (metadata) in the csegSearchResults

1.- In “Site Configuration” go to "Manage Properties of Crawled Content", locate the value-type properties in the urn:schemas-microsoft-com:office:office namespace, select the desired custom metadata (ows_METADATA) and check the option, "Included in the Advanced Search options", which exposes the meta property to the Sharepoint Search Service.

2.- Edit the Search.aspx with Search.aspx?Mode=Edit&PageView=Shared

3.- Export the csegSearch webpart

4.- Edit the .dwp file (add your custom metadata to the <QueryTemplateSelectPart>) This is the select part in the query

“urn:schemas-microsoft-com:office:office:ows_METADATA”

5.- Import the .dwp and put in the Search.aspx page

6.- Then in extended results put

MyMetadata; urn:schemas-microsoft-com:office:office:ows_METADATA

Wednesday, August 03, 2005 7:54:46 AM (Hora de verano romance, UTC+02:00)   #    Comments [3]   csegSearch  | 

Buff, finally csegSearch 1.1

Thanks to Henrik, Raphael, André, Klaus and Mario for your comments.

Fixed/Improvements

- Add support to display custom attributes in results view.
- Fix the query string parameters
- Fix empty Hilight color
- Hilight keywords in document title and author
- Parser optimization and autofix 

Operation

Webpart will transform the keywords into sharepoint joining  the words with the nexus AND as in google.  Internally csegSearch uses a parser engine that tries to correct the syntax of queries.

  •     Supports  AND, OR and NOT operators (also short form &,| and !)
  •     Supports  NEAR operator
  •     Supports  Wildcars and brackets
  •     Supports Special keywords (site, file, status, author)
  •     Hilights results (now client mode via javascript, support wildcards)
  •     Extend results easily (add custom)
  •     Go to folder button

Special keywords:

    They are added to the main query using AND operator. And always are considered using the nexus OR among them. Special keywords only works with simple queries.

    site, author, status, file

    Both accept wildcards ej: site:Demo*, file:*.doc

Custom properties

Show Query: If checked show the current query (debug purposes).

Show keywords: If checked show the keywords after parser it.

Extend Results: To show others attributes in your query results you need edit this property.

<Title>;<Search Attribute>,<Tile>;<Search Attribute> ...

Example: Modified;DAV:getlastmodified,Description2;urn:schemas.microsoft.com:fulltextqueryinfo


Query where part: Where part used in queries, you can modify it to use a custom where part.

Colorize color: Name of the color to hilights results (red, blue etc...) if empty not colorize.

Go to folder text: Query results show a new button under documents to go to the folder of document this is the text of button, if empty this button is not showed.

Search text: If show keywords is enabled this is the text before keywords.

Download csegSearchWebPart.zip (12,07 KB)

Wednesday, July 27, 2005 12:07:37 AM (Hora de verano romance, UTC+02:00)   #    Comments [3]   csegSearch  | 

This webpart allows to make searches GOOGLE  type in sharepoint.

In the first place I would like to thank  Mattiew Cosier since to a large extent I have been inspired by his work. And Gustavo to test the webpart in your systems.

This webpart is a subclass of the webpart included in sharepoint called SearchResults. Baically, csegSearch   transforms the keywords and  gives them the correct syntax to be used with the predicate CONTAINS of the Sharepoint searches..

Being a subclass of SearchResults we can interchange them and  continue using the adavanced searches and the management searches.


Installation

This webpart settles like a normal webpart..

Stsadm -o addwppack -filename csegSearchWebPart.cab [ -globalinstall -force ]


Once installed we need to modify the search.aspx page and to change webpart SearchResults by csegSearch (see installation video)

In the properties of csegSearch, we will change the name of the list by "sch" in order to use advanced search management (sort and group)


Operation

Webpart will transform the keywords into sharepoint joining  the words with the nexus AND as in google.  Internally csegSearch uses a parser engine that tries to correct the syntax of queries.

  •     Supports  AND, OR and NOT operators (also short form &,| and !)
  •     Supports  NEAR operator
  •     Supports  Wildcars and brackets
  •     Supports Special keywords (site and file)
  •     Hilights results.

Special keywords:

    They are added to the main query using AND operator. And always are considered using the nexus OR among them. Special keywords only works with simple queries.

    site:
    file:

    Both accept wildcards ej: site:Demo*, file:*.doc

Custom properties

Debug query: If checked show the current query.

Debug keywords: If checked show the keywords after parser it.

Query where part: Where part used in queries, you can modify it to use a custom where part.

Open links in a new window: If checked when click a result its show in a new window.

Colorize color: Name of the color to hilights results (red, blue etc...) if empty not colorize.

Go to folder text: Query results show a new button under documents to go to the folder of document this is the text of button, if empty this button is not showed.

Sample Queries

Input Keywords Result Query
red car "red" AND "car"
"red car" "red car"
red car big "red" AND "car" AND "big"
red car or big "red" AND "car" OR "big"
red (car or moto) "red" AND ("car" OR "moto")
red car not big ("red" AND "car") AND NOT "big"
red and and car "red" AND "car"
red car  or not big "red" AND "car" OR "big"
red car site:Demo* site:Test* file:doc "red" AND "car" AND (Site contains Demo* OR Site contains Test*) AND file contains doc

I wait for your commentaries and suggestions for future versions

Download csegSearch   Updated

Tuesday, July 26, 2005 7:46:56 PM (Hora de verano romance, UTC+02:00)   #    Comments [9]   csegSearch | SharePoint  | 

Page 1 of 1 in the csegSearch category

Copyright © 2008 Carlos Segura. All rights reserved.