Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Only index objects with specific property value

Vote:
 

I have an index in dire need of some cleaning due to lack of free space.

I want to index only objects of a specific type with correct value on a property.

I have built an extension method for GenericMedia to filter if it is of a certain type:

public static bool IsBlue(this T content)
		{
			var iContent = content as IContent;

			if (iContent != null)
			{
				//fancy logic
				return boolean;
			}

			return false;
		}

Initializing:

SearchClient.Instance.Conventions.ForInstancesOf().IncludeField(x => x.IsBlue());

This property is used when filtering the search.

Since only a fraction of the indexed Generic Media objects actually have true value on on the property IsBlue, I see no reason to index those who do not.

How do I index only these blue objects?

I was thinking of something along these lines:

ContentIndexer.Instance.Conventions.ForInstancesOf().ShouldIndex(x => false);
			ContentIndexer.Instance.Conventions.ForInstancesOf().Where(x => x.IsBlue()).ShouldIndex(x => true);

But, the syntax is all wrong. So, do any you know how to solve this problem?

Thanks for helping.

#144284
Feb 10, 2016 14:19
Vote:
 

Hi Hannes,

Does it work if you create an extension method like this:

public static class GenericMediaExtensions
{
    public static bool IsBlue(this GenericMedia content)
    {
        // fancy logic
    }
}

And then use this:

ContentIndexer.Instance.Conventions
                .ForInstancesOf<GenericMedia>()
                .ShouldIndex(x => x.IsBlue());
#144285
Feb 10, 2016 14:53
Vote:
 

Great idea, I will try it and get back to you.

#144518
Feb 15, 2016 10:18
* 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.