コード例 #1
0
ファイル: BPlusTreeTest.cs プロジェクト: thoward/bsharptree
        public void TestSomeExamples()
        {
            IIndex<int, string, string> index = new SimpleIndex();
            IInverter<string, string> inverter = new StringInverter();

            index.AddItem(new mockindex.Document { Id = 1, Value = "A B C D E F" }, inverter);
            index.AddItem(new mockindex.Document { Id = 2, Value = "B C" }, inverter);
            index.AddItem(new mockindex.Document { Id = 3, Value = "A B E F" }, inverter);
            index.AddItem(new mockindex.Document { Id = 4, Value = "C D E F" }, inverter);
            index.AddItem(new mockindex.Document { Id = 5, Value = "E F" }, inverter);
            index.AddItem(new mockindex.Document { Id = 6, Value = "D D D D E F" }, inverter);
            index.AddItem(new mockindex.Document { Id = 7, Value = "D E F" }, inverter);
            //            index.AddDocument(new Document { DocID = 8, Text = "A B C D E F" }, inverter);
            //            index.AddDocument(new Document { DocID = 9, Text = "A B C D E F" }, inverter);
            index.AddItem(new mockindex.Document { Id = 10, Value = "A B" }, inverter);
            index.AddItem(new mockindex.Document { Id = 11, Value = "E E E A B" }, inverter);
            index.AddItem(new mockindex.Document { Id = 12, Value = "C A B" }, inverter);

            foreach (var result in index.Inversions.Documents(DocumentComparer.Default))
            {
                Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            }

            Console.Out.WriteLine("-------------------------");
            Console.Out.WriteLine("find documents that match clause A and clause B (other clauses don't affect matching) ");
            Console.Out.WriteLine("-------------------------");
            var queryText = "A AND B OR C OR D OR E OR F";
            DoQuery(index, queryText, inverter);

            queryText = "+A +B C D E F";
            DoQuery(index, queryText, inverter);

            Console.Out.WriteLine("-------------------------");
            Console.Out.WriteLine("find documents matching at least one of these clauses ");
            Console.Out.WriteLine("-------------------------");
            queryText = "C OR D OR E OR F";
            DoQuery(index, queryText, inverter);

            queryText = "C D E F";
            DoQuery(index, queryText, inverter);

            Console.Out.WriteLine("-------------------------");
            Console.Out.WriteLine("find documents that match A, and match one of B, C, D, E, or F ");
            Console.Out.WriteLine("-------------------------");
            queryText = "A AND (B OR C OR D OR E OR F)";
            DoQuery(index, queryText, inverter);

            queryText = "+A +(B C D E F)";
            DoQuery(index, queryText, inverter);

            Console.Out.WriteLine("-------------------------");
            Console.Out.WriteLine("find documents that match at least one of C, D, E, F, or both of A and B");
            Console.Out.WriteLine("-------------------------");
            queryText = "(A AND B) OR C OR D OR E OR F ";
            DoQuery(index, queryText, inverter);

            queryText = "(+A +B) C D E F";
            DoQuery(index, queryText, inverter);
        }
コード例 #2
0
ファイル: BPlusTreeTest.cs プロジェクト: thoward/bsharptree
        public void TestBuildQuery()
        {
            var index = new SimpleIndex();
            index.AddItem(new mockindex.Document { Id = 1, Value = "foo one" });
            index.AddItem(new mockindex.Document { Id = 2, Value = "two" });
            index.AddItem(new mockindex.Document { Id = 3, Value = "three two" });
            index.AddItem(new mockindex.Document { Id = 4, Value = "four six" });
            index.AddItem(new mockindex.Document { Id = 5, Value = "five two three" });
            index.AddItem(new mockindex.Document { Id = 6, Value = "five" });
            index.AddItem(new mockindex.Document { Id = 7, Value = "five two" });
            index.AddItem(new mockindex.Document { Id = 8, Value = "five three" });
            index.AddItem(new mockindex.Document { Id = 9, Value = "three" });
            index.AddItem(new mockindex.Document { Id = 10, Value = "four two three" });

            foreach (var result in index.Inversions.Documents(DocumentComparer.Default))
            {
                Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            }

            Console.Out.WriteLine("==== five OR (two -three)");
            var rootQuery = index.QueryExecutor.Should("five");
            var subQuery = index.QueryExecutor.Should("two").MustNot("three");

            var finalQuery = rootQuery.Should(subQuery);

            foreach (var result in finalQuery.Invertables())
            {
                Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            }

            //var queryText = "-six foo four +one";
            var queryText = "+(five (four AND two)) +(three two nothing here to see) -two";

            DoQuery(index, queryText, new StringInverter());

            //Console.Out.WriteLine("=== graph for " + queryText + "===");
            //var parser = new Parser(new Scanner());
            //var tree = parser.Parse(queryText);

            //var rootExpressionNode =
            //    tree.Nodes.FirstOrDefault(a => a.Token.Type == TokenType.Start).Nodes.FirstOrDefault(
            //        a => a.Token.Type == TokenType.Expression);

            //if(default(ParseNode) == rootExpressionNode)
            //    throw new Exception("No query in parse tree.");

            //var rootQueryClause = AnalyzeQueryNode(rootExpressionNode, );

            //var queryExecutor = index.GetQueryExecutor(rootQueryClause);

            //Console.Out.WriteLine("=== results for: " + queryText + " ===");
            //foreach (var result in queryExecutor.Invertables())
            //{
            //    Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            //}

            //foreach (var leafnode in FindLeafNodes(tree))
            //{
            //    // build leaf node
            //    // TERM|QUOTEDTERM OP? (TERM|QUOTEDTERM)?
            //    for (int i = 0; i < leafnode.Nodes.Count; i+=2)
            //    {
            //        var termExp = leafnode.Nodes[i];
            //        var termNode = termExp.Nodes.Find(a => a.Token.Type == TokenType.TERM || a.Token.Type == TokenType.QUOTEDTERM);
            //        if (null == termNode) throw new Exception("WTF");
            //        var term = termNode.Token.ToString();

            //        var prefixNode = termExp.Nodes.Find(a => a.Token.Type == TokenType.PREFIX);
            //        if (null != prefixNode)
            //        {

            //        }
            //    }

            //    PrintParseNode(leafnode);
            //}
        }
コード例 #3
0
ファイル: BPlusTreeTest.cs プロジェクト: thoward/bsharptree
        public void TestMockLinq()
        {
            var index = new SimpleIndex();
            index.AddItem(new mockindex.Document { Id = 1, Value=  "foo one" });
            index.AddItem(new mockindex.Document { Id = 2, Value = "two" });
            index.AddItem(new mockindex.Document { Id = 3, Value = "three two" });
            index.AddItem(new mockindex.Document { Id = 4, Value = "four six" });
            index.AddItem(new mockindex.Document { Id = 5, Value = "five two three" });
            index.AddItem(new mockindex.Document { Id = 6, Value = "five" });
            index.AddItem(new mockindex.Document { Id = 7, Value = "five two" });
            index.AddItem(new mockindex.Document { Id = 8, Value = "five three" });
            index.AddItem(new mockindex.Document { Id = 9, Value = "three" });

            foreach (var result in index.Inversions.Documents(DocumentComparer.Default))
            {
                Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            }

            foreach (var term in index.Inversions)
            {
                //Console.Out.WriteLine("term: {0}, docs: {1}", term.Text, string.Join(",", term.Documents.Select(a=>a.DocID.ToString()).ToArray()));
            }
            //.ButNot("three")

            Console.Out.WriteLine("");

            Console.Out.WriteLine("==== five OR two OR three ");

            var results = index.QueryExecutor.MustHave("five").Should("two").Should("three");
            foreach (var result in results.Invertables())
            {
                Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            }

            Console.Out.WriteLine("==== five OR two OR three ");
            var subQuery = index.QueryExecutor.MustHave("two").MustNot("three");
            results = index.QueryExecutor.MustHave("five").Should(subQuery);

            foreach (var result in results.Invertables())
            {
                Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value);
            }
        }