1
votes

Can I use XPath Builder under Developer Center inside Sitecore Shell to select all items below a node and filter it by if field exists, single line text field? With a fast query (not limited by the Query.MaxItems setting)

for example somethings like: fast://sitecore/content//*[@#my field# != '' ]

But this query make no difference between empty and field does not exist, I want the empty ones in my result and not the items where the field not exsist.

1
Don't think its possible with sitecore query. You may have to use linq to sitecore instead.xoail
I don't think is posible, why you don't query by template? You know all the templates that contains your field.Vlad Iobagiu
Right, by query the templates I can do my query.Jan Bluemink

1 Answers

2
votes

Here is an article talking about how to fix Fast query to search by field: http://www.agehrke.com/2014/12/fixing-sitecore-fast-query-querying-by-field-id/

Otherwise something like this would work:

   Item[] items = Sitecore.Context.Database.SelectItems("/sitecore/content//*[@MyField != '']")

Or use an index:

public IEnumerable<SearchExample> Example()
        {
            using (var context = ContentSearchManager.GetIndex(GlobalIndex).CreateSearchContext())
            {
                var query = context.GetQueryable<SearchExample>()
                    .Where(item => item.MyField != null)                    
                    .ToList();
                return query;
        }
    }