Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Microsoft Content Management Server : Adding a Search Page to the MCMS Site (part 3) - Building the Microsoft SQL Full-Text Query

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
2/8/2012 3:36:25 PM
Building the Microsoft SQL Full-Text Query

SPS’s search process uses full-text indexes and queries for fast keyword lookups in order to provide timely responses to the end user. Full-text queries are very similar to regular T-SQL queries in Microsoft SQL Server, but you have additional functions, or predicates, that you can use to give your query more power. One of these predicates that is useful when searching SharePoint indexes is FREETEXT. FREETEXT takes a list of words separated by spaces, determines which words and phrases are significant, and uses that information to build an internal query to search the targeted data in an efficient manner.

First, you need to be aware of the various fields, or properties, available to you in your query. SharePoint provides a list with this information in the Site Settings administration page of your portal.

1.
Open a new instance of Internet Explorer and navigate to our portal: http://portal.tropicalgreen.net.

2.
Click on the Site Settings link in the upper right.

3.
Under the Search Settings and Indexed Content section, click on the Manage properties from crawled documents link.

For each document crawled, the Manage Properties of Crawled Content page lists all properties that SharePoint could potentially contain indexed data on. For our purposes, we’re only going to look at the two fields below, as they contain information for our search results page:

  • DAV:href

  • DAV:getlastmodified



Notice that some of the fields listed under the urn:schemas.microsoft.com:htmlinfo:metainfo group are the same fields as we added to our template META tags using the SearchMetaTagGenerator user control from the MCMS Connector.


The other things we’ll need are the name of the search scope we created, the name of the content index, and our keywords. Once we have all that information, it makes most sense to construct the MSSQLFT query in its own method for readability. We’ll call this method BuildMssqlftQuery() and pass it a string containing our search keywords and the search scope to query. Add the following method at the end of the SearchResults.aspx.cs page:

/// <summary>
/// Builds the Microsoft SQL FullText query based on the parms.
/// </summary>
/// <param name="keywords">Keywords submitted for search.</param>
/// <param name="searchScope">SPS Search scope to filter.</param>
/// <returns>String of the MSSQLFT query.</returns>
private string BuildMSsqlftQuery(string keywords, string searchScope)
{
StringBuilder mssqlftQuery = new StringBuilder();
ArrayList whereClause = new ArrayList();

#region FILTER: keywords
// list of keywords to include
if (keywords != null && keywords.Length >0)
{
// add the keyword filter, use a calculated weighted field
// just as SPS does
whereClause.Add(string.Format(" {0} {1}",
"WITH (\"DAV:contentclass\":0,"
+ "\"urn:schemas.microsoft.com:fulltextqueryinfo:description\":0,"
+ "\"urn:schemas.microsoft.com:fulltextqueryinfo:sourcegroup\":0,"
+ "\"urn:schemas.microsoft.com:fulltextqueryinfo:cataloggroup\":0,"
+ "\"urn:schemas-microsoft-com:office:office#Keywords\":1.0,"
+ "\"urn:schemas-microsoft-com:office:office#Title\":0.9,"
+ "\"DAV:displayname\":0.9,"
+ "\"urn:schemas-microsoft-com:publishing:Category\":0.8,"
+ "\"urn:schemas-microsoft-com:office:office#Subject\":0.8,"
+ "\"urn:schemas-microsoft-com:office:office#Author\":0.7,"
+ "\"urn:schemas-microsoft-com:office:office#Description\":0.5,"
+ "\"urn:schemas-microsoft-com:sharepoint:portal:profile:"
+ "PreferredName\":0.2,contents:0.1,*:0.05) "
+ "AS #WeightedProps",
"FREETEXT(#WeightedProps, '" +keywords.ToString().Trim() +"')")
);
}
#endregion

#region FILTER: sps source group
// filter source group
whereClause.Add(string.Format(" {0}",
"(\"urn:schemas.microsoft.com:fulltextqueryinfo:Sourcegroup\" = '"
+ searchScope +"')"));
#endregion

//build search query
mssqlftQuery.Append("SELECT ");
mssqlftQuery.Append("\"DAV:href\",");
mssqlftQuery.Append("\"DAV:getlastmodified\"");
mssqlftQuery.Append(" FROM Non_Portal_Content..SCOPE()");
mssqlftQuery.Append(" WHERE ");
int i=0;
foreach (string s in whereClause)
{
if (i > 0)
mssqlftQuery.Append(" AND ");
mssqlftQuery.Append(s);
i++;
}
return mssqlftQuery.ToString();
}


Notice we added a calculated field, which we used to apply certain weight to some fields. This is how SharePoint actually executes its own search. You could configure the property weighting to give more emphasis to specific properties in your query. For example, you may want to give more weight to the title of the page, or to the keywords stored in the HTML META tags, than to the contents of the page.

Now that we have this method, let’s move on to creating the MSQuery string. We’ll use this method in the construction of our MSQuery string.

Other -----------------
- Sharepoint 2007 : Managing Security - Configure Access Requests for Lists and Libraries
- Sharepoint 2007 : Managing Security - See Who Is a Member of a SharePoint Group
- Sharepoint 2007 : Managing Security - Assign Permissions on a List or Library
- InfoPath with Sharepoint 2010 : Expose Form Fields as Web Part Connection Parameters & Create a Form to Send Data to Web Parts
- Windows Server 2003 : Creating Virtual Machines (part 2) - Configuring Virtual Machines
- Windows Server 2003 : Creating Virtual Machines (part 1) - Initial Configuration of a Virtual Machine
- Windows Home Server 2011 : Sharing Videos
- Microsoft Dynamics AX 2009 : Processing Business Tasks - Creating company-specific document layout
- Microsoft Dynamics AX 2009 : Processing Business Tasks - Posting sales orders
- Active Directory Domain Services 2008 : Add a Computer to a Group
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server