Searching Custom columns in SharePoint

By Geert van der Cruijsen at January 16, 2008 22:33
Filed Under: SharePoint

The SharePoint Keywordquery and Fulltextsearch are good ways to search metadata programmatically. This option is only available for MOSS 2007 because you don’t have a server context object in WSS 3.0.


When you Create a keyword query instance the metadata properties that will be returned will only be the basic SharePoint metadata fields like name, title etc. When you want to get your own created columns in the results you’ll have to add the property names to the to the SelectProperties object from the keywordquery.

// Set result properties
kwq.SelectProperties.Add("ProductID");

To search custom SharePoint properties you’ll have to set these properties as Managed Metadata first. After you’ve done this it’s pretty easy. You can just put “propertyname:value” as QueryText and then the search will search the property “propertyname” which contain “value”. You’ll have to put quotes around the search value because otherwise the search will also show results where the value is only a part of the property value.

Below is a full example how to create a KeywordQuery in code for in example your custom webparts.

string SSP = ConfigurationManager.AppSettings["SSP"].ToString(); 
ServerContext context = ServerContext.GetContext(SSP);
KeywordQuery kwq = new KeywordQuery(context);

// Set properties for the query before executing
kwq.ResultTypes = ResultType.RelevantResults;
kwq.EnableStemming = true;
kwq.TrimDuplicates = true;

// Set result properties
kwq.SelectProperties.Add("ProductID"); 

kwq.QueryText = column + ":" + value;
// Fetch data
ResultTableCollection results = kwq.Execute();
ResultTable resultTable = results[ResultType.RelevantResults];

// Load data into a DataTable
DataTable tbl = new DataTable();
tbl.Load(resultTable, LoadOption.OverwriteChanges);

return tbl;

Hope this will help you building your own custom search webparts in MOSS 2007

Geert van der Cruijsen

Comments

7/21/2010 8:37:09 PM #

After looking around for a legitimate hotmail password hack system, I found this device. Be cautious with it however, I'm not confident terrific choice legal to use it to hack someones hotmail or yahoo account password, its only legal to use it alone from the event you neglect the password. http://www.hotmailpasswordhack.net

hotmail password hack

7/23/2010 9:50:30 PM #

http://freemanga4u2.blogspot.com Totally free COMICS, MANGA, ANIME ARTWORKS Obtain

free manga download

7/26/2010 1:53:04 AM #

SharePoint SharePoint SharePoint Hi, I was researching the web  & I discovered your web site. Keep up the superb job.

Rosette Potier

7/26/2010 1:53:11 AM #

SharePoint SharePoint SharePoint I fully consider the above remark, the internet is having a doubt growing into the most important medium of communication across the world and its due to web-sites similar to this that ideas are spreading so quickly

Rolande Dimariano

7/26/2010 6:54:43 AM #

Do you gain decent capital from this webpage or are you doing it only for fun?

Tracie Darrington

7/26/2010 6:54:56 AM #

Great site, keeping me from working

Delois Bourdages

7/27/2010 12:23:33 AM #

Positive site, where did you come up with the information with this posting? I'm pleased I found it though, ill be checking back soon to find out what other posts you have.

Melvin Gracy

7/27/2010 12:23:34 AM #

I used to be wondering if you would like to be a guest poster on my blog? and in alternate you may put one link the put up? Please reply if you get an opportunity and I will ship you my contact particulars - thanks

Emil Esenwein

7/27/2010 5:22:04 AM #

Out of the ordinary webpage, not like the other folks!

Alise Wedo

7/27/2010 5:22:05 AM #

SharePoint SharePoint SharePoint Hello, I used to be researching the web  and I revealed your web site. Keep up the excellent job.

Perry Hartwig

7/27/2010 3:04:13 PM #

I came here through a search in Google and your site gave me just the right information

google sniper warrior

Add comment



biuquote
Loading