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

Forums / Sitefinity SDK / Get Available Search Indices

Get Available Search Indices

21 posts, 0 answered
  1. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    21 Apr 2011
    Link to this post
    I am creating a custom search control that allows specify what content they would like to search (events, news, etc).  I would like the user to be able to specify which search index to use for each type of content in the control designer in the Sitefinity backend.  How would I retrieve the available defined search indices to put them in a combobox for user selection?  I didn't see a way to retrieve them from the SearchManager.  Is there another object that manages the search indices or did I miss them on the SearchManager?

    Thanks.
  2. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    26 Apr 2011
    Link to this post
    Does anyone know how to accomplish this?  This is one of the last features of my project which is wrapping up very shortly.  I need to be able to allow the user to select which search indices to use for my search functionality.  How do I get the available search indices?

    Thanks.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Apr 2011
    Link to this post
    Hi Geoff,

    You can use the code below to get the active pipes


                var providerName = "SearchPublishingProvider";
                var pipeTypeName = "SearchIndex";

                List<PublishingPipeViewModel> pipesList = new List<PublishingPipeViewModel>();
                var manager = PublishingManager.GetManager(providerName);
                var query = manager.GetPipeSettings().Where(p => p.PipeName == pipeTypeName);
                query = query.Where(p => p.IsActive == true && p.IsInbound == false);

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  4. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    27 Apr 2011
    Link to this post
    Thanks, Ivan.  That retrieved the search indices for me.  Not sure how I would have figured out those strings without being told, since there doesn't appear to be any documentation around this.

    This leads me to another question.  I'm now attempting to perform a search using a selected index and am not getting any search results.  The index is created for events, events exist on the sitefinity backend, and I have reindexed the search index.  The events were created using a simple workflow, which required approval before publishing the events.  I selected the frontend page I used to create the events as the "Default page where events are published", but am getting no results.  I assume the events were actually created through the backend, since that is where the approval/publishing took place.

    Which page do I need to select for the "Default page where events are published"?
    How would I index events created through the Sitefinity backend?

    There's not much to it, but here is my code to perform the search:
    /* EventsSearchIndexTitle is a valid string containing a valid title of a search index */
    /* query is a string containing part of one of the event titles */
     
    SearchManager searchManager = SearchManager.GetManager(null);
    IResultSet results = searchManager.Find(EventsSearchIndexTitle, query, null);
     
    /* results contains 0 elements */

    Thanks.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Apr 2011
    Link to this post
    Hi Geoff,

    If you use the public search box and search result control are you getting results? There is a bug related to the search that we found earlier this week and we are going to provide a fix with the internal build.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  6. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    29 Apr 2011
    Link to this post
    Ivan, I do get results using the same Search Index with the built in search controls.  Do the built in controls use the same API that I am trying to hook into?  Assuming this is the case, am I using the API incorrectly?

    Thanks.
  7. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    04 May 2011
    Link to this post
    Ivan,
    Do you have more input on this issue?  Why does the built in search control work, but my custom search control does not?  Are the controls not using the same API?  As posted in another thread, the only outstanding tasks on my project currently are awaiting feedback from Telerik in this thread and this thread, so timely resolutions to these issues would be appreciated by both my team and my client.

    Thanks.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 May 2011
    Link to this post
    Hello Geoff,

    Can you try to add the following two parameters to the Find method

    var IndexCatalogue = "NameOfYourIndex";
    var searchQuery = "SearchFor";
    var skip =0;
    var take = 50;

    var searchManager = SearchManager.GetManager(null);
                        IResultSet result = searchManager.Find(
                            IndexCatalogue,
                            searchQuery,
                            skip,
                            take
                            );

    All the best,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  9. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    06 May 2011
    Link to this post
    Adding 'skip' and 'take', as shown in your posted example, still returns 0 results, while the same query returns results using the out of the box search control with the same search index.

    For what it's worth, I am using Sitefinity 4.0 SP1 because there are breaking changes in 4.1 and we are unable to upgrade at this point in time.  Do you know of any bugs in 4.0 SP1 that would be causing this behavior?

    Does your posted code sample return results for a given search index in your environment?  Which version of Sitefinity are you testing against?

    Thanks.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 May 2011
    Link to this post
    Hi Geoff,

    I am still not able to replicate an issue with the same code.


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  11. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    12 May 2011
    Link to this post
    Ivan, which version of Sitefinity did you test the code on?  I am using Sitefinity 4.0 SP1 because of the breaking changes in 4.1 and we are unable to upgrade at this point in time.  Do you know of any bugs in 4.0 SP1 that would be causing this behavior?

    Thanks.
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 May 2011
    Link to this post
    Hi Geoff,

    I am using Sitefinity 4.1 release.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  13. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    17 May 2011
    Link to this post
    Ivan, I am able to get the previously posted code to work in 4.1 SP1.

    Now that I have an IResultSet, I don't see how to retrieve the search results from it.
    The .ToArray() extension method throws an IndexOutOfRangeException when called, even though the IResultSet contains 2 results.  I'm assuming this is a bug.  Is there another way to iterate through the returned list?  What type is contained within the collection?

    Thanks.
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 May 2011
    Link to this post
    Hi Geoff,

    The query returns IResultSet which inherits from IEnumerable<IDocument>. The IResultSet is based on the hits. Inside the IResultSet there is all data for the returned item.

    • ID
    • Title
    • Content
    • Summary
    • ContentOwnerFirstName
    • ContentOwnerLastName
    • ContentOwnerEmail
    • PublicationDate
    • ContentCategories
    • ContentExpirationDate
    • ContentParentItemId
    • ContentLink
    • PipeId
    • ContentType
    • ItemHash
    • OriginalItemId




    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  15. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    18 May 2011
    Link to this post
    Thanks for the internal datatype and the list of properties available.
    I was hoping to display this collection through a RadGrid, but am unable to bind the collection to the grid's datasource.  As mentioned before, calling .ToArray() on the collection throws an IndexOutOfRangeException, and binding the IEnumerable collection results in the DataItem being null on the RadGrid.ItemDataBound event.

    Here is my code attempting to display the results:
    protected override void InitializeControls(GenericContainer container)
    {
        grdSearchResults.ItemDataBound += new GridItemEventHandler(grdSearchResults_ItemDataBound);
    }
     
    private void SearchEvents(string query)
    {
        if (string.IsNullOrEmpty(SearchCatalog))
            return;
     
        int skip = 0;
        int take = 50;
     
        SearchManager searchManager = SearchManager.GetManager(null);
        IResultSet results = searchManager.Find(SearchCatalog, query, skip, take);
     
        grdSearchResults.DataSource = results;
        grdSearchResults.DataBind();
    }
     
    private void grdSearchResults_ItemDataBound(object sender, GridItemEventArgs e)
    {
        IDocument result = e.Item.DataItem as IDocument;
        // result == null  :-(
     
        Label lblTitle = e.Item.FindControl("lblTitle") as Label;
        if (result != null && lblTitle != null)
            lblTitle.Text = result.GetValue("Title");
    }

    Thanks.
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 May 2011
    Link to this post
    Hello Geoff,

    Find returns IResultSet. You need to cast the result to List

    <telerik:RadGrid runat="server" ID="RadGrid2" AutoGenerateColumns="true" Skin="Vista"  EnableViewState="true" >
    </telerik:RadGrid>


    var IndexCatalogue = "index1";
    var skip = 0;
    var take = 50;
     
    var searchManager = SearchManager.GetManager(null);
    IResultSet result = searchManager.Find(
        IndexCatalogue,
        "ssss",
        skip,
        take
        );
     
    this.RadGrid2.DataSource = result.AsEnumerable().First().Fields.ToList();
    this.RadGrid2.DataBind();


    Regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  17. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    19 May 2011
    Link to this post
    I tried using LINQ a few different ways to bind the grid's datasource.

    this.RadGrid2.DataSource = result.AsEnumerable().First().Fields.ToList();
    this.RadGrid2.DataBind();
    This results in the fields of the first document being "bound" to the grid.  I think to display the search results, I would need the documents bound as the datasource and not the fields of a single document.

    this.RadGrid2.DataSource = result.AsEnumerable().ToList();
    this.RadGrid2.DataBind();
    I then tried this, which should bind the documents to the grid instead of a single document's fields, however, this still resulted in e.Item.DataItem being null in the ItemDataBound event.

    Am I correct in my understanding that I need to bind the documents and not the document fields to display the search results?
    Am I not correctly retrieving an IEnumerable<IDocument> list in the second code snippet?
    I'm not understanding why I can look at RadGrid2.DataSource and see the list display correctly on assignment, but then the DataItem is null within the event.

    Thanks.
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 May 2011
    Link to this post
    Hi Geoff,

    From the fields you can extract all data for the returned item. We return field items that represents the actual content item.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  19. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    24 May 2011
    Link to this post
    Ivan,

    Using
    var fields = result.AsEnumerable().First().Fields.ToList();
    fields contains 9 items.

    These items are:
    - OriginalItemID
    - Id
    - PipeId
    - ContentType
    - Title
    - PublicationDate
    - Link
    - Summary
    - Content

    The values of these items match the metadata associated with the first item I expect to be returned in the search results, but 2 items are returned.  I'm not sure how to extract data for the second item returned, or x items after that, using the results from the given code.  Can you explain how you are able to get the result items and their associated fields?

    Thanks.
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 May 2011
    Link to this post
    Hi Geoff,

    The sample code queries the first item item only.  This is an ASP.NET IEnumerable<Type>
    For instance you can use MoveNext and .Curent to get the items .

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  21. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    24 May 2011
    Link to this post
    Correct, but I am trying to bind this collection to a RadGrid, so I cannot iterate through the list.
    I previously posted this:
    this.RadGrid2.DataSource = result.AsEnumerable().ToList();
    this.RadGrid2.DataBind();
    However, this resulted in e.DataItem being null, so I was unable to act on each of the items.

    How would I retrieve the search results and bind them to the datasource of a RadGrid?

    Thanks.
21 posts, 0 answered