protected override SqlProvider VisitFreeText(FreeTextProvider provider)
        {
            SqlFreeTextTable fromTable;

            QueryParameterBinding[] bindings;

            var stringTypeMapping = Driver.GetTypeMapping(StringType);
            var criteriaBinding   = new QueryParameterBinding(
                stringTypeMapping, provider.SearchCriteria.Invoke, QueryParameterBindingType.Regular);

            var index   = provider.PrimaryIndex.Resolve(Handlers.Domain.Model);
            var table   = Mapping[index.ReflectedType];
            var columns = provider.Header.Columns.Select(column => column.Name).ToList();

            if (provider.TopN == null)
            {
                fromTable = SqlDml.FreeTextTable(table, criteriaBinding.ParameterReference, columns);
                bindings  = new[] { criteriaBinding };
            }
            else
            {
                var intTypeMapping = Driver.GetTypeMapping(Int32Type);
                var topNBinding    = new QueryParameterBinding(intTypeMapping, context => provider.TopN.Invoke(context), QueryParameterBindingType.Regular);
                fromTable = SqlDml.FreeTextTable(table, criteriaBinding.ParameterReference, columns, topNBinding.ParameterReference);
                bindings  = new[] { criteriaBinding, topNBinding };
            }
            var fromTableRef = SqlDml.QueryRef(fromTable);
            var select       = SqlDml.Select(fromTableRef);

            select.Columns.Add(fromTableRef.Columns[0]);
            select.Columns.Add(SqlDml.Cast(fromTableRef.Columns[1], SqlType.Double), "RANK");

            return(CreateProvider(select, bindings, provider));
        }
示例#2
0
        protected override SqlProvider VisitFreeText(FreeTextProvider provider)
        {
            var rankColumnName    = provider.Header.Columns.Last().Name;
            var stringTypeMapping = Driver.GetTypeMapping(typeof(string));
            var binding           = new QueryParameterBinding(stringTypeMapping,
                                                              provider.SearchCriteria.Invoke, QueryParameterBindingType.Regular);

            SqlSelect select           = SqlDml.Select();
            var       realPrimaryIndex = provider.PrimaryIndex.Resolve(Handlers.Domain.Model);
            var       index            = realPrimaryIndex.ReflectedType.Indexes.PrimaryIndex;
            var       query            = BuildProviderQuery(index);
            var       table            = Mapping[realPrimaryIndex.ReflectedType];
            var       fromTable        = SqlDml.FreeTextTable(table, binding.ParameterReference, table.Columns.Select(column => column.Name).AddOne(rankColumnName).ToList());
            var       fromTableRef     = SqlDml.QueryRef(fromTable);

            foreach (var column in query.Columns)
            {
                select.Columns.Add(fromTableRef.Columns[column.Name] ?? column);
            }
            select.Columns.Add(SqlDml.Cast(fromTableRef.Columns[rankColumnName], SqlType.Double), rankColumnName);
            select.From = fromTableRef;
            if (provider.TopN != null)
            {
                select.Limit = provider.TopN.Invoke();
                select.OrderBy.Add(select.Columns[rankColumnName], false);
            }
            return(CreateProvider(select, binding, provider));
        }
示例#3
0
        public void FreeTextTest()
        {
            SqlSelect select = SqlDml.Select();
            var       table  = Catalog.DefaultSchema.Tables["Address"];

            select.From = SqlDml.QueryRef(SqlDml.FreeTextTable(table, "How can I make my own beers and ales?", EnumerableUtils.One(table.Columns[0].Name).ToList(), EnumerableUtils.One(table.Columns[0].Name).ToList()));
            select.Columns.Add(select.From.Asterisk);
            Console.WriteLine(SqlDriver.Compile(select).GetCommandText());
        }
示例#4
0
        public void FreeTextTopNByRankTest()
        {
            SqlSelect select = SqlDml.Select();
            var       table  = Catalog.Schemas["Person"].Tables["Address"];

            select.From = SqlDml.QueryRef(SqlDml.FreeTextTable(table,
                                                               "How can I make my own beers",
                                                               EnumerableUtils.One(table.Columns[0].Name).ToList(),
                                                               (SqlLiteral)5));
            Console.WriteLine(sqlDriver.Compile(select).GetCommandText());
        }
示例#5
0
        protected override SqlProvider VisitFreeText(FreeTextProvider provider)
        {
            var rankColumnName    = provider.Header.Columns[provider.Header.Columns.Count - 1].Name;
            var stringTypeMapping = Driver.GetTypeMapping(WellKnownTypes.StringType);
            var binding           = new QueryParameterBinding(stringTypeMapping,
                                                              provider.SearchCriteria.Invoke, QueryParameterBindingType.Regular);

            var select           = SqlDml.Select();
            var realPrimaryIndex = provider.PrimaryIndex.Resolve(Handlers.Domain.Model);
            var index            = realPrimaryIndex.ReflectedType.Indexes.PrimaryIndex;
            var query            = BuildProviderQuery(index);
            var table            = Mapping[realPrimaryIndex.ReflectedType];
            var fromTable        = SqlDml.FreeTextTable(table, binding.ParameterReference,
                                                        table.Columns.Select(column => column.Name).Append(rankColumnName).ToArray(table.Columns.Count + 1));
            var fromTableRef = SqlDml.QueryRef(fromTable);

            foreach (var column in query.Columns)
            {
                select.Columns.Add(fromTableRef.Columns[column.Name] ?? column);
            }

            select.Columns.Add(SqlDml.Cast(fromTableRef.Columns[rankColumnName], SqlType.Double), rankColumnName);
            select.From = fromTableRef;
            if (provider.TopN == null)
            {
                return(CreateProvider(select, binding, provider));
            }

            var intTypeMapping = Driver.GetTypeMapping(typeof(int));
            var topNBinding    = new QueryParameterBinding(
                intTypeMapping, context => provider.TopN.Invoke(context), QueryParameterBindingType.Regular);

            select.Limit = topNBinding.ParameterReference;
            select.OrderBy.Add(select.Columns[rankColumnName], false);
            return(CreateProvider(select, new[] { binding, topNBinding }, provider));
        }