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

Forums / Developing with Sitefinity / Search to Provide Article ID

Search to Provide Article ID

6 posts, 0 answered
  1. Ben
    Ben avatar
    18 posts
    Registered:
    12 May 2008
    19 Oct 2009
    Link to this post
    We'd like to create our own control for displaying a new article found via the built-in search function.  We're even considering generating our own control for displaying the search results, but one item at a time...
    Right now the search functionality doesn't seem to provide the Article ID field for the articles that satisfy the search criteria.  How can we get that?  If we have that GUID, we can pass it to a page we've already created to display the article.
       Thanks in advance,
          Ben
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    19 Oct 2009
    Link to this post
    Hello Ben,

    You need to create a custom search indexing provider and search indexing info class. In your SearchindexingInfo class which should inherit from IIndexerInfo you need to override ItemId property as shown below:

    public Guid  ItemID
           {
               get { return this.itemId; }
           }

    If you pass a certain guid value to ItemID the indexer will search only in this item.

    Another option is overriding ParentIDs in your custom provider that should inherits from ContentIndexProvider. By doing so you can search only in items that have certain parent. For instance all items from a given blog where we have contentitem.ParentId.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Ben
    Ben avatar
    18 posts
    Registered:
    12 May 2008
    19 Oct 2009
    Link to this post
        I'm not sure I did a good enough job explaining what I want to do.  I want the search to examine the same domain of articles that it does now, but when it finds matches, I want to be able to get the article ID (GUID) of those articles that match the search criteria.  I don't want to restrict the search by limiting it to an ID.
       Does that help?
          Ben
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    20 Oct 2009
    Link to this post
    Hello Ben,

    The items returned by Search Results are of type ResultItem and you cannot get the id of an item. The ResultItem represents information about a document in a result set. The available properties are Title, Snippet, Url, Score, but none of this properties will give you the access to the item ID.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Ben
    Ben avatar
    18 posts
    Registered:
    12 May 2008
    21 Oct 2009
    Link to this post
    Ivan,
       Disappointing, but there may be other ways to accomplish this.  I could find the Guid if I could match the article title to the condensed version that's part of the URL on the Search Results page.  Can I get the exact algorithm you use to convert the article's title to the string you put in the URL?  With that in hand, I could use that portion of the URL and the GC_MetaData table to find the Guid.
       Thanks,
          Ben
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    22 Oct 2009
    Link to this post
    Hello Ben,

    If you get the title you can use ContentManager and GetMetaData method, but this will work only in case you do not have two items with the same title ( for instance you use several index types in one).

    However, I managed to come up with something that will do the trick.

    1. Create an index.
    2 Open  fieldsIndexingInfo.xml file located under Add_Data/Search/YourIndexName
    3. Add the following line as shown below:

    <?xml version="1.0" encoding="utf-8"?>
    <fields>
      <field name="title" weight="1" indexAttribute="" filterTag="title" filterAttributes="" />
      <field name="guid" weight="1" indexAttribute="" filterTag="guid" filterAttributes="" />
      <field name="keywords" weight="1" indexAttribute="content" filterTag="meta" filterAttributes="name:keywords;" />
      <field name="description" weight="1" indexAttribute="content" filterTag="meta" filterAttributes="name:description;" />
      <field name="script" weight="-1" indexAttribute="" filterTag="script" filterAttributes="" />
      <field name="style" weight="-1" indexAttribute="" filterTag="style" filterAttributes="" />
    </fields>

    4. Restart the application and then run the indexer again.

    Now you should see the ResultItem ID returned in the snippet.

    If necessary you can subscribe for ItemDataBound event of the repeater that lists all items ( under SearchResults template) and extract this ID as shown below:

    protected void Page_Load(object sender, EventArgs e)
        {
            this.rptResults.ItemDataBound += new RepeaterItemEventHandler(rptResults_ItemDataBound);
             
        }
     
        void rptResults_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                
                Telerik.Search.Engine.ResultItem resultITem = e.Item.DataItem as Telerik.Search.Engine.ResultItem;
                string value = resultITem.Snippet;
                string ID = value.Substring(0, 36);
                 
               
            }
        }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
6 posts, 0 answered