Configure Examine to index what you want to search by setting up ExamineIndex.config and ExamineSettings.config I Usually set up a separate index from the default indexes used by the umbraco backend.
Publish a node in umbraco backend, and verify that your index folder is created, if you want you can even check the content of the index with Luke.
Create an ASP.NET usercontrol that performs the search and lists out the result. The code below is an example that performs a search on a limited set of Institution nodes, but your code could be very different depending on your needs
// From the search masterpage/usercontrol codebehind
private List<Institution> GetInstitutions()
{
// Perform search
string searchTerm = SearchTerm.Text;
ExamineManager mgr = ExamineManager.Instance;
ISearchCriteria criteria = mgr.SearchProviderCollection["InstitutionSearcher"].CreateSearchCriteria();
IBooleanOperation filter = GetFilter(searchTerm, criteria);
ISearchResults searchResults = mgr.SearchProviderCollection["InstitutionSearcher"].Search(filter.Compile());
if (searchResults.Any())
return searchResults.Select(r => new Institution(r)).ToList(); //I've got a class that has a .ctor which takes a searchresult
return null;
}
private IBooleanOperation GetFilter(string searchTerm, ISearchCriteria criteria)
{
// If searchterm is numeric we'll search on zipcode
int zipCode;
if (int.TryParse(searchTerm, out zipCode))
{
return criteria.Field("zipcode", searchTerm);
}
// If not we'll search on name and address
IExamineValue[] examineValues = { searchTerm.MultipleCharacterWildcard() };
if (searchTerm.Contains(" "))
{
string[] terms = searchTerm.Split(' ');
List<IExamineValue> values = new List<IExamineValue>();
foreach (var term in terms)
{
values.Add(term.MultipleCharacterWildcard());
}
examineValues = values.ToArray();
}
return criteria.GroupedOr(new[] { "name", "address" }, examineValues);
}
// From the Institution.cs
public Institution(SearchResult hit)
{
Id = hit.Id; // You could also return the node of the hit using new Node(hit.Id)
Number = hit.Fields.ContainsKey("instId") ? int.Parse(hit.Fields["instId"]) : -1;
Name = hit.Fields.ContainsKey("name") ? hit.Fields["name"] : "";
Address = hit.Fields.ContainsKey("address") ? hit.Fields["address"] : "";
ZipCode = hit.Fields.ContainsKey("zipcode") ? hit.Fields["zipcode"] : "";
City = hit.Fields.ContainsKey("city") ? hit.Fields["city"] : "";
WebUrl = hit.Fields.ContainsKey("webUrl") ? hit.Fields["webUrl"] : "";
}
<!-- Get the search term from the query string--> <xsl:variable name="searchTerm" select="umbraco.library:RequestQueryString('s')" />
<xsl:template match="/">
<!-- Check if there's a search term to search on--> <xsl:if test="string-length($searchTerm) > 0">
<!-- Get the search results from examine --> <!--************************ THIS IS WHERE THE MAGIC HAPPENS *****************************-->
<xsl:variable name="results" select="examine:Search($searchTerm)"/> <!-- If i remove this then this xslt works ...but nothin will be searched as i will remove this --> <!-- but if i keep this then i get the error Error parsing XSLT file: \xslt\SearchResults.xslt
-->
<!--************************ END OF MAGIC ************************************************-->
Lucene search in umbraco website...
Hi,
I want to implement the lucene search in my website but i dont know how to implement it...can anybody help me in that .....
Hi vaibhav,
Did you read the available documentation? It can be found here: http://www.farmcode.org/page/Umbraco-Examine.aspx, and here: http://examine.codeplex.com/documentation.
If you have an Umbraco.tv subscription there is also 3 instructional video available at: http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco
If you already did read that please don't hesitate to post and ask about specifik problems and questions you have.
Regards
Jesper Hauge
Hi,
I did read that document ...but i want the steps for implementing the lucene search ....
can u plz tell these steps ....
Hi vaibhav,
I can give you an overview:
I Usually set up a separate index from the default indexes used by the umbraco backend.
There's some articles as well in blogworld you could look at:
http://joeriks.wordpress.com/2011/03/15/ajax-enabled-search-in-umbraco-using-examine-and-razor/
http://www.thereturnvalue.com/blog/2010/11/13/implements-examine-search-in-a-multi-language-umbraco-site
http://www.yart.com.au/Resources/Umbraco-Tips-And-Tricks/Umbraco-Examine-Site-Search.aspx
To get and idea of how others are doing this.
Regards
Jesper Hauge
Hi,
I found one demo website from here.......http://www.farmcode.org/post/2010/07/01/Examine-demo-site-source-code-from-CodeGarden-2010.aspx
i made same demo site(it works properly) like this on my umbraco ....but its not working....
i have created document types , templates , usercontrol , xslt & macro ....what else thing should i create or change to work in out.....
plz have a look at that demo site & help me plz....
Plz help me ....
I wanted to use an XSLT approach and this link helped me out: http://our.umbraco.org/wiki/reference/xslt/using-examine-in-xslt
is working on a reply...