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 18, 2012 @ 19:25
    Babajide
    0

    Examine can't search for two words

    Am having a wierd problem with my search. When i search for two words it doesn't return any results. But when i search for the first word it returns the appropriate search results.

    This is my SearchResults.ascx.cs code:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

     

    using UmbracoExamine;

    using Examine;

    using Examine.LuceneEngine.SearchCriteria;

     

    public partial class usercontrols_SearchResults : System.Web.UI.UserControl

    {

     

            public string Term { get; set; }

    public int Count { get; set; }

     

            protected void Page_Load(object sender, EventArgs e)

            {

    Term = Request.QueryString["s"].ToString();

    if (Term.Length > 1)

    {

                //Create search Criteria

                var sc = ExamineManager.Instance.CreateSearchCriteria();

     

                //define query

                var query = sc.NodeName(Term.MultipleCharacterWildcard())

                            .Or()

                            .Field("bodyText", Term.MultipleCharacterWildcard());

                         //   .Or()

                         //   .Field("summary", Term.MultipleCharacterWildcard());

     

                //or search by keyword

     

                var results = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"].Search(Term, true);

                rp_results.DataSource = results;

    Count = results.Count();

                rp_results.DataBind();

    }

            }

     

     

            //simple helper to add summary of search result

            public string HighLightSummary(RepeaterItem item)

            {

                SearchResult sr = (SearchResult)item.DataItem;

     

                if (sr.Fields.ContainsKey("bodyText"))

                    return umbraco.library.TruncateString(umbraco.library.StripHtml(sr.Fields["bodyText"]), 300, "...").Replace(Term, "<strong>" + Term + "</strong>");

     

                if (sr.Fields.ContainsKey("summary"))

                    return umbraco.library.TruncateString(umbraco.library.StripHtml(sr.Fields["summary"]), 300, "...").Replace(Term, "<strong>" + Term + "</strong>");

     

     

                return string.Empty;

     

            }

        }

    public static class SearchResultExtensions

        {

            // Create a set of helper methods to make output

            // cleaner.

            public static string FullUrl(this SearchResult sr)

            {

                // Generate the URL for the returned node using 

                // the umbraco library method NiceUrl.

                var urlStr = umbraco.library.NiceUrl(sr.Id);

                return urlStr;

            }

     

            public static string GetDetails(this SearchResult sr, int length)

            {

                var contentStr = "";

                var truncateStr = "...";

                if (sr.Fields.ContainsKey("bodyText"))

                {

                    contentStr = sr.Fields["bodyText"];

                }

                else if (sr.Fields.ContainsKey("question"))

                {

                    contentStr = sr.Fields["question"];

                }

                else if (sr.Fields.ContainsKey("answer"))

                {

                    contentStr = sr.Fields["answer"];

                }

    else if (sr.Fields.ContainsKey("Name"))

                {

                    contentStr = sr.Fields["name"];

                }

     

                // Only show the first 300 characters of the node

                // contents and use that as the preview of the 

                // page content in the repeater.

                if (contentStr.Length > length) contentStr = contentStr.Substring(0, length) + truncateStr;

                return contentStr;

            }

        }

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies