Problems with ItemsFind.....

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

 N2.Find.Items.Where
      .Detail("Tags")
      .In<int>(tagIDs)
      .Select()
      .ToList<ContentItem>();

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?
Coordinator
Mar 2, 2009 at 9: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 9:40 PM
Edited Mar 2, 2009 at 9: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.
Coordinator
Mar 2, 2009 at 9: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 9:52 PM
Edited Mar 2, 2009 at 9:54 PM
Could you give me more detailed info about operating with query, what's the type of this variable.
Coordinator
Mar 2, 2009 at 10:13 PM
It's probably something like:

    var query = Find.Items.Where
Mar 2, 2009 at 10:28 PM
Thanx it works...
Mar 26, 2009 at 1: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
                               .Where;
                             //.Type.Eq(typeof(T))
                             //.Select<GalleryItem>;

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

            List<GalleryItem> allImages = query;
Mar 27, 2009 at 4: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
                .Type.Eq(typeof(T))
                .Filters(filters)
                .FirstResult(startIndex*perPage)
                .MaxResults(perPage)
                .OrderBy.Published.Desc
                .Select<T>();

Mar 30, 2009 at 12: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 12:40 PM
This is only a sample, you can adopt it as you wish.

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