Answered by:
list of departments

Question
-
Hi --
What would be the best way to list all distinct departments from user profiles? I was trying to find a wildcard search for departments but I did not have success, so I was thinking in create a auto-complete field to help in the department search, and integrate with the people search.
thanks
Alex.Thursday, September 24, 2009 2:08 AM
Answers
-
Hi Alex,
SP Raj is referring to performing a search using the API. For example:
StringBuilder queryText = new StringBuilder();
queryText.Append("SELECT Department");
queryText.Append("FROM SCOPE() ");
queryText.Append("WHERE \"scope\" = 'People' ");
// add a "AND fieldname = 'vaue'" to the querytext
Microsoft.Office.Server.Search.Query.ResultTableCollection results = query.Execute();
Microsoft.Office.Server.Search.Query.FullTextSqlQuery query = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(SPContext.Current.Site);
query.QueryText = queryText.ToString();
query.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
query.RowLimit = 5000;
Also make sure you have performed a full crawl and the user profiles are available in the standard people search.
This doesn't return a distinct record set, use this with the ReturnDistinct method in this article http://blog.robgarrett.com/2009/09/23/pre-search-facets-in-moss-2007/
Hope this helps
Dave
My SharePoint Blog - http://www.davehunter.co.uk/blog- Proposed as answer by Dave Hunter Wednesday, September 30, 2009 11:08 AM
- Marked as answer by Chengyi Wu Friday, October 2, 2009 2:33 AM
Thursday, September 24, 2009 8:50 AM -
LINQ Query suggested by Aaron would be better http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/64927d06-9fe5-4330-bcfc-8ce68b9e588a
My SharePoint Blog - http://www.davehunter.co.uk/blog- Marked as answer by Chengyi Wu Friday, October 2, 2009 2:33 AM
Wednesday, September 30, 2009 11:11 AM
All replies
-
Thursday, September 24, 2009 5:50 AM
-
Hi Alex,
SP Raj is referring to performing a search using the API. For example:
StringBuilder queryText = new StringBuilder();
queryText.Append("SELECT Department");
queryText.Append("FROM SCOPE() ");
queryText.Append("WHERE \"scope\" = 'People' ");
// add a "AND fieldname = 'vaue'" to the querytext
Microsoft.Office.Server.Search.Query.ResultTableCollection results = query.Execute();
Microsoft.Office.Server.Search.Query.FullTextSqlQuery query = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(SPContext.Current.Site);
query.QueryText = queryText.ToString();
query.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
query.RowLimit = 5000;
Also make sure you have performed a full crawl and the user profiles are available in the standard people search.
This doesn't return a distinct record set, use this with the ReturnDistinct method in this article http://blog.robgarrett.com/2009/09/23/pre-search-facets-in-moss-2007/
Hope this helps
Dave
My SharePoint Blog - http://www.davehunter.co.uk/blog- Proposed as answer by Dave Hunter Wednesday, September 30, 2009 11:08 AM
- Marked as answer by Chengyi Wu Friday, October 2, 2009 2:33 AM
Thursday, September 24, 2009 8:50 AM -
LINQ Query suggested by Aaron would be better http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/64927d06-9fe5-4330-bcfc-8ce68b9e588a
My SharePoint Blog - http://www.davehunter.co.uk/blog- Marked as answer by Chengyi Wu Friday, October 2, 2009 2:33 AM
Wednesday, September 30, 2009 11:11 AM