Esempio n. 1
0
        public void MemUseTest()
        {
            Index index = new Index("MemTest");
            int   N     = 1000;

            index.AddDataSource(new SamePageDataSource(N));
            index.CreateAsync().ContinueWith((i) => { Directory.Delete("MemTest", true); });
            Thread.Sleep(3000);
            long startMem = GC.GetTotalMemory(false);

            Task <long> .Run(() =>
            {
                long maxmem = 0;
                while (index.IsCreating)
                {
                    long l
                        = GC.GetTotalMemory(false);
                    if (l > maxmem)
                    {
                        maxmem = l;
                    }
                    Thread.Sleep(100);
                }
                return(maxmem);
            }).ContinueWith((i) => { Assert.True(i.Result - startMem < 10000000); }).Wait();
        }
Esempio n. 2
0
        public async Task CoordTest()
        {
            using (Index index = new Index())
            {
                index.WorkPath = "CoordTest\\";
                int N = 1000;
                index.AddDataSource(new TestDataSource(N));
                index.Stemmers.Clear();
                await index.CreateAsync();

                Assert.False(index.IsCreating);
                Assert.True(index.CanSearch);

                string[] words = { "and", "tupman", "everybody", "old" };

                // coordinate test
                foreach (string word in words)
                {
                    List <int> pos = new List <int>();
                    foreach (Match m in Regex.Matches(TestText1.ToLower(), @"\b" + word + @"\b"))
                    {
                        pos.Add(m.Index);
                    }
                    Index.SearchResult res = index.Search(word);
                    Assert.Equal(2 * N, res.foundPages.Count);
                    Assert.Equal(pos.Count, res.foundPages[0].pos.Count);
                    foreach (var p in res.foundPages)
                    {
                        Assert.True(pos.SequenceEqual(p.pos));
                    }
                }
            }
            Directory.Delete("CoordTest\\", true);
        }
        public IActionResult New(SessionIndexModel model)
        {
            Index index = createIndexForUser();

            ViewData.Add("Docodo", docodo.getVersion());
            ViewResult res = View(new SessionIndexModel(index));

            ViewBag.Languages = docodo.getLanguages();

            switch (model.Type)
            {
            case SessionIndexModel.TypeEnum.Web:

                WebDataSource web = new WebDataSource("web", model.Path);
                web.MaxItems = 20;
                index.AddDataSource(web);
                index.CreateAsync();
                break;

            default:
                ViewData.Add("Error", $"Data Source {model.Type} is not supported");
                break;
            }


            return(res);
        }
Esempio n. 4
0
        public async Task PageTextTest()
        {
            int N = 10;
            SamePageDataSource ds = new SamePageDataSource(N);

            using (Index index = new Index("PageTextTest"))
            {
                index.AddDataSource(ds);
                await index.CreateAsync();

                Index.SearchResult res = index.Search("\"old lady\"");
                Assert.Contains(Index.SearchResult.BEGIN_MATCHED_SYMBOL + "old" + Index.SearchResult.END_MATCHED_SYMBOL, res.foundPages[0].text);
                res = index.Search("Test");
                Assert.Contains(Index.SearchResult.BEGIN_MATCHED_SYMBOL + "Test" + Index.SearchResult.END_MATCHED_SYMBOL, res.foundDocs.First().headers["Name"]);
            }
            Directory.Delete("PageTextTest", true);
        }
