PropertyCriteria for testing field contains some text

Vote:
 
Can you create a PropertyCriteria search criteria for use with DataFactory.Instance.FindPagesWithCriteria to find all pages where a field is not empty? I have a string field that may contain some text and I want to list the pages with some text in this field.
#33036
Sep 30, 2009 11:43
Vote:
 

Not an answer to your question, but -

- personally I would just append a filter to the collection/control instead, which in my opinion allows you to write more flexible and exact omittment queries. (Untested and not optimized) example:

for(int i=e.Pages.Count-1; i>=0; i--)
   if(e.Pages[i]["MyProp"] != null && e.Pages[i]["MyProp"].ToString().Contains("some text"))
      e.Pages.RemoveAt(i);


Regards,
/Marten

#33039
Sep 30, 2009 12:41
Vote:
 
If checking against null is sufficent you should be able to do this in the database by setting the criteria's IsNull property. If you have large amounts of content this will be much faster than filtering. Though you have to try this, I have only used it to find pages with IsNull = true, so it might not work with IsNull = false (which would be equivalent to not setting it I suppose).
#33041
Sep 30, 2009 13:03
Vote:
 

I was trying to avoid getting all pages and then testing the results.

I have tried all permutations that I can think of using the IsNull, and the only result I can get is to return all pages where the field is blank, the opposite of what I want. Changing CompareCondition.Equal to CompareCondition.NotEqual does not change the results.

If IsNull is false, then exception "The crieria value cannot be null or empty. Set the IsNull property to search for null." is returned.

--
PropertyCriteria pageCriteria = new PropertyCriteria();
pageCriteria.Condition = EPiServer.Filters.CompareCondition.Equal;
pageCriteria.Required = true;
pageCriteria.Type = PropertyDataType.String;
pageCriteria.Name = fieldName;
pageCriteria.IsNull = true;
--

 

#33044
Edited, Sep 30, 2009 13:46
Vote:
 

You could do something like in this post, but that would make your query in the database a horror instead, so there might be a performance impact there instead:

http://world.episerver.com/Forum/Pages/Thread.aspx?id=13184&epslanguage=en

I'm thinking, what happens if you just add a criteria for one character and set Required to false? Will that yield all pages or will it skip the null pages?

#33046
Sep 30, 2009 13:52
Vote:
 

I tried the following, which did not return any found pages, the letter "b" does not appear in the "fieldName".
--
PropertyCriteria pageCriteria = new PropertyCriteria();
pageCriteria.Condition = EPiServer.Filters.CompareCondition.Contained;
pageCriteria.Required = false;
pageCriteria.Type = PropertyDataType.String;
pageCriteria.Name = fieldName;
pageCriteria.Value = "b";
pageCriteria.Required = false;
--

I also thought of trying saying that comparison was boolean, in case some text present was treated as true and no text as false, but all variations of CompareCondition.Equals and CompareCondition.NotEquals and pageCriterial.Value of "true" or "false" returned no results.

A less database horror version would be to test for vowels (a, e, i, o and u), as in my case they will be English words so one of these must be present in the word; which is what I am going with for now.

#33052
Sep 30, 2009 15:31
* 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.