Question

How can we perform a sharepoint 2007 search programatically?i.e. I wanna search the whole sharepoint site for a (suppose) hard coded string through coding and get the results. When I'll be running the code it will access the sharepoint search engine and show me the search results.Please help me out...

Was it helpful?

Solution

you can use SharePoint web service to do that.

Corey Roth have a tutorial about using SharePoint search web service.

MSDN also have article to use web service for enterprise search in http://msdn.microsoft.com/en-us/library/ms543175%28v=office.12%29.aspx

OTHER TIPS

you can use Query Object Model Classes to do that. FullTextSqlQuery Use this class to execute SQL syntax search queries. QueryKeywordQuery Use this class to execute Keyword syntax search queries.

SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));
KeywordQuery query = new KeywordQuery(proxy);
query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
query.QueryText = queryText;
query.ResultTypes |= ResultType.RelevantResults;
ResultTableCollection searchResults = query.Execute();
if (searchResults.Exists(ResultType.RelevantResults))
{
    ResultTable searchResult = searchResults[ResultType.RelevantResults];
    DataTable result = new DataTable();
    result.TableName = "Result";
    result.Load(searchResult, LoadOption.OverwriteChanges);
}

FullTextSqlQuery is available in two different namespaces. There is Microsoft.SharePoint.Search.Query.FullTextSqlQuery for SharePoint Foundation and there is Microsoft.Office.Server.Search.Query.FullTextSqlQuery for SharePoint Server.

using (SPSite site = new SPSite("http://localhost"))
{
  using (FullTextSqlQuery query = new FullTextSqlQuery(site))
  {

query.QueryText = "SELECT Title, FooText FROM scope() WHERE FooText = 'Foo2'";
query.ResultTypes = ResultType.RelevantResults;

ResultTableCollection queryResults = query.Execute();
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);

} }

Custom Search Solutions for SharePoint 2010 - FullTextSqlQuery

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top