Summary: Learn how to programmatically create search queries by using the Search Web service in Microsoft Office SharePoint Server 2007.
Applies to: Microsoft Office SharePoint Server 2007
Patrick Tisseghem, U2U
July 2007
hey Rohit,
on similar lines we have created a console application, just copy the code and paste it into the webpart page.
one more thing..
we hv created a managed property named CreatedOn that has values from the custom defined column.
share point on its own does not gives u a column named Created On so you have to create it by your own.
here goes the code snippet
using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.Search;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search;
using Microsoft.Office.Server.Search.Query;
using System.Xml;
using System.Data;
using System.Runtime.InteropServices;
namespace BusinessLayerTestCases
{
public class Program
{
static void Main(string[] args)
{
//The string containing the keyword to use in the search
//string sqlString = "SELECT Tech,Title FROM Scope() WHERE Tech = 'windows'";
string sqlString = "SELECT CreatedOn, Title FROM Scope() WHERE CreatedOn >= GETGMTDATE()";
using (SPSite site = new SPSite("http://moss:42007"))
{
FullTextSqlQuery query = new FullTextSqlQuery(site);
query.QueryText = sqlString;
query.ResultTypes = ResultType.RelevantResults;
ResultTableCollection coll = query.Execute();
if ((int)ResultType.RelevantResults != 0)
{
ResultTable tblResult = coll[ResultType.RelevantResults];
if (tblResult.TotalRows == 0)
{
Console.WriteLine("No Search Results Returned.");
}
else
{
Console.WriteLine("Search Results Returned From Object Model");
DataTable dtResults = new DataTable("tblResults");
DataSet dsResults = new DataSet("dsResults");
dsResults.Tables.Add(dtResults);
dsResults.Load(coll[ResultType.RelevantResults], LoadOption.OverwriteChanges, dtResults);
Console.WriteLine("Row count:" + dtResults.Rows.Count);
foreach (DataRow dr in dtResults.Rows)
{
Console.WriteLine("\n\n");
Console.WriteLine(dr.ItemArray[1]);
}
}
}
}
Console.ReadKey();
}
}
}
you may also refer http://msdn2.microsoft.com/en-us/library/ms559713.aspx for date related functions
Dear All,
we have created the custom search webpart for the share point but we are unable to search the content on the specified columns in the lists and library also we are unable to search on the dates of the document.
please suggest if any one have the idea about the above porblem
Thanks in anvance
[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.
