Wednesday, 9 September 2009

Problem adding Keywords and Best Bets programmatically in MOSS 2007

I was writing a small Windows application for a customer to create keywords and best bets using a CSV file and experienced a weird problem. I used the code published here by Stefan Goßner as a starting point, which successfully added the keywords to the Manage Keywords UI in Site Collection Administration, but when I tried to search on one of the keywords, no best bets were shown in the search results.

The format of the CSV file was, as follows:

Keyword name, Synonyms (semi-colon delimited), Best bet URL

For example: Acme Primary School, Acme;Acme School;Acme Primary, http://www.acme.com

The code I used to create the keywords was:

keywords.AllKeywords.Create(keywordTerm, DateTime.Today.AddHours(-1));
keywords.AllKeywords[keywordTerm].Synonyms.Create(objSynonyms);
keywords.AllKeywords[keywordTerm].BestBets.Create(objBestBet.ToString() + " Profile", "Full school profile for " + objBestBet.ToString(), new Uri(objUrl.ToString()));
keywords.AllKeywords[keywordTerm].Update();

I then found that if I clicked on one of these keywords in the Manage Keywords UI and clicked OK without changing anything, the search for that keyword worked. I eventually discovered that SharePoint didn’t like adding the semi-colon delimited synonyms as a single string and that they needed to be created separately. Therefore, I changed the code to below, using the semi-colons to split the string up into an array of separate synonyms, which worked:

keywords.AllKeywords.Create(keywordTerm, DateTime.Today.AddHours(-1));
//Create synonyms from semi-colon separated array
string[] synonymArray = objSynonyms.ToString().Split(new char[] { ';' });
foreach (string synonym in synonymArray)
{
     keywords.AllKeywords[keywordTerm].Synonyms.Create(synonym);
}
keywords.AllKeywords[keywordTerm].BestBets.Create(objBestBet.ToString() + " Profile", "Full school profile for " + objBestBet.ToString(), new Uri(objUrl.ToString()));
keywords.AllKeywords[keywordTerm].Update();

