Пример #1
0
        public IEnumerable <int?> SearchMovieIds(MovieSearchParams search)
        {
            if (string.IsNullOrEmpty(search.Search))
            {
                return(Enumerable.Empty <int?>());
            }

            using (var sphinx = new DbSphinx())
            {
                var qb = new SphinxQueryBuilder("torronto_movies")
                         .SelectColumns("id")
                         .AddMatch(string.Format("@!(description) {0}", EscapeUserInput(search.Search)))
                         .AddLimits(0, 100);

                if (search.MovieStatus > MovieStatus.Unknown)
                {
                    qb.AddWhere("status", (int)search.MovieStatus);
                }

                var items = sphinx.Query <int?>(qb.Build())
                            .ToList();

                return(items);
            }
        }
Пример #2
0
        public void TestSelectLimit()
        {
            var query = new SphinxQueryBuilder("first_index")
                        .AddLimits(22, 33)
                        .Build();

            var expected =
                @"SELECT *
FROM `first_index`
LIMIT 22, 33";

            Assert.AreEqual(expected, query);
        }
Пример #3
0
        public void TestSelect()
        {
            var query = new SphinxQueryBuilder("test")
                        .AddWhere("video_quality", 30)
                        .AddWhere("sound_quality", 20)
                        .Build();

            var expected =
                @"SELECT *
FROM `test`
WHERE `video_quality` = 30 AND `sound_quality` = 20";

            Assert.AreEqual(expected, query);
        }
Пример #4
0
        public void TestSelect2()
        {
            var query = new SphinxQueryBuilder("first_index", "second_index")
                        .SelectColumns("a", "b", "c")
                        .AddWhere("video_quality", 30)
                        .Build();

            var expected =
                @"SELECT `a`, `b`, `c`
FROM `first_index`, `second_index`
WHERE `video_quality` = 30";

            Assert.AreEqual(expected, query);
        }
Пример #5
0
        public void TestSelectMatch()
        {
            var query = new SphinxQueryBuilder("first_index")
                        .SelectColumns("id")
                        .AddMatch("abyr'valg")
                        .AddWhere("video_quality", 30)
                        .Build();

            var expected =
                @"SELECT `id`
FROM `first_index`
WHERE MATCH('abyr\'valg') AND `video_quality` = 30";

            Assert.AreEqual(expected, query);
        }
Пример #6
0
        public IEnumerable <int?> SearchTorrentIds(TorrentSearchParams search)
        {
            if (string.IsNullOrEmpty(search.Search))
            {
                return(Enumerable.Empty <int?>());
            }

            using (var sphinx = new DbSphinx())
            {
                var qb = new SphinxQueryBuilder("torronto_torrents")
                         .SelectColumns("id")
                         .SelectLiteral(string.Format("((video_quality & {0}) > 0) vq", (int)search.VideoQuality))
                         .SelectLiteral(string.Format("((sound_quality & {0}) > 0) aq", (int)search.AudioQuality))
                         .SelectLiteral(string.Format("((translation & {0}) > 0) tq", (int)search.TranslationQuality))
                         .AddMatch(EscapeUserInput(search.Search))
                         .AddLimits(0, 100);

                if (search.VideoQuality > VideoQuality.Unknown)
                {
                    qb.AddWhere("vq", 1);
                }
                if (search.AudioQuality > AudioQuality.Unknown)
                {
                    qb.AddWhere("aq", 1);
                }
                if (search.TranslationQuality > Translation.Unknown)
                {
                    qb.AddWhere("tq", 1);
                }

                var items = sphinx.Query <int?>(qb.Build())
                            .ToList();

                return(items);
            }
        }