After a long pause I will continue blogging about Umbraco. The first post will cover a the solution for a question Sebastiaan asked via Twitter. He mentioned that his editors are used to search nodes via the build in search from Umbraco. Umbraco 4.0.x and lower uses Lucene for indexing and searching the nodes. You can implement the frontend search also with Lucene using the same index. But as I had Sebastiaan also had many problems with Lucene, let's say it is unstable. These problems had been one reason for me to create the Simple Search for Umbraco (SS4U [project page on our and Codeplex]).
Let's recap: the SS4U is a search engine which iterates through the nodes in the umbraco.presentation.nodefactory namespace and compares the nodes values.
To get SS4U working you have to configure it like I described in the project documentation. I added the following xml to my config file:
<?xml version="1.0"?>
<SimpleSearch4Umbraco xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SearchDefinition name="Umbraco Backend Search" iterationType="IterateAll" isDefault="true">
<DocumentType alias="Person" category="Employee" includeChildNodes="true" testNodeName="true">
<Property alias="Name" comparisonType="String" comparison="Contains" />
<Property alias="Prename" comparisonType="String" comparison="Contains" />
</DocumentType>
</SearchDefinition>
</SimpleSearch4Umbraco>
Now to replace the Umbraco UI Search I added a new project to my SS4U with two Web Forms in different folders, both named Search.aspx and derived from umbraco.BasePages.UmbracoEnsuredPage. The first one will replace the auto complete search from the search box in the upper left. I also added the following code to the Page_Load event:
if (helper.Request("q").Trim() != "" && getUser() != null)
{
var query = helper.Request("q").Trim();
var searcher = new Searcher();
var results = searcher.Search(query, null, "Umbraco Backend Search");
var items = new List<SearchItem>();
items.AddRange((from x in results
select
new SearchItem
{
Author = "",
ChangeDate = DateTime.Now,
Description = x.Text,
Icon = "",
NodeId = x.Id,
ObjectType = Guid.Empty,
Tags = null,
Title = x.Text
}).Take(20));
var rh = new ResultHelper(items);
var js = new JavaScriptSerializer();
Response.Write(js.Serialize(rh));
}
As you can see it does nearly the same as the original Search.aspx from Umbraco. This code replaces only the search engine but uses the returning helpers like the original code does. In this way you don't have to fuddle in the Java Scripts to get the auto complete to work, just replace the search.aspx located in the umbraco/dashboard folder with the new created. And it works:
To replace the search dialog I took the search.aspx located in the umbraco/dialogs folder and replaced the code in the DoSearch method:
private void DoSearch()
{
string query = keyword.Text.Trim();
var searcher = new Searcher();
var results = searcher.Search(query, null, "Umbraco Backend Search");
var result = new XmlDocument();
result.LoadXml("<results/>");
foreach (var si in results)
{
var x = xmlHelper.addTextNode(result, "result", si.Text);
x.Attributes.Append(xmlHelper.addAttribute(result, "id", si.Id.ToString()));
x.Attributes.Append(xmlHelper.addAttribute(result, "icon", ""));
x.Attributes.Append(xmlHelper.addAttribute(result, "title", si.Text));
x.Attributes.Append(xmlHelper.addAttribute(result, "author", ""));
x.Attributes.Append(xmlHelper.addAttribute(result, "changeDate", ""));
result.DocumentElement.AppendChild(x);
}
searchResult.XPathNavigator = result.CreateNavigator();
}
As well as for the auto complete I replaced only the search engine and used the return helpers the original code uses:
If you need another UI Search than Lucene you only have to replace two Web Forms just outputting the same formats as the original ones do.
To use SS4U to do the UI Search you have to be aware that SS4U searches only the published nodes and the search for a node id will not work (atm). The performance shouldn't be that a problem for sites with <= 10k nodes.
v4.1 of Umbraco comes with Umbraco Examine which uses the new Lucene versions. Hopefully this version will be stable enough to use it in production.
The code of SS4U is checked in on codeplex. I will update our and the download from codeplex the next days.
I have added a new umbraco related project to our.umbraco.org. It is called "Simple Search for Umbraco" and provides a simple way to let your site be searched. It is based on iterating through the umbraco.presentation.nodeFactory objects and it is easy to install and to use. This blog now uses this search via xslt output.
View
Just let me know what you think about it.
09.09.10 18:28: @umbraco happy birthday my friend
09.07.10 20:02: Aaaaadler ;-)
09.07.10 20:01: Einmal Bier holen = Tor verpasst => Der Weg in den Keller ist eindeutig zu lang...
09.04.10 06:04: @Shazwazza Done ;-) #ucomponents #Umbraco
09.03.10 20:43: @netaddicts LOL
![]()
This blog is written by Thomas Höhler. Living next to Frankfurt, Germany,
I am trying to share my experiences about
Umbraco [the most flexible CMS I know],
my ClientTools for Umbraco,
and some other more or less usefull stuff