Wednesday 23 March 2011

Setting the first clause in a Lucene query to a SHOULD clause using Umbraco Examine

I'm using Umbraco Examine to index my content by setting up an Index on my Shared document type. I wanted to allow multiple search terms to be looked for in the index regardless of their order. So for example if a search for:

technology portable

or

portable technology

Both technology and portable will be searched for in the index. This was done using GroupOr methods but the problem was the first search term would always be included in the query as a MUST clause. Here is the code.

// Get the search criteria by using our searcher provider and looking only in the content tree of Umbraco.
var criteria = ExamineManager.Instance.SearchProviderCollection["SharedSearcher"].CreateSearchCriteria(IndexTypes.Content);

// Build the search query.
Examine.SearchCriteria.IBooleanOperation query = null;

foreach (var searchTerm in nonEmptySearchTerms)
{
query = query == null ? criteria.GroupedOr(fields, searchTerm.Trim().MultipleCharacterWildcard()) :
query.Or().GroupedOr(fields, searchTerm.Trim().MultipleCharacterWildcard());
}

// Perform the search.
results = ExamineManager.Instance.Search(query.Compile());
results.OrderByDescending(x => x.Score); // Relevance.

The only changed required was in the criteria creation to set the default BooleanOperator to an or, and thus setting the first clause to be SHOULD instead of MUST. Here is the corrected line:

var criteria = ExamineManager.Instance.SearchProviderCollection["SharedSearcher"].CreateSearchCriteria(IndexTypes.Content, BooleanOperation.Or);

Wednesday 9 March 2011

Default Umbraco Master Page



Manual Umbraco Setup

Setup Umbraco Development Environment

Technologies used:

· Visual Studio 2010

· IIS7 (using hosts file)

· Tortoise-SVN

· Windows 7

· Umbraco 4.6.1

· SQL Server 2008 (management studio)

· .NET 4.0

Get Umbraco

1. Download the version of Umbraco you want from http://umbraco.codeplex.com/releases/view/59502

2. Create an Umbraco folder on your computer where you will extract the files to e.g. C:\Development\Umbraco\4.6.1.

3. Copy the downloaded file to C:\Development\Umbraco\4.6.1 and once there right click on the zip file and select Properties. Under the General tab click Unblock and then Ok.

4. Unzip the files here. They will be extracted into sub-folders but you need to copy the actual files under the build folder into C:\Development\Umbraco\4.6.1.

5. Delete the sub folders generated by un-zipping.

6. Add NetworkService user to C:\Development folder with full permissions.
























Hosts file

7. Click the orb in Windows 7 and type %SystemRoot%\system32\drivers\etc\ into the search textbox and open the folder.

8. Locate the hosts file. This file must not have a extension. Open this file.

9. Add a new entry with the IP 127.0.0.1 (localhost) and space and then your site name e.g. fuelcelltoday.local.

10. Save the file.

11. Click the orb in Windows 7 and type cmd. Once the command line window has opened type ping fuelcelltoday.local and hit enter. If you get a reply then you site is setup correctly.










SQL Server 2008 setup

12. Open SQL Server 2008 Management Studio.

13. Add a new database called e.g. FuelCellToday. This is the database Umbraco will use.

14. Add a new login e.g. fuelcelltoday/password

15. Add a new user e.g. fuelcelltoday/password

IIS7 setup

16. Open IIS7 and right click on Sites then select Add Web Site.

17. Add the site name e.g. FuelCellToday.

18. Point the physical path to C:\Development\Umbraco\4.6.1.

19. Add the host name you chose e.g. fuelcelltoday.local

20. Click Ok.

21. Click on the Application Pools. Right click the application pool created for your site e.g. FuelCellToday and select Advanced Settings.

22. Change the .NET Framework Version to v4.0.

23. Make sure Managed Pipeline Mode is set to Integrated.

24. Set the Identity to NetworkService.

25. Set Load User Profile to False.

26. Click Ok.

Install Umbraco

27. In your browser open the new IIS site URL e.g. http://fuelcelltoday.local.

28. Walk through the Umbraco setup and make sure you select the database we created above. You will also be able to create an admin Umbraco user login during this process. It’s very simple step-by-step process. Once this is done the Umbraco tables will be installed to the database.

29. Test you can login into the Umbraco admin section e.g. http://fuelcelltoday.local/umbraco/umbraco.aspx

30. Test you can see the Umbraco default screen e.g. http://fuelcelltoday.local.

Create SVN repository using Tortoise-SVN

31. In your SVN provider create a new repository e.g. FuelCellToday. Copy the URL created.

32. Create a new folder where the web application will live e.g. C:\Development\Websites.

33. With Tortoise-SVN Checkout the SVN repository here so a new folder is created link to SVN e.g. C:\Development\Websites\FuelCellToday.

Setup Visual Studio 2010 solution

34. Open Visual Studio 2010 and create a new ASP.NET Empty Web Application project. I keep the solution file in the root so I uncheck Create directory for solution option. It’s up to you. Select the folder location you wish to create your project e.g. C:\Development\Websites\FuelCellToday.

35. Copy all the files and folders from the Umbraco folder e.g. C:\Development\Umbraco\4.6.1 to this new website folder. Overwrite any of the files generated by the application with the files from Umbraco folder.

36. In Visual Studio click the Show all files icon in the solution explorer and then Include all the folders and files you just copied into the solution. This might take a while.

37. Build the solution to make sure everything is in order.

Add files to source control using Tortoise-SVN

38. The following files/folders must be ignored. This is so we can easily copy newer versions of Umbraco to this folder and not files that aren’t needed to be under source control:

a. App-Code

b. App-Data

c. bin

d. data

e. install

f. obj

g. python

h. umbraco

i. umbraco_client

j. *.user

k. *.sln

l. *.suo

39. Commit the folder using Tortoise-SVN.

40. Build the solution.

41. Point IIS physical folder to the new website folder e.g. C:\Development\Websites\FuelCellToday.

42. Check the site URLS work e.g. http://fuelcelltoday.local.

New developers

43. Create a checkout folder and download the SVN code e.g. C:\Dev1\Webistes\FuelCellToday.

44. Download Umbraco and unzip files, then copy them into the website folder.

45. Open Visual Studio 2010 and select Open Web Site and select the new folder e.g. C:\Dev1\Webistes\FuelCellToday.

46. Setup IIS as explained above to point to the new folder.

47. Open the site URL.