1
Vote

Using Union and Intersect in WhereThroughIndex in i4o v2

description

In v2 branch in WhereThroughIndex results from different indexes are combined using Union and Intersect. However Union and Intersect, while operating on IEnumerable interface, are set operations. They return sets, and because of that they remove duplicates. So, there's a bug: if original sequence contains duplicates, result returned from WhereThroughIndex with complex query is not.

comments

staxmanade wrote Feb 15, 2011 at 5:24 AM

I'm struggling to see what your issues is. Any you can produce a test?

Gregory1981 wrote Feb 15, 2011 at 4:47 PM

The issue is that WhereThroughIndex sometimes returns duplicates and sometimes not, which is inconsistent and confusing.
Here it is:
    [Test]
    public void SuperComplexQueryWithDuplicates()
    {

        var single = new SimpleClass { Name = "Jason Jarett", Age = 25, FavoriteColor = Color.Aqua };
        SimpleClass[] someItems = {
                                    single,
                                    single,
                                    single,
                                    single                                          
                                  };
        var indexSpec = IndexSpecification<SimpleClass>.Build()
            .With(person => person.FavoriteColor)
            .And(person => person.Age)
            .And(person => person.Name);
        var theIndexSet = new IndexSet<SimpleClass>(someItems, indexSpec);
        var result =
            from item in theIndexSet
            where item.Name == "Jason Jarett" && item.Age == 25 && item.FavoriteColor == Color.Aqua
            select item;
        Assert.AreEqual(4, result.Count());
    }

wrote Feb 14, 2013 at 3:52 AM