public void AndMergeTest_SomeOverlap_ReturnsMatchingPostings()
        {
            //Test with two
            IList <Posting> first  = UnitTest.GeneratePostings("(1,[0,5]), (2,[10,99])");
            IList <Posting> second = UnitTest.GeneratePostings("(1,[2,9]), (3,[77])");

            IList <Posting> result = Merge.AndMerge(first, second);

            result.Should().HaveCount(1, "because only 1 posting overlap");

            //Test with list
            List <IList <Posting> > list = new List <IList <Posting> > {
                UnitTest.GeneratePostings("(1,[0,5]), (2,[8])"),
                UnitTest.GeneratePostings("(2,[1,9])"),
                UnitTest.GeneratePostings("(1,[3]), (2,[4]), (3,[9])"),
                UnitTest.GeneratePostings("(2,[7]), (3,[7])")
            };

            result = Merge.AndMerge(list);
            result.Should().HaveCount(1, "because only 1 posting overlap");
        }
        public void AndMergeTest_AllOverlap_ReturnsOneOfThePostingLists()
        {
            //Test with two
            IList <Posting> first  = UnitTest.GeneratePostings("(1,[0,5]), (2,[10,99])");
            IList <Posting> second = UnitTest.GeneratePostings("(1,[2,9]), (2,[77])");

            IList <Posting> result = Merge.AndMerge(first, second);

            result.Should().HaveCount(first.Count, "because all overlaps");

            //Test with list
            List <IList <Posting> > list = new List <IList <Posting> > {
                UnitTest.GeneratePostings("(1,[0,5]), (2,[1])"),
                UnitTest.GeneratePostings("(1,[3,6]), (2,[7])"),
                UnitTest.GeneratePostings("(1,[4]), (2,[3,6])"),
                UnitTest.GeneratePostings("(1,[2,8]), (2,[9])")
            };

            result = Merge.AndMerge(list);
            result.Should().HaveCount(2, "because all in the list overlaps");
        }
        public void AndMergeTest_NoOverlap_ReturnsEmpty()
        {
            //Test with two
            IList <Posting> first  = UnitTest.GeneratePostings("(1,[0,5]), (3,[10])");
            IList <Posting> second = UnitTest.GeneratePostings("(2,[2,9]), (4,[77])");

            IList <Posting> result = Merge.AndMerge(first, second);

            result.Should().BeEmpty("because nothing overlaps between the two");
            result.Should().HaveCount(0, "because nothing overlaps between the two");

            //Test with list
            List <IList <Posting> > list = new List <IList <Posting> > {
                UnitTest.GeneratePostings("(1,[0,5]), (2,[4])"),
                UnitTest.GeneratePostings("(2,[6]), (3,[7])"),
                UnitTest.GeneratePostings("(1,[2]), (3,[1,9])"),
                UnitTest.GeneratePostings("(3,[8]), (4,[6])")
            };

            result = Merge.AndMerge(list);
            result.Should().BeEmpty("because nothing in the list overlaps");
        }
        /// <summary>
        /// Gets Postings of documents which contain the similar sounding author names.
        /// </summary>
        /// <param name="nameQuery">author name to find documents</param>
        /// <returns>postings with document and empty positions</returns>
        public IList <Posting> GetPostings(string nameQuery)
        {
            IList <Posting> result = new List <Posting>();

            //Check author name can contains multiple terms
            string[] terms = nameQuery.Split(' ');
            //remove the empry string in the string array
            terms = terms.Where(x => !string.IsNullOrEmpty(x)).ToArray();

            List <IList <Posting> > list = new List <IList <Posting> >();

            foreach (string term in terms)
            {
                string soundCode = ParseToSoundex(term);

                List <int> docIDs;
                try
                {
                    List <int> temp = this.map.Get(soundCode);
                    docIDs = temp == default(List <int>) ? new List <int>() : temp;
                }
                catch (KeyNotFoundException)
                {
                    continue;
                }

                IList <Posting> postings = new List <Posting>();
                foreach (int id in docIDs)
                {
                    postings.Add(new Posting(id, new List <int>()));
                }
                list.Add(postings);
            }

            result = Merge.AndMerge(list);
            return(result);
        }