Trying to build a search query where results are only returned if the item contains a particular field - I can't exclude an empty field as if it's empty it won't be in the index, which means this won't work:
var criteria = searchProvider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content)
.NodeTypeAlias("profile")
.And()
.Field("mainImage", "*")
.Compile();
What I need is all profile nodes with an image assigned - if my index has 1000 profiles but only half have an image, I don't want to grab them all via Examine, then filter the results to exclude the image-less nodes, I just want the 500 back from Examine
Any suggestions would be great. Probably missing something really simple...
EDIT: I'm using .Range("mainImage", "0", "999999"), which seems to be doing to trick
The range is good working solution. The other thing you could do if you wanted is that during gatheringnode data if the image is not set then set the value to say -1 or some other fake value then in your query you could do:
var criteria = searchProvider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content)
.NodeTypeAlias("profile")
.And().Not()
.Field("mainImage", "-1")
.Compile();
Syntax might a bit off but you get the picture so that would also return all items with an image. However I like the range.
Examine Fluent API - search for presence of field
Trying to build a search query where results are only returned if the item contains a particular field - I can't exclude an empty field as if it's empty it won't be in the index, which means this won't work:
What I need is all profile nodes with an image assigned - if my index has 1000 profiles but only half have an image, I don't want to grab them all via Examine, then filter the results to exclude the image-less nodes, I just want the 500 back from Examine
Any suggestions would be great. Probably missing something really simple...
EDIT: I'm using .Range("mainImage", "0", "999999"), which seems to be doing to trick
Nathan,
The range is good working solution. The other thing you could do if you wanted is that during gatheringnode data if the image is not set then set the value to say -1 or some other fake value then in your query you could do:
Syntax might a bit off but you get the picture so that would also return all items with an image. However I like the range.
Regards
Ismail
is working on a reply...