16 comments:

  1. Hi Phil,

    I too face the same problem.
    I have added only Keyword, definition & best bet but still i am not getting keyword in search.
    then if i simply edit the keyword in UI & then clickin OK, now keyword is displayed in serach.

    Kindly let me know how to solve this issue bcoz u have mentioned that u have seperated Synonyms by semicolon";" but i havn't added

    ReplyDelete
  2. Hi,

    Have you updated your keywords after the changes (see last line in my code above)? The problem I was having was with synonyms, so if you haven't got any then it is probably a different issue to the one I had.

    Phil

    ReplyDelete
  3. Can you post a "step-by-step" for doing this with a CSV for SharePoint / FAST 2010? I'm starting to loose all my hair on this ;) Any help would be greatly appreciated.

    Thanks!

    ReplyDelete
  4. Hi Bryan - I have posted a reply to this on my PowerShell blog at http://get-spscripts.com/2010/10/create-search-keywords-and-best-bets.html

    Phil

    ReplyDelete
  5. https://www.facebook.com/bantalsilikongrosir
    http://bantalsilikon01.blogspot.com/2014/12/a.html
    http://jualsangkarpleci.blogspot.com/2014/12/a.html
    http://kopiluwakliar01.blogspot.com/2014/12/a.html
    http://vvty.in/uncategorized/marinir-seo/

    http://marinirseo.blogspot.com/2014/12/a.html
    http://marinir-seo.blogspot.com/2014/12/a.html
    http://bumbu-pecel-malang.blogspot.com/2014/12/a.html
    http://distro-seo.blogspot.com/2014/12/a.html
    http://restoran-seo.blogspot.com/2014/12/a.html
    http://bantalmalangmurah.blogspot.com/2014/12/a.html
    http://distrobantal.blogspot.com/2014/12/a.html
    http://kesethandukmalang.blogspot.com/2014/12/a.html


    http://tasya.marinirseo.web.id/?p=4http://jeannet.marinirseo.web.id/?p=4http://anne.marinirseo.web.id/?p=4http://jelita.marinirseo.web.id/?p=4http://ruth.marinirseo.web.id/?p=4http://caca.marinirseo.web.id/?p=4http://brenda.marinirseo.web.id/?p=1 || http://tasya1.marinirseo.web.id/?p=4http://jeannet1.marinirseo.web.id/?p=4http://anne1.marinirseo.web.id/?p=4http://jelita1.marinirseo.web.id/?p=4http://ruth1.marinirseo.web.id/?p=4http://caca1.marinirseo.web.id/?p=5http://brenda1.marinirseo.web.id/?p=4 || http://tasya2.marinirseo.web.id/?p=5http://jeannet2.marinirseo.web.id/?p=4http://anne2.marinirseo.web.id/?p=4http://jelita2.marinirseo.web.id/?p=4http://ruth2.marinirseo.web.id/?p=4http://caca2.marinirseo.web.id/?p=4http://brenda2.marinirseo.web.id/?p=4http://brenda3.marinirseo.web.id/?p=4http://tasya3.marinirseo.web.id/dua/http://jeannet3.marinirseo.web.id/?p=4http://anne3.marinirseo.web.id/?p=4http://jelita3.marinirseo.web.id/?p=4http://ruth3.marinirseo.web.id/?p=4http://caca3.marinirseo.web.id/?p=4 || nhttp://brenda4.marinirseo.web.id/?p=4http://tasya4.marinirseo.web.id/?p=4http://jeannet4.marinirseo.web.id/?p=4http://anne4.marinirseo.web.id/?p=4http://jelita4.marinirseo.web.id/?p=5http://ruth4.marinirseo.web.id/?p=4http://caca4.marinirseo.web.id/?p=4 || http://tasya5.marinirseo.web.id/?p=4http://anne5.marinirseo.web.id/?p=4http://jelita5.marinirseo.web.id/?p=4http://ruth5.marinirseo.web.id/?p=4http://caca5.marinirseo.web.id/?p=4http://synganne.marinirseo.web.id/?p=4
    http://tasya.marinirseo.web.id/?p=4http://jeannet.marinirseo.web.id/?p=4http://anne.marinirseo.web.id/?p=4http://jelita.marinirseo.web.id/?p=4http://ruth.marinirseo.web.id/?p=4http://caca.marinirseo.web.id/?p=4http://brenda.marinirseo.web.id/?p=1 || http://tasya1.marinirseo.web.id/?p=4http://jeannet1.marinirseo.web.id/?p=4http://anne1.marinirseo.web.id/?p=4http://jelita1.marinirseo.web.id/?p=4http://ruth1.marinirseo.web.id/?p=4http://caca1.marinirseo.web.id/?p=5http://brenda1.marinirseo.web.id/?p=4 || http://tasya2.marinirseo.web.id/?p=5http://jeannet2.marinirseo.web.id/?p=4http://anne2.marinirseo.web.id/?p=4http://jelita2.marinirseo.web.id/?p=4http://ruth2.marinirseo.web.id/?p=4http://caca2.marinirseo.web.id/?p=4http://brenda2.marinirseo.web.id/?p=4http://brenda3.marinirseo.web.id/?p=4http://tasya3.marinirseo.web.id/dua/http://jeannet3.marinirseo.web.id/?p=4http://anne3.marinirseo.web.id/?p=4http://jelita3.marinirseo.web.id/?p=4http://ruth3.marinirseo.web.id/?p=4http://caca3.marinirseo.web.id/?p=4 || nhttp://brenda4.marinirseo.web.id/?p=4http://tasya4.marinirseo.web.id/?p=4http://jeannet4.marinirseo.web.id/?p=4http://anne4.marinirseo.web.id/?p=4http://jelita4.marinirseo.web.id/?p=5http://ruth4.marinirseo.web.id/?p=4http://caca4.marinirseo.web.id/?p=4 || http://tasya5.marinirseo.web.id/?p=4http://anne5.marinirseo.web.id/?p=4http://jelita5.marinirseo.web.id/?p=4http://ruth5.marinirseo.web.id/?p=4http://caca5.marinirseo.web.id/?p=4http://synganne.marinirseo.web.id/?p=4

    ReplyDelete
  6. If you have a history of illness that is difficult to recover, maybe our next article will help you to recover

    Obat Untuk kaligata
    Obat Untuk Menghilangkan keputihan
    Obat Pengering luka bernanah
    Obat luka
    Obat eksim

    ReplyDelete
  7. Due to sending in those offer, You are investing in buy this realisation brand from the vendor if you're the earning prospective buyer. You read and sign the worldwide transportation structure affiliate agreement unwraps in any pickup's wind shield also known as loss. Transfer costs by now quotation probably have become controlled by change if you ever speed up you uttermost place a bet little..

    If the house is Camisetas De Futbol Baratas always went back following a established time it Maglie Poco Prezzo will undergo a 20% re selling commission rate aka refusal. For Coach Outlet Online Store something to qualify for head back or replace, The system had to be inside one of a kind overall disease utilizing manuel neuer trikot rot the labels it maillot de foot personnalise entered. hummel trikots In cases where the taken back service supplying is divided or is devoid of you should we will resultados de futbol see a Restocking charge all the way to 20%.

    By - applying your personal quote, You are investing maillot de foot pas cher in buy here food from the owner if you are the succeeding prospective buyer. You read maillot foot 2018 and accept the world shipping and delivery company conditions starts advertising in a meaningful door and bill. Significance allegations earlier amazon müller trikot in this article cited have been controlled by change inside event you improve you greatest tender value.

    ReplyDelete