Welcome to TechNet Blogs Sign in | Join | Help

How To: create Keywords and Best Bets for MOSS Search programmatically

Yesterday I received an interesting question: a customer had the need to import several hundred keywords and related best bets programmatically to a couple of site collections.

And for sure he did not want to do this manually using the web UI.

I found the following solution for this problem:

SPSite spsite = new SPSite("http://localhost:4007");
SearchContext searchContext = SearchContext.GetContext(spsite);
Keywords keywords = new Keywords(searchContext, new Uri("http://localhost:4007"));

// loop begin
Keyword myKeyword = keywords.AllKeywords.Create("myKeyword", DateTime.Now);
myKeyword.Synonyms.Create("mySynonym");
BestBet bestBet = myKeyword.BestBets.Create("myBestBet""my descript"new Uri("http://www.myBestBetDestination.com"));
myKeyword.Update();
// loop end

http://localhost:4007 is the site collection where the code should add the the keywords and best bets to.

Where the loop is outlined you would need to implement a method to read the values from a file or database and then add each entry as a keyword.

Published Wednesday, March 28, 2007 10:49 AM by Stefan_Gossner

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Wednesday, March 28, 2007 7:49 AM by " + title + "

# " + title + "

Thursday, April 12, 2007 11:39 AM by Matthias Glubrecht

# re: How To: create Keywords and Best Bets for MOSS Search programmatically

Hi Stefan,

thanks a lot; this post saved us half a day of trial and error, I guess :-)

Regards, Matthias

Monday, July 02, 2007 1:54 PM by Jerry K.

# re: How To: create Keywords and Best Bets for MOSS Search programmatically

Can you do the same in SPS 2003? (add keywords and best bets programatically)

Sunday, September 09, 2007 12:06 PM by hoover high school football alabama 2005 schedule

# hoover high school football alabama 2005 schedule

hoover high school football alabama 2005 schedule

Wednesday, October 17, 2007 10:46 AM by Carlos Sampaio

# Thank You Stefan

Thank you Stefan for this sample. We had over 1500 keywords, plus Synonyms on our site. This will reduce the effort from days to minutes.

Wednesday, October 31, 2007 5:22 PM by Cale Hoopes

# re: How To: create Keywords and Best Bets for MOSS Search programmatically

Stefan,

Since you can do this programmatically and it seems to bind to the SSP does this mean that you can set keywords (synonyms) and best bets at the SSP level for non-MOSS site searching? I'm curious because I have a MCMS 2002 site that we're going to crawl with MOSS and we want to know if we can configure synonyms and best bets.

Meaning, do you think I could do:

SearchContext searchContext = SearchContext.GetContext(spsite);

Keywords keywords = new Keywords(searchContext, new Uri("http://MYCMSSITE/"));

// loop begin

Keyword myKeyword = keywords.AllKeywords.Create("myKeyword", DateTime.Now);

myKeyword.Synonyms.Create("mySynonym");

BestBet bestBet = myKeyword.BestBets.Create("myBestBet", "my descript", new Uri("http://www.myBestBetDestination.com"));

myKeyword.Update();

Let me know what you think.

Cale

Thursday, November 01, 2007 7:03 AM by Stefan_Gossner

# re: How To: create Keywords and Best Bets for MOSS Search programmatically

Hi Cale,

I haven't tried it myself but I think this should also work for non portal content (e.g. MCMS sites).

Give it a try!

Cheers,

Stefan

Thursday, November 01, 2007 12:46 PM by Cale Hoopes

# re: How To: create Keywords and Best Bets for MOSS Search programmatically

Ok, I'll let you know how it goes. It sure would be interesting to find out. It's too bad there isn't an interface at the SSP level to set keywords by scope our source or something. Considering you can set authority pages at this level, it seems like it would have made sense to make the keyword interface at that level too.

Thursday, November 29, 2007 2:13 PM by Life of a Hungarian SharePoint Geek

# Creating Keywords and Best Bets for MOSS Search programmatically

You can administer keywords and best bets on the MOSS admin UI at Search keywords at Site Collection

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker