Example #1
0
        public PostingArray Union(PostingArray other, bool max)
        {
            int min = Math.Max(this.list.Length, other.list.Length);

            if (this.list.Length == 0)
            {
                return(other);
            }
            if (other.list.Length == 0)
            {
                return(this);
            }
            List <Posting> result = new List <Posting>(min);
            int            i0     = 0;
            int            i1     = 0;
            Posting        item0  = this.list[i0];
            Posting        item1  = other.list[i1];

            while (i0 < this.list.Length && i1 < other.list.Length)
            {
                if (i0 == this.list.Length)
                {
                    result.Add(item1);
                    i1 = other.Next(i1, out item1);
                }
                else if (i1 == other.list.Length)
                {
                    result.Add(item0);
                    i0 = this.Next(i0, out item0);
                }
                else if (item0.Document == item1.Document)
                {
                    if (max)
                    {
                        result.Add(new Posting(item0.Document, Math.Max(item0.Bm25F, item1.Bm25F)));
                    }
                    else
                    {
                        result.Add(new Posting(item0.Document, item0.Bm25F + item1.Bm25F));
                    }

                    i0 = this.Next(i0, out item0);
                    i1 = other.Next(i1, out item1);
                }
                else if (item0.Document.hash < item1.Document.hash)
                {
                    result.Add(item0);
                    i0 = this.Next(i0, out item0);
                }
                else
                {
                    result.Add(item1);
                    i1 = other.Next(i1, out item1);
                }
            }

            return(new PostingArray(result.ToArray()));
        }
Example #2
0
        public PostingArray Intersection(PostingArray other, bool max)
        {
            int min = Math.Min(this.list.Length, other.list.Length);

            if (min == 0)
            {
                return(new PostingArray(new Posting[0]));
            }

            int            span0  = this.list.Length / other.list.Length;
            int            span1  = other.list.Length / this.list.Length;
            List <Posting> result = new List <Posting>(min / 10 + 1);
            int            i0     = 0;
            int            i1     = 0;
            Posting        item0  = this.list[i0];
            Posting        item1  = other.list[i1];

            while (i0 < this.list.Length && i1 < other.list.Length)
            {
                if (item0.Document == item1.Document)
                {
                    if (max)
                    {
                        result.Add(new Posting(item0.Document, Math.Max(item0.Bm25F, item1.Bm25F)));
                    }
                    else
                    {
                        result.Add(new Posting(item0.Document, item0.Bm25F + item1.Bm25F));
                    }
                    i0 = this.Next(i0, out item0);
                    i1 = other.Next(i1, out item1);
                }
                else if (item0.Document.hash < item1.Document.hash)
                {
                    i0 = this.SkipAhead(i0, span0, item1.Document, out item0);
                }
                else
                {
                    i1 = other.SkipAhead(i1, span1, item0.Document, out item1);
                }
            }

            return(new PostingArray(result.ToArray()));
        }