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:
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.
Permalink
PingBack from http://www.virtual-generations.com/2007/03/28/sharepoint-2007-link-dump-3/
Permalink
Hi Stefan,
thanks a lot; this post saved us half a day of trial and error, I guess 🙂
Regards, Matthias
Permalink
Can you do the same in SPS 2003? (add keywords and best bets programatically)
Permalink
hoover high school football alabama 2005 schedule
Permalink
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.
Permalink
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
Permalink
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
Permalink
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.
Permalink
You can administer keywords and best bets on the MOSS admin UI at Search keywords at Site Collection
Permalink
How do you move keywords and best bets through different environments to get to production?
From what I can find out, whilst the keywords and best bets are added within a site collection they are stored in the SSP database.
The content deployment job for the site does not move the keywords to production. I’ve found some links saying how to export and import keywords but not easily move between environments with minimum effort.
Permalink
Hi Chris,
you need to follow the steps in the links you found.
Cheers,
Stefan
Permalink
OK, thanks. These are the links I found, can you recommend one over the other?
http://www.codeplex.com/searchadmin
http://www.sharepointblogs.com/mingssn/archive/2008/05/09/export-keywords-best-bet-for-sharepoint-2007.aspx
I’m assuming the codeplex solution as the latter appears in complete?
Permalink
Hi Chris,
sorry I did not try any of these personally so I cannot do a recommendation.
Cheers,
Stefan
Permalink
Hi,
I’ve setup Keywords and they seem to work fine. However I’ve added a contact to receive an alert when the keywords come up for review but the contact doesn’t get any emails or alets. I did some further investigations into this and apparently an alert should also go out to the contact when the keyword is initiall setup. Has anyone ever got this to work? I’ve tried this in all our environments but it doesn’t seem to work in any of them.
Regards,
Diran
Permalink
Hi Stefan, I created the keywords and best bets using your code – thanks – and they appeared in the site collection as expected.
However, I have a problem where they do not appear during a search. If I go into the keyword settings using the UI and just click OK without changing anything, they then appear in the search as normal.
Any ideas?
Permalink
Came across this problem myself.
It seems that you need to use DateTime.UtcNow instead of DateTime.Now to enable the Keyword immediately, i.e.
keywords.AllKeywords.Create("myKeyword", DateTime.UtcNow);
Hope this helps.
Permalink
If anyone is having issues adding multiple Synonyms for a keyword follow this article pacsharepoint.com/…/problem-adding-keywords.html
Sameer Dhoot | http://sharemypoint.in