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

Forums / Bugs & Issues / Duplicate search results for news items.

Duplicate search results for news items.

11 posts, 0 answered
  1. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    09 Dec 2010
    Link to this post
    Hello,

    I am running SiteFinity 3.7.

    Lets say I have created a news item titled, "Test" and I have put it in the category called "Apples". I have three different news pages with NewsViews. Each page/NewsVIew is set to pull in different categories. 

    Page 1 pulls in the Apples category
    Page 2 pulls in the Pears category
    Page 3 pulls in the Watermelon category.

    So, when I do a search on my site, only one result should appear, right?  Unfortunately, im getting the same news article in all 3 pages, when it should just be the apples news page.

    /Apples/10-12-08/This_is_a_test_news_item.aspx
    /Pears/10-12-08/This_is_a_test_news_item.aspx
    /Watermelon/10-12-08/This_is_a_test_news_item.aspx
  2. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    09 Dec 2010
    Link to this post
    I think i figured out what the issue was.  The admin before me set up 3 News Indexes. That's why it was coming up 3 times! The News Index was going through all the news articles, 3 times, looking for articles with the keyword. 

    I believe he did it that way because he was trying to set up user friendly urls for each category of news items.  For example,  The page about apples makes sense to be found in the virtual url "/produce/09-05-22/story-about-apples.aspx". So, he created 3 separate News Indexes for the 3 categories of news feeds (example:"produce","cars","planes").  While the story about apples was found "/produce", it was also pulling up in "cars" and "planes".

    So, I guess my question comes down to this.  Can i just have one News Index (so results don't show up multiple times), but have the search create a specific URL for the the category the news article is in?



  3. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    09 Dec 2010
    Link to this post
    After further investigation, it appears that if I create a news item and have 3 pages with newsview controls then I have 3 valid URLs for that news item, regardless of setting the newsview control to only show specific categories. For example, this URL is valid when it should not be. It's a news item about oranges and the news view item should only pull up news items about apples:
    /Apples/10-12-08/This_is_a_news_item_about _oranges.aspx

    How can I avoid this? I would like to keep the 3 pages with the 3 configured newsviews because they are set to pull from different categories.  Can I force a newsview on a page to ONLY pull from a SPECIFIC category?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2010
    Link to this post
    Hi Dan,

    Currently the index gets all published content and the page you set in the index is only used for constructing the url. To get items only for one category and for a single page you have to create a custom NewsIndexProvider that inherits from the base - NewsIndexProvider.  In your custom class you have to override GetContentToIndex() where you can use IMetaSearchInfo to filter the items that will be added for indexing.

    IMetaSearchInfo[] filter = this.manager.GetFilter(this.FilterExpression);
    List<IMetaSearchInfo> newFilter = new List<IMetaSearchInfo>(filter);

    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
  5. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    10 Dec 2010
    Link to this post
    Thank you for your response. I am new to ASP.NET and SiteFinity. So I'm a bit lost by your explanation.
    Where exactly would I put this class code? And would it fix the issue of multiple URLS being generated for one news item?


  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2010
    Link to this post
    Hello Dan,

    You can take a look at this post.

    The class can be added to App_Code or you can compile it to a class library. Using a filter you can add only items from a certain category or filter the entire data of news based on a metakey or property.


    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
  7. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    10 Dec 2010
    Link to this post
    Thanks for helping. I looked at the link you provided but i couldn't see how it related to my problem.

    I understand the class file I need to drop in should be in App_Code. What should I call this file? Is the code below all I need to paste into the file? 

    IMetaSearchInfo[] filter = this.manager.GetFilter(this.FilterExpression);
    List<IMetaSearchInfo> newFilter = new List<IMetaSearchInfo>(filter);

    Again, i'm not an ASP.NET expert. I am helping someone with their SiteFinity site and just trying to get this duplicate news item resolved for them. 

    Thanks
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2010
    Link to this post
    Hi Dan,

    The other post shows how to crate a custom link so you can reuse a code from there so I would say that it is related to your problem, because you need to build a custom index otherwise I would not point to you this direction.
    Creating a custom index is not something trivial and I suggest that you should take watch this webinar.

    Once again the index does not filter by category. It gets all news items regardless of the NewsView control and its filtering.

    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
  9. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    10 Dec 2010
    Link to this post
    Thanks for the link to the webinar video.  I understand the search index does not filter by news category, but this still seems like an overlooked bug within Sitefinity. I cannot imagine anyone would want duplicate results in their searches. I should be able to have more than one news view within my site and not have a news item appear multiple times in my search.
  10. Dan
    Dan avatar
    23 posts
    Registered:
    04 Dec 2010
    10 Dec 2010
    Link to this post
    Ok, i got the code from another forum post. I have placed it in App Code and i think i'm nearly there. However, I am getting an error.
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 32:         if (ContentManager.Providers[DataProviderName].MetaKeys.ContainsKey("Category"))
    Line 33:         {
    Line 34:             List<IMetaSearchInfo> newFilter = new List<IMetaSearchInfo>(filter);
    Line 35:             MetaSearchInfo searchInfo = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", "SomeName", SearchCondition.Equal);
    Line 36:             newFilter.Add(searchInfo);

    The Code:

    using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Telerik.Framework.Search;
    using Telerik.News.WebControls;
    using Telerik.Cms.Web;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using Telerik.News;
     
    public class NewsIndexProviderCustom : Telerik.News.NewsIndexProvider
    {
        public NewsIndexProviderCustom()
        {
            //
            // TODO: Add constructor logic here
            //
        }
      
        public override Telerik.Framework.Search.IIndexerInfo[] GetContentToIndex()
        {
            //return base.GetContentToIndex();
      
            if (this.retrievalMethod != RetrievalMethod.Direct)
                return new IIndexerInfo[0];
      
            if (this.manager == null)
                throw new InvalidOperationException("Manager is null");
      
            IMetaSearchInfo[] filter = this.manager.GetFilter(this.FilterExpression);
      
            if (ContentManager.Providers[DataProviderName].MetaKeys.ContainsKey("Category"))
            {
                List<IMetaSearchInfo> newFilter = new List<IMetaSearchInfo>(filter);
                MetaSearchInfo searchInfo = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", "SomeName", SearchCondition.Equal);
                newFilter.Add(searchInfo);
                filter = newFilter.ToArray();
            }
            IList itemsList = this.manager.GetContent(0, 0, String.Empty, ContentStatus.Published, this.ParentIDs, filter);
      
            List<IContent> lst = new List<IContent>();
            foreach (IContent cnt in itemsList)
            {
                if (!lst.Contains(cnt))
                    lst.Add(cnt);
            }
      
            List<IIndexerInfo> data = new List<IIndexerInfo>(lst.Count);
            foreach (IContent content in lst)
            {
                if (content != null)
                {
                    if (this.manager.Provider.AllowLocalization)
                    {
                        foreach (string lng in content.Languages)
                        {
                            CultureInfo cult = CultureInfo.GetCultureInfo(lng);
                            string path = this.GetItemUrl(content, this.baseUrl, cult);
                            data.Add(this.GetIndexerInfo(path, content, cult));
                        }
                    }
                    else
                    {
                        string path = this.GetItemUrl(content, this.baseUrl, null);
                        data.Add(this.GetIndexerInfo(path, content));
                    }
                }
            }
            return data.ToArray();
        }
         
    }
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Dec 2010
    Link to this post
    Hello Dan,

    You are missing the references to

    System.Collections.Generic and Telerik.Cms.Engine.

    System.Collections.Generic.List<Telerik.Cms.Engine.IMetaSearchInfo> ...

    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
11 posts, 0 answered