Copied to clipboard

Flag this post as spam?

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


  • Babajide 26 posts 46 karma points
    Jul 09, 2012 @ 16:35
    Babajide
    0

    How to implement search code in Umbraco 4.7

    Hello guys, i've been trying to get my search bar going but i cannot find how to implement this code in my template:

    @using Examine
    @using Examine.SearchCriteria
    @{
        //Get the values posted from the form
        var searchTerm Request.Form["searchTerm"];

        //Check if searchQuery is null from the posted form data...
        if (searchTerm == null)
        {
            //If it is null then the form was not posted and the page was visited directly
            <p>Please use the search box</p>

            //Stop all other code running in this Macro
            return;
        }

        var searcher ExamineManager.Instance.SearchProviderCollection["RazorSiteSearcher"];
        var searchCriteria searcher.CreateSearchCriteria(BooleanOperation.Or);
        
        var query searchCriteria.GroupedOr(new string["nodeName""bodyText" }searchTerm).Compile();
        var searchResults   searcher.Search(query);
        var noResults       searchResults.Count();
        
        <p>You searched for @searchTermand found @noResults results</p>
        
        <ul class="search-results">
            @foreach (var result in searchResults)
            {
                <li>
                    <href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["nodeName"]</a>
                </li>
            }
        </ul>
    }

    P.S: I got this code from the umbraco "Razor CookBook_search" folder.

    I hope someone can reply as soon as possible!!

    Thanks a ton.

     

  • parwej ahamad 17 posts 37 karma points
    Jul 09, 2012 @ 18:43
  • Babajide 26 posts 46 karma points
    Jul 09, 2012 @ 19:07
    Babajide
    0

    No. Will do. I will be back in a minute. Thanks a lot

  • Babajide 26 posts 46 karma points
    Jul 10, 2012 @ 21:04
    Babajide
    0

    I've been trying to make the examine code work, but the video tutorials on umbraco are very short with little to no info at all. And the page you sent me doesn't really explain well enough. What i want to know is the continuation of this video(setting up a new search index): http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/examine/setting-up-a-new-search-index.aspx

  • parwej ahamad 17 posts 37 karma points
    Jul 11, 2012 @ 06:28
    parwej ahamad
    0

    Hi, given video is paid tutorial so if want then you have to subscribe with 19 EUR per month then you can watch full video. I think so it's not very tuff task to implement the examine search. Please let me know then exact error which you are getting currently.

     

    Parwej

    e: [email protected]

  • Babajide 26 posts 46 karma points
    Jul 11, 2012 @ 23:13
    Babajide
    0

    I have configured everything necessary but i keep on getting this error: 

    Exception Details: System.Configuration.Provider.ProviderException: Unable to load default search provider

     

    [ProviderException: Unable to load default search provider]
       Examine.ExamineManager.LoadProviders() +595
       Examine.ExamineManager..ctor() +28
       Examine.ExamineManager..cctor() +21
    
    [TypeInitializationException: The type initializer for 'Examine.ExamineManager' threw an exception.]
       Examine.ExamineManager.get_Instance() +14
       usercontrols_SearchResults.Page_Load(Object sender, EventArgs e) +103
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
  • parwej ahamad 17 posts 37 karma points
    Jul 12, 2012 @ 18:40
    parwej ahamad
    0

    I did the quick test and it's working fine:

    follow the same steps, as I provided earlier link for configuration. Note: if you are using 4.7.2 then no need to do that because it's already configured.

    Search form: 

     <form method="post">
    <input type="text" id="searchstring" name="searchstring" />
            <input type="submit"/>
    </form>

    Razor script for result:

    @using Examine
    @using Examine.SearchCriteria
    @using UmbracoExamine

    @{
      var searchString Request["searchstring"];
      if (!String.IsNullOrEmpty(searchString))
      {
        var searchProvider ExamineManager.Instance.DefaultSearchProvider.Name;
        var searchResults ExamineManager.Instance.SearchProviderCollection[searchProvider].Search(searchStringtrue);

        foreach (var in searchResults)
        {
          <div>
            <h3><href="@umbraco.library.NiceUrl(c.Id)">@c.Fields["nodeName"]</a></h3>        
            
          </div>
        }
      }
    }

    Please let me know if still not working.

    Parwej

    [email protected]

Please Sign in or register to post replies

Write your reply to:

Draft