Esempio n. 5
0
        public async Task VocabTest()
        {
            using (Index index = new Index())
            {
                index.WorkPath = "VocabTest\\";
                int            Npages = 100;
                TestDataSource ds     = new TestDataSource(Npages);
                index.AddDataSource(ds);
                index.MaxDegreeOfParallelism = 1;
                await index.CreateAsync();

                Assert.False(index.IsCreating);
                Assert.True(index.CanSearch);

                Vocab voc = new Vocab();
                voc.Add("and", 1);
                voc.Add("end", 3);
                voc.Add("old", 2);
                voc.Add("the", 6);
                voc.Add("them", 5);
                voc.Add("then", 4);
                voc.Range = ('a', 'z');
                voc.Name  = "en";

                using (Index vocindex = new Index("VocabTest\\vocindex\\"))
                {
                    vocindex.AddDataSource(ds);
                    vocindex.AddVoc(voc);

                    await vocindex.CreateAsync();

                    Assert.Equal(Index.Status.Idle, vocindex.status);
                    Assert.True(vocindex.CanSearch);

                    Assert.Equal(Regex.Matches(TestText1.ToLower(), @"\band\b").Count * 2 * Npages, vocindex["#1"].Count());

                    Assert.True(vocindex.Search("Tupman").Equals(index.Search("Tupman")));
                    Assert.True(vocindex.Search("and").Equals(index.Search("and")));
                    Assert.True(vocindex.Search("Tupman and").Equals(index.Search("Tupman and")));
                }
            }
            Directory.Delete("VocabTest\\", true);
        }
Esempio n. 6
0
        public async Task RequestSyntaxTest()
        {
            using (Index index = new Index())
            {
                index.WorkPath = "RequestSyntaxTest\\";
                //index.Stemmers.Clear();

                int Npages = 100;
                index.AddDataSource(new TestDataSource(Npages));
                await index.CreateAsync();

                Assert.False(index.IsCreating);
                Assert.True(index.CanSearch);

                Index.SearchResult res = index.Search("and (tupman|old)" /*, new Index.SearchOptions(){ dist = 20}*/);

                Assert.Equal(2, res.foundDocs.Count);

                Assert.Equal(Npages, res.foundDocs.First().pages.Count);
                Assert.Equal(Npages, res.foundDocs.Last().pages.Count);

                res = index.Search("and (tupman|old) {Name=Dump}" /*, new Index.SearchOptions(){ dist = 20}*/);

                Assert.Equal(1, res.foundDocs.Count);

                Assert.Equal(Npages, res.foundDocs.First().pages.Count);

                Assert.Equal(res.foundPages[0].pos.Count, res.foundPages[1].pos.Count);
                for (int q = 0; q < 2 * Npages; q++)
                {
                    Assert.Equal(42, res.foundPages[q].pos.Count);
                }
                Assert.True(Enumerable.SequenceEqual(res.foundPages[0].pos, res.foundPages[1].pos));

                res = index.Search("lady old", new Index.SearchOptions()
                {
                    dist = 40
                });
                foreach (int pos in res.foundPages[0].pos)
                {
                    Console.WriteLine("" + pos + ":" + TestText1.Substring(pos, 10));
                }

                Assert.Equal(10, res.foundPages[0].pos.Count);
                res = index.Search("\"lady\" old", new Index.SearchOptions()
                {
                    dist = 40
                });
                Assert.Equal(8, res.foundPages[0].pos.Count);
                res = index.Search("\"old lady\"", new Index.SearchOptions()
                {
                    dist = 40
                });
                Assert.Equal(8, res.foundPages[0].pos.Count);
                res = index.Search("\"lady old\"", new Index.SearchOptions()
                {
                    dist = 40
                });
                Assert.Equal(0, res.foundPages.Count);

                Assert.Equal(12, index.Search("lady (old | young)", new Index.SearchOptions()
                {
                    dist = 40
                }).foundPages[0].pos.Count);
                Assert.Equal(3, index.Search("\"old ladies were\"", new Index.SearchOptions()
                {
                    dist = 40
                }).foundPages[0].pos.Count);
                res = index.Search("\"old lady were\"", new Index.SearchOptions()
                {
                    dist = 40
                });
                Assert.Equal(0, res.foundPages.Count);
                res = index.Search("\"old (lady|ladies) (who|were|looked)\"", new Index.SearchOptions()
                {
                    dist = 40
                });
                //foreach (int pos in res.foundPages[0].pos)
                // Console.WriteLine(""+pos+":"+TestText1.Substring(pos,10));
                Assert.Equal(9, res.foundPages[0].pos.Count);

                res = index.Search("?an?", new Index.SearchOptions()
                {
                    dist = 40
                });
                Assert.Equal(Regex.Matches(TestText1.ToLower(), @"\w*an\w*").Count, res.foundPages[0].pos.Count);
            }
            Directory.Delete("RequestSyntaxTest\\", true);
        }