Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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...

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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

share|improve this answer
    
Thanks a lot bagus.Finally I got what I intended to do. –  DeathRider Feb 4 '12 at 10:24
add comment

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

share|improve this answer
    
Please don’t add just a link as answer to a question. If the link breaks, the answer you provided will not be useful for future visitors. Provide an answer of your own and use the link as reference. If needed, you can block quote the content from your link. More information is found in our help center, especially How do I write a good answer –  Robert Lindgren Jan 29 at 9:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.