Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • vaibhav 119 posts 139 karma points
    May 30, 2011 @ 14:45
    vaibhav
    0

    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 .....

  • Jesper Hauge 298 posts 487 karma points c-trib
    May 30, 2011 @ 14:57
    Jesper Hauge
    2

    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

  • vaibhav 119 posts 139 karma points
    May 31, 2011 @ 09:14
    vaibhav
    0

    Hi,

    I did read that document ...but i want the steps for implementing the lucene search ....

    can u plz tell these steps ....

  • Jesper Hauge 298 posts 487 karma points c-trib
    Jun 01, 2011 @ 09:08
    Jesper Hauge
    0

    Hi vaibhav,

    I can give you an overview:

    • 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"] : "";
    }

    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

  • vaibhav 119 posts 139 karma points
    Jun 01, 2011 @ 14:02
    vaibhav
    0

    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....

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:examine="urn:examine"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
    xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
    xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
    xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml examine umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <!-- 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 ************************************************-->


    <p>
    Search text:&nbsp;<b>
    <u>
    <xsl:value-of select="$searchTerm"/>
    </u>
    </b>&nbsp;&nbsp;<i>
    <b>
    <xsl:value-of select="count($results//node)"/>
    </b>&nbsp;result(s)
    </i>
    </p>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    Plz help me ....

  • Jon Dunfee 199 posts 468 karma points
    Oct 07, 2012 @ 06:20
    Jon Dunfee
    0

    I wanted to use an XSLT approach and this link helped me out: http://our.umbraco.org/wiki/reference/xslt/using-examine-in-xslt

Please Sign in or register to post replies

Write your reply to:

Draft