When a bool property is false it is stored as null in the database. To do searches for nulls, use the IsNull property of the PropertyCriteria:
var matches = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage,
new PropertyCriteriaCollection()
{
new PropertyCriteria()
{
IsNull = true,
Name = "ExcludeFromSearch",
Required = true
}
});
Hi,
Thanks for the reply.
But what about those pages that dont have this property.can these pages also include in that.
Yes, that should also match pages of page types that don't even have the property "ExcludeFromSearch".
I have creted the same
var pubCriteria = new PropertyCriteria
{
Condition = CompareCondition.Equal,
IsNull = true,
Name = "ExcludeFromSearch",
Required = true,
//Value = false.ToString()
Type = PropertyDataType.Boolean
};
but this shows all the pages in my project .
Hi,
Thanks for the reply. The result is bit strange. actually
var pages = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criterias);
in this pages consist of list of those pages having ExcludeFromSearch set to true.
I have used the same ur code
var matches = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage,
new PropertyCriteriaCollection()
{
new PropertyCriteria()
{
IsNull = true,
Name = "ExcludeFromSearch",
Required = true
}
});
still result is same.
Exclude from search is a Selected/nonSelected field with default value is true in my stytem pages and result here shows only those pages.
Did you set the default value after creating the pages? In that case the value is still false in all your pages. Default value is only used to update the GUI when creating a new page, it is not a fallback value for pages that don't have a value set.
is there any way by which i get all the pages that dont have the property exclude from search
Well, then you should have a "IncludeInSearch" property and just search for when it is true... I guess it depends on what you consider the default and thereby what would be the most common.
Hi,
I am quite new to Episerver.I am creating content search . and i want to exclude some pages from my search. I have added a property to those page i want to exclude and added creteria as:
var criterias = new PropertyCriteriaCollection();
var pubCriteria = new PropertyCriteria
{
Condition = CompareCondition.Equal,
Name = "ExcludeFromSearch",
Value = false.ToString(),
Type = PropertyDataType.Boolean,
Required = true
};
criterias.Add(pubCriteria);
var pages = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criterias);
only those pages which I want to exclude from search consist of this property not every page. When I hit search "pages" consist of none or null.