Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Best pratice for including information that does not exist on Content

Vote:
 

I wounder what is the best way to include content that should be searchable but does not exist on the content. Take this for example.

I have a ContentType that looks like this:

    /// 
    /// Used primarily for publishing news articles on the website
    /// 
    [SiteContentType(
        GroupName = Global.GroupNames.News,
        GUID = "AEECADF2-3E89-4117-ADEB-F8D43565D2F4")]
    [SiteImageUrl(Global.StaticGraphicsFolderPath + "page-type-thumbnail-article.png")]
    public class ArticlePage : StandardPage
    {
        [Display(Name = "Location",
             Description = "Select location for this article",
             Order = 50)]
        [SelectOne(SelectionFactoryType = typeof(LocationSelectionFactory))]
        public virtual string Location { get; set; }
    }

Location here will be an integer (id) that is a link to another system and we want to save that in the property.

But we want the visitors to be able to search on the name of the location and get all the articles for that location.

So... the ContentType will have a property with a value like this "23", but we want the visitors to be able to search for its name (like New York).

The way we have solved it (but I think is not the best way) is to add another property on the PageType that looks like this:

public virtual string IndexedLocation
        {
            get
            {
                var location = GetLocation(Location);

                if (location != null)
                {
                    return location.Title;
                }
                return null;
            }
        }

It does not feel good to do this, mainly because I am putting logics inside the model and that is not good and it will be run every time this page will be requested even though it is only interesting when adding/updating it to the index.

Are there any other better way to do this?

#121457
May 11, 2015 16:26
Vote:
 

Hello Henrik,

You can create an extension method for ArticlePage type and call it LocationTitle, for example. Then use it to configure a convention in the initialization module:

SearchClient.Instance.Conventions
    .ForInstancesOf<ArticlePage>()
    .IncludeField(x => x.LocationTitle());
#121459
May 11, 2015 16:57
Vote:
 

Thanks Sergii

I will try it out

#121460
May 11, 2015 17:00
Vote:
 

It workes great!
Thanks Sergii

#121461
May 11, 2015 17:24
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.