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.