Sorry if this has already been posted; "like" is a really difficult word to search for :)
I'm running 6.1.6 and have created a Partial View Macro that produces a table based on child pages. I have a requirement that this table can be filtered by the user. At the moment I have code similar to this which allows the child pages' names to be filtered:
var pages = CurrentPage.Children(); var filteredPages = pages.Where("name == \"nameGoesHere\""); // do stuff with filteredPages.name, filteredPages.url etc.
This works when the full page name has been entered, but I need to be able to handle partial names too. If it were SQL then I'd do something like this:
var filteredPages = pages.Where("name LIKE \"%nameGoesHere%\"");
This is the sort of thing that I'd think was really simple, but I'm having no luck finding any documentation on it (maybe it's so blindingly obvious that it wasn't worth documenting!)
What's the easiest way to accomplish something like this?
I think maybe the search methods should do this, unfortunately I don't think they are documented yet but give them a try:
E.g.
var filteredDescendantPages = CurrentPage.AncestorOrSelf(1).SearchDescendants("links");
var filteredChildPages = CurrentPage.AncestorOrSelf(1).SearchChildren("links");
I think you will need to construct a Examine ISearchCriteria but it does get a little complex, this might be a starting point though:
var provider = ExamineManager.Instance.DefaultSearchProvider;
var criteria = provider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
var terms = new[] { "links" };
var fields = new List<string> { "nodeName" };
criteria.GroupedOr(fields, terms);
var filteredChildPages = Model.Content.AncestorOrSelf(1).Search(criteria);
Thanks for that; unfortunately I've been dumped with some other work so it might be a few days before I can try it, but I'll let you know how I get on. Looks like I need to read about Examine! :)
How can I implement "like"?
Sorry if this has already been posted; "like" is a really difficult word to search for :)
I'm running 6.1.6 and have created a Partial View Macro that produces a table based on child pages. I have a requirement that this table can be filtered by the user. At the moment I have code similar to this which allows the child pages' names to be filtered:
This works when the full page name has been entered, but I need to be able to handle partial names too. If it were SQL then I'd do something like this:
This is the sort of thing that I'd think was really simple, but I'm having no luck finding any documentation on it (maybe it's so blindingly obvious that it wasn't worth documenting!)
What's the easiest way to accomplish something like this?
Thanks :)
Hi Chris,
I think maybe the search methods should do this, unfortunately I don't think they are documented yet but give them a try:
E.g.
Jeavon
Thanks, that's got me on the right track, but is there any way to specify which fields should be searched?
Hi Chris,
I think you will need to construct a Examine ISearchCriteria but it does get a little complex, this might be a starting point though:
Jeavon
Hi Chris,
I've been thinking about this and have improved the snippet to be a bit more useful?
I actually think that the SearchChildren and SearchDescendants methods should have some overloads so you could do something like:
Or
Jeavon
Thanks for that; unfortunately I've been dumped with some other work so it might be a few days before I can try it, but I'll let you know how I get on. Looks like I need to read about Examine! :)
I had some time today and got it working! Thanks so much!
For the benefit of anyone else with a similar issue, here's what I ended up doing:
is working on a reply...