Search with Creteria

Vote:
 

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.

#46020
Nov 25, 2010 7:29
Vote:
 

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
    }
}); 

#46031
Nov 25, 2010 9:29
Vote:
 

Hi,

Thanks for the reply.

But what about those pages that dont have this property.can these pages also include in that.

#46036
Nov 25, 2010 10:36
Vote:
 

Yes, that should also match pages of page types that don't even have the property "ExcludeFromSearch".

#46039
Nov 25, 2010 10:41
Vote:
 

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 .

#46041
Nov 25, 2010 11:01
Vote:
 

Comment out the Type aswell.

#46043
Nov 25, 2010 11:06
Vote:
 

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.

#46044
Nov 25, 2010 11:16
Vote:
 

That is very strange. What if you do it exactly as in my example?

#46045
Nov 25, 2010 11:20
Vote:
 

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.

#46046
Nov 25, 2010 11:29
Vote:
 

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.

#46047
Nov 25, 2010 11:31
Vote:
 

is there any way by which i get all the pages that dont have the property exclude from search

#46048
Nov 25, 2010 11:33
Vote:
 

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.

#46050
Nov 25, 2010 11:37
Vote:
 
#46051
Nov 25, 2010 11:44
Vote:
 
#46052
Nov 25, 2010 12:27
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.