+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / index search for event

index search for event

4 posts, 0 answered
  1. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    07 Jan 2011
    Link to this post
    I created an index search for events based on the post. It works fine, so now I can setup the search index for events in admin section. There is one issue that I need to let users to select an search result page like NewsIndex (see attached image). Can you give me some instructions? Thanks.

    EventIndexProvider.cs
    public class EventIndexProvider : IIndexingServiceClient
        {
            /// <summary>
            /// Defines the name of the provider. This name is used to mange providers within Indexing Service.
            /// </summary>
            public string Name
            {
                get
                {
                    return "EventIndexProvider";
                }
            }
     
            /// <summary>
            /// Provides detailed description of the client
            /// </summary>
            public string Description
            {
                get
                {
                    return "Provides indexing for events";
                }
            }
     
            /// <summary>
            /// Meta fields for this provider
            /// </summary>
            protected string[] MetaFields
            {
                get
                {
                    return new string[]{
                        "Title"
                    };
                }
            }
     
            public IIndexerInfo[] GetContentToIndex()
            {
                List<IIndexerInfo> list = new List<IIndexerInfo>();
     
                // get current events
                EventsManager mgr = new EventsManager("Events");
                IMetaSearchInfo[] filters = new IMetaSearchInfo[1];
                 
                //filters[0] = new MetaSearchInfo(MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterOrEqual);
                filters[0] = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual);
                IList events = mgr.Content.GetContent("Event_Start DESC", filters);
     
                foreach (IContent ev in events)
                {
                    Hashtable metaFields = new Hashtable();
                    foreach (string key in MetaFields)
                    {
                        metaFields.Add(key, "");
                    }
     
                    metaFields["Title"] = ev.GetMetaData("Title");
     
                    list.Add(
                        new EventIndexerInfo(
                        string.Format("/events/details{0}.aspx", ev.Url),
                        metaFields,
                        ev.Content.ToString())
                        );
                }
     
                return list.ToArray();
            }
     
            public string[] GetUrlsToIndex()
            {
                return new string[0];
            }
     
            public event EventHandler<IndexEventArgs> Index;
     
            public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
            {
            }
        }
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jan 2011
    Link to this post
    Hello Stephen,

    You need SettingsControl and ViewSettingsControl. For more information and samples, please take a look at implementing custom index

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    12 Jan 2011
    Link to this post
    Thanks Ivan. I got the following error in admin. Can you help me out? Thanks again.

    The given key was not present in the dictionary.
    Description:
    An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    Source Error:
    Line 90:         public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
    Line 91:         {
    Line 92:             eventsPageUrl = settings["ProductPageUrl"];
    Line 93:             settings.TryGetValue("EventIndexProvider", out productsProvider);
    Line 94:             if (String.IsNullOrEmpty(eventsPageUrl))


    This is how I set the key in EventsSettingControl
    public IDictionary<string, string> GetSettings()
            {
                settings = new Dictionary<string, string>();
                settings["EventIndexProvider"] = ProviderName = ctrlContainer.ProviderName.SelectedValue;
                settings["ProductPageUrl"] = ctrlContainer.SingleProductUrl.Text;
                return settings;
            }

    The only difference between my index provider and the product search provider in your post is that my index provider is inherited from IIndexingServiceClient, but the product search provider is inherited from ContentIndexProvider. Does it cause any issues? Thanks.

    My Provider:
    public class EventIndexProvider : IIndexingServiceClient
      {
           public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
            {
                eventsPageUrl = settings["ProductPageUrl"];
                settings.TryGetValue("EventIndexProvider", out productsProvider);
                if (String.IsNullOrEmpty(eventsPageUrl))
                    throw new ArgumentException(String.Format("CannotCreateAbsoluteUri"));
            }
     
    }

    ProductSearch Provider in your post:
    public class ProductsIndexProvider : ContentIndexProvider
    {
           public override void Initialize(IDictionary<string, string> settings)
            {
                productsPageUrl = settings["ProductPageUrl"];
                settings.TryGetValue("ProductsProvider", out productsProvider);
     
                if (String.IsNullOrEmpty(productsPageUrl))
                    throw new ArgumentException(String.Format("CannotCreateAbsoluteUri"));
                base.Initialize(settings);
            }
    }
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2011
    Link to this post
    Hello Stephen,

    The key you are looking for in to inside dictionary of settings. These key has not been added or somewhere during the pipe  the value has been cleared.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered