Friday, March 9, 2012

How to: Make folder hits appear at the end of your search results

imagePaul Olenick tweeted me a question on how to get folder hits to appear at the end of the search results using FAST Search for SharePoint.

If we are talking about folders from file shares this is not too hard. If we refer to my post about Taking promotions/demotions one step further we can accomplish this by adding negative promotion using XRANK.

Monday, February 20, 2012

Finding the week number from a date–ISO 8601

I previously wrote about how to find the first day or date given a week number and how to get that working correctly.

Going the other way is in theory easier as you can use functions from .Net itself.

public static int GetWeekNumber(this DateTime date)
{
    var currentCulture = CultureInfo.CurrentCulture;
    return currentCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}

Except there is a bug in .Net which will return the wrong week for some boundary dates around the end of December and the beginning of January.

The fix is equal to that of my previous post, use the Thursday of the week of your date and it will work.

public static int GetWeekNumber(this DateTime date)
{
    int daysToAdd = date.DayOfWeek != DayOfWeek.Sunday ? DayOfWeek.Thursday - date.DayOfWeek : (int)DayOfWeek.Thursday - 7;
    date = date.AddDays(daysToAdd);
    var currentCulture = CultureInfo.CurrentCulture;
    return currentCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}

Monday, January 30, 2012

Finding the first day of a week–ISO 8601

[See http://techmikael.blogspot.com/2012/02/finding-week-number-from-dateiso-8601.html on how to get the correct week number from a date]

I’m working on an application where we work with week numbers and of course there was an error in getting everything to work correct with week numbers. For a specific week I want to get the Monday of that week. With the ISO 8601 standard a week starts on a Monday and ends on a Sunday, and I’m dealing with a calendar which states that week 1 = the first week with 4 full days.

Our current code was not working, and checking on StackOverflow I found a couple of samples in order to fix this:
http://stackoverflow.com/questions/3854429/in-net-knowing-the-week-number-how-can-i-get-the-weekdays-date
http://stackoverflow.com/questions/5377851/get-date-range-by-week-number-c-sharp
http://stackoverflow.com/questions/662379/calculate-date-from-week-number

The flaw in these solutions is that they all base the week calculation on the first Monday of the year. Reading up on ISO 8601 at Wikipedia the solution is simple:
The week number can be described by counting the Thursdays: week 12 contains the 12th Thursday of the year.
Instead of basing the code on a Monday, use Thursday and all boundary conditions with week 1, 52 and 53 are resolved. Then subtract 3 days at the end to get the Monday.

The following code works for all boundary conditions which the previous code samples fail at:

public static DateTime FirstDateOfWeek(int year, int weekOfYear)
{
    DateTime jan1 = new DateTime(year, 1, 1);
    int daysOffset = DayOfWeek.Thursday - jan1.DayOfWeek;

    DateTime firstThursday = jan1.AddDays(daysOffset);
    var cal = CultureInfo.CurrentCulture.Calendar;
    int firstWeek = cal.GetWeekOfYear(firstThursday, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

    var weekNum = weekOfYear;
    if (firstWeek <= 1)
    {
        weekNum -= 1;
    }
    var result = firstThursday.AddDays(weekNum * 7);
    return result.AddDays(-3);
}

Friday, January 27, 2012

How to do Visual Best Bets for built-in SharePoint Search

Marcus Johansson did a post about the use of Best Bets this morning which inspired me to write this post. Read his post for more thoughts around the use of best bets.

Visual Best Bets is a feature of FAST Search for SharePoint which lets you point to a file with html content to be displayed above your search results. For example an image, silverlight or flash content can be used to graphically enhance what is linked to the keyword term. The Visual Web Part uses an iframe to accomplish this and loads up your content inside the iframe. This is useful as you can easily edit the html file at will.

But why go the extra mile for a separate file, or opt in for FS4SP for this feature? The Best Bet web part support the showing of keywords and keyword definitions. Keyword definitions are formatted as html. And a definition with html formatting is in effect a Visual Best Bet. (If you have more than one Visual Best Bet you want to assign to the keyword you would have to add them all to the same html for this to work.)

Tuesday, December 13, 2011

Returning Best Bets and Visual Best Bets with KeywordQuery and FAST Search for SharePoint

When using the Search Center the Best Bets or Visual Best Bets functionality works like a charm, but I have not been able to get it to work using the KeywordQuery class in SharePoint.

I had done some research previously on the matter after being contacted by Xavier Vanneste who blogged about this (http://blog.xvanneste.com/Lists/Billets/Post.aspx?ID=82), but was not able to figure it out at the time.

I’m currently writing sample code for my upcoming book on FS4SP and I had to figure this out. Time to bring out the tools!

One hour with the Visual Studio Reflector plugin and setting break-points internally in the SSA I finally figured it out. And in a way it was obvious.

Saturday, December 10, 2011

How to prevent an item from being indexed with FAST for SharePoint

Yes, it can be done!

It’s Saturday, my kid has gone to sleep, and I finally have time to tell you guys the good news. Preventing an item from being index, or to paraphrase, to drop a document in the document processing pipeline is indeed possible!

You can already prevent items from being indexed by limiting SharePoint lists and libraries from being crawled with library settings and you can use crawl rules to exclude certain url patterns. But what I am talking about is preventing an item from being indexed based business rules in your organization and looking at the meta data of the item or inside the text of a file.

There are many scenarios for not wanting an item searchable. You might want to prevent indexing items in your organization which contains the super secret codename “wobba”, or items of a certain ContentType. When indexing file shares you don't have much meta data to go on at all for excluding items, so creating your own module with the proper rules might be the only way to go.

Monday, November 28, 2011

Creating a Secure Store Target application with access for all users

I am currently working on a SharePoint application which access users Exchange calendars via web services. In order to access the calendars we need to provide credentials and we use a service account which has access to all calendars.

Instead of storing the logon information of the service account in a list or web.config we want to store this in Secure Store which is ideal for storing credentials (big surprise there). We also want to create the Secure Store target application in code with an installer and not using Central Admin.

Sunday, November 20, 2011

Taking promotions/demotions one step further in FAST Search for SharePoint

promotionsI am not sure how many times I have read the documentation on promotions and demotions in Microsoft documentation, but I can say it is numerous.

And yet yesterday I discovered a valuable piece of nugget which I’m sure I will use a lot in the future.

Friday, October 21, 2011

Error while running the FAST for SharePoint post configuration

During a customer installation the other day my project colleagues encountered a weird issue when configuring up a FAST server. (This was after we got all policy issues resolved due to server hardening – which took some time as well).

When running the configuration wizard they got an unexpected error, and the configuration didn’t finish.
Time to hit the installer log…. The error they got was hidden a bit down the load and was coming from the “ULS Common Core Components” which is installed during configuration.

20.10.2011 14:42:39 Verbose InstallAction - Installing ULSCommonCore services
20.10.2011 14:42:39 Verbose Executing ULSCommonCore installer msiexec /i "C:\FASTSearch\\installer\files\ulscommoncore.msi" /quiet /norestart INSTALLLEVEL=100 - 
20.10.2011 14:42:39 Verbose Utility.Execute - Starting process msiexec with working directory - , write output - False, file - , user - 
20.10.2011 14:42:41 Warning Utility.Execute - Return code for binary msiexec is not 0. This may indicate that binary didn't execute successfully
20.10.2011 14:42:41 Verbose Utility.Execute - Finished executing msiexec
20.10.2011 14:42:41 Error InstallULSCommonCore - An error occurred while executing binary msiexec. Return code is not 0.
20.10.2011 14:42:41 Error Utility.WriteException - Exception -  : Exception - System.Management.Automation.RuntimeException: Error executing ULSCommonCore installer.


Upon my suggestion they kicked off the ULS installer manually and got the following pop-up which gave information for further internet searches.

image

The error is caused by the registry size being too small and has to be increased. Not too obvious from neither the install log nor the pop-up.

Thanks to the below post for giving the resolution on how to increase it :) http://www.geosoft.com/support/knowledge-base/errormessage/Error-An-error-occurred-during-the-installation-of-assembly-Microsoft-VC90-ATL.

Monday, October 17, 2011

A side-by-side approach for upgrading SharePoint search to FAST

search in capeMore and more businesses are upgrading their existing SharePoint 2010 search solutions to FAST Search for SharePoint. Doing so will most likely require scheduled downtime when you make the actual switch.

This can be avoided by cleverly upgrading your existing Search Service Application to a FAST Query SSA.

Want to learn more? Head over to my article at NothingButSharePoint.com for the details - http://pzl.no/qKacHz.