コード例 #1
0
        public void GeneratefTSSearchQuery_singleToken_Test()
        {
            _mockTokenizer.Setup(t => t.Tokens).Returns(new string[] { "SingleToken" });
            _mockTokenizer.Setup(t => t.GetMatchQuery()).Returns("SingleToken*");

            var queryGenerator = new FtsQueryGenerator(_mockGroupingStrategy.Object, _mockTokenizer.Object);
            var expected =
                "SELECT MAX(LocationId) as LocationId, locations.TOWN_NAME,locations.POSTCODE, COUNT(*) as Number " +
                "from locations JOIN locations_srch ON locations.locationId = locations_srch.docid " +
                "WHERE locations_srch MATCH 'SingleToken*' GROUP BY locations.TOWN_NAME,locations.POSTCODE " +
                "ORDER by Number desc LIMIT 100;";

            Assert.Equal(expected, queryGenerator.Generate());
        }
コード例 #2
0
        public void GeneratefTSSearchQuery_multipleTokens_Test()
        {
            _mockTokenizer.Setup(t => t.Tokens).Returns(new string[] { "multiple","Tokens", "Test" });
            _mockTokenizer.Setup(t => t.GetMatchQuery()).Returns("multiple Tokens");
            _mockTokenizer.Setup(t => t.GetLikeQuery()).Returns("%Test%");

            var queryGenerator = new FtsQueryGenerator(_mockGroupingStrategy.Object, _mockTokenizer.Object);
            var expected =
                "SELECT matchResults.* FROM (SELECT MAX(LocationId) as LocationId, locations.TOWN_NAME,locations.POSTCODE, COUNT(*) as Number " +
                "from locations JOIN locations_srch ON locations.locationId = locations_srch.docid " +
                "WHERE locations_srch MATCH 'multiple Tokens' " +
                "GROUP BY locations.TOWN_NAME,locations.POSTCODE ORDER by Number desc ) as matchResults " +
                "WHERE matchResults.TOWN_NAME like '%Test%' " +
                "OR matchResults.POSTCODE like '%Test%' " +
                "LIMIT 100;";

            Assert.Equal(expected, queryGenerator.Generate());
        }