Exemplo n.º 1
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static SqlWhereCollection FullTextWhere(
            this SqlWhereCollection where,
            Context context,
            SiteSettings ss,
            string searchText,
            bool itemJoin)
        {
            var name = Strings.NewGuid();

            if (ss != null && ss.TableType != Sqls.TableTypes.Normal)
            {
                return(where.ItemWhereLike(
                           context: context,
                           ss: ss,
                           columnName: "FullText",
                           searchText: searchText,
                           name: name,
                           forward: false,
                           itemJoin: itemJoin));
            }
            switch (ss?.SearchType)
            {
            case SiteSettings.SearchTypes.FullText:
                var words = Words(searchText);
                if (words?.Any() != true)
                {
                    return(where);
                }
                if (itemJoin)
                {
                    where.FullTextWhere(
                        context: context,
                        words: words,
                        itemsTableName: ss.ReferenceType + "_Items");
                }
                else
                {
                    where.FullTextWhere(
                        context: context,
                        words: words,
                        idColumnBracket: ss.IdColumnBracket(),
                        tableType: ss.TableType);
                }
                return(where);

            case SiteSettings.SearchTypes.MatchInFrontOfTitle:
                return(where.ItemWhereLike(
                           context: context,
                           ss: ss,
                           columnName: "Title",
                           searchText: searchText,
                           name: name,
                           forward: true,
                           itemJoin: itemJoin));

            case SiteSettings.SearchTypes.BroadMatchOfTitle:
                return(where.ItemWhereLike(
                           context: context,
                           ss: ss,
                           columnName: "Title",
                           searchText: searchText,
                           name: name,
                           forward: false,
                           itemJoin: itemJoin));

            case SiteSettings.SearchTypes.PartialMatch:
            default:
                return(where.ItemWhereLike(
                           context: context,
                           ss: ss,
                           columnName: "FullText",
                           searchText: searchText,
                           name: name,
                           forward: false,
                           itemJoin: itemJoin));
            }
        }
        /// <summary>
        /// Fixed:
        /// </summary>
        public static SqlWhereCollection FullTextWhere(
            this SqlWhereCollection where,
            SiteSettings ss,
            string searchText,
            bool itemJoin)
        {
            var name = Strings.NewGuid();

            if (ss != null && ss.TableType != Sqls.TableTypes.Normal)
            {
                return(where.ItemWhereLike(
                           ss: ss,
                           columnName: "FullText",
                           searchText: searchText,
                           name: name,
                           forward: false,
                           itemJoin: itemJoin));
            }
            switch (ss?.SearchType)
            {
            case SiteSettings.SearchTypes.PartialMatch:
                return(where.ItemWhereLike(
                           ss: ss,
                           columnName: "FullText",
                           searchText: searchText,
                           name: name,
                           forward: false,
                           itemJoin: itemJoin));

            case SiteSettings.SearchTypes.MatchInFrontOfTitle:
                return(where.ItemWhereLike(
                           ss: ss,
                           columnName: "Title",
                           searchText: searchText,
                           name: name,
                           forward: true,
                           itemJoin: itemJoin));

            case SiteSettings.SearchTypes.BroadMatchOfTitle:
                return(where.ItemWhereLike(
                           ss: ss,
                           columnName: "Title",
                           searchText: searchText,
                           name: name,
                           forward: false,
                           itemJoin: itemJoin));

            default:
                switch (Parameters.Search.Provider)
                {
                case "FullText":
                    var words = Words(searchText);
                    if (words?.Any() != true)
                    {
                        return(where);
                    }
                    where.Add(new SqlWhere(
                                  name: name,
                                  value: words,
                                  raw: itemJoin
                                    ? FullTextWhere(
                                      words: words,
                                      itemsTableName: ss.ReferenceType + "_Items",
                                      name: name)
                                    : FullTextWhere(
                                      words: words,
                                      idColumnBracket: ss.IdColumnBracket(),
                                      tableType: ss.TableType,
                                      name: name)));
                    return(where);

                default:
                    return(where.Add(Rds.ItemsWhere().SqlWhereLike(
                                         tableName: "Items",
                                         name: name,
                                         searchText: searchText,
                                         clauseCollection: Rds.Items_FullText_WhereLike(
                                             tableName: ss.ReferenceType + "_Items",
                                             name: name,
                                             forward: false)
                                         .ToSingleList())));
                }
            }
        }