This project is read-only.

Problems with ItemsFind.....

Topics: Developer Forum
Mar 2, 2009 at 8:08 PM
That's the way I find items:
 int[] tagIDs = Request.QueryString["tags"].Split(',').Select(x => Int32.Parse(x)).ToArray();


I want this expression to search only items with full tags collection from tagIDs, but results shows that items found not with full tags collection (with one tag from tagIDs).
What's the problem, how could It been solved?
Mar 2, 2009 at 10:28 PM
Could you expand on what you mean with full tags collection? This should find items where one of the tags is in the array. Perhaps this test fixture could be helpful.
Mar 2, 2009 at 10:40 PM
Edited Mar 2, 2009 at 10:46 PM
I just want to find Item wich have all tags ids (int its DetailCollection) from tagIDs array, but my result shows that search find Items where only one tag from tagIDs was met.
Mar 2, 2009 at 10:48 PM
I think you shouldn't use In. It matches "any of these". This could work:

foreach(int id in tagIDs)
    query = query.And.Details("Tags").Eq(id);
Mar 2, 2009 at 10:52 PM
Edited Mar 2, 2009 at 10:54 PM
Could you give me more detailed info about operating with query, what's the type of this variable.
Mar 2, 2009 at 11:13 PM
It's probably something like:

    var query = Find.Items.Where
Mar 2, 2009 at 11:28 PM
Thanx it works...
Mar 26, 2009 at 2:43 PM
SerZHio_hiper, could you please post your code in full. I'm trying to implement this but I don't understand it...
This is kind of what I'm tying to do:

            string[] tags = new string[] { "car", "horse" };

            var query = N2.Find.Items

            foreach (string tagString in tags) {
               query = query.And.Where.Detail("Tags").Eq(tagString);                

            List<GalleryItem> allImages = query;
Mar 27, 2009 at 5:04 PM
Take it:

            var query = N2.Find.Items.Where;
            foreach (int id in (int[])getTagIdsFromQueryString("tags"))
            { query = query.Detail("Tags").Eq(id).And; }
            return query

Mar 30, 2009 at 1:32 PM
Hmm, I made a mistake. Tags in my case are items themselves and not details. (because besides a tagname each tag has a tag category as well).
Each galleryitem has a collection of Tags. Is there a way to get galleryitems by tagname? Of course I could get all galleryitems first and then filter out the results but that isn't a very clean solution isn't it?

Mar 30, 2009 at 1:40 PM
This is only a sample, you can adopt it as you wish.

Mar 30, 2009 at 1:53 PM
I understand the example but I can't find how to adopt it to my specific case.