日期:2014-05-18  浏览次数:20374 次

Contains 问题 急 在线等
SQL code

if (Utility.StringUtil.IsNotNull(keyword))
       {
           if (keyword != "Search Outlines" && keyword.Trim().Length>0)
           {
               //keyword = "SQLEncode("+keyword.Trim()+")";
               keyword = Utility.StringUtil.parameterReplace(keyword.Trim());
               where_keyword = string.Format(" where title like '%{0}%' or  course like'%{1}%' or DocType.DocType like '%{2}%' or School like '%{3}%' or professor like '%{4}%' or contains(data, '\"{5}\"')", keyword, keyword, keyword, keyword, keyword, keyword);
           }
       }
       string sql = "select Outline.dataType,Outline.title,DocType.docType,Outline.course,LawSchool.School,Professor.professor,Outline.price,Outline.points,Outline.uploadDate,Outline.id " +
                                            " from Outline inner join Users on Users.id = Outline.userId " +
                                            " inner join LawSchool on Outline.schoolId = LawSchool.id " +
                                            " inner join DocType on Outline.docType=DocType.id" +
                                            " inner join Professor on Outline.professorId=Professor.id ";

       string countSql = "select count(*) " +
                                            " from Outline inner join Users on Users.id = Outline.userId " +
                                            " inner join LawSchool on Outline.schoolId = LawSchool.id " +
                                            " inner join DocType on Outline.docType=DocType.id" +
                                            " inner join Professor on Outline.professorId=Professor.id ";
       if (this.OutlineDAO.getCount(countSql + where_keyword) > 0)
       {
           sql += where_keyword;
           countSql += where_keyword;
           this.Panel_msg.Style.Add("display", "none");
       }



提示错误:

无法对 表或索引视图'Outline' 使用 CONTAINS 或 FREETEXT 谓词,因为它未编制全文索引。


------解决方案--------------------
SQL code
/*
在库TEST上建立全文索引
*/
use test
create table poofly(id int not null, name varchar(10))
go
/* 首先创建一个唯一索引,以便全文索引利用*/
create unique clustered  index un_ky1 on poofly(id)
/*创建全文目录*/
create FULLTEXT CATALOG FT1 AS DEFAULT
/*C创建全文索引*/
create FULLTEXT INDEX ON poofly(NAME) key index un_ky1 ON  FT1
/*修改全文目录*/
alter FULLTEXT CATALOG FT1  REBUILD
/*删除全文目录FT(含有全文索引时候不能删除)*/
drop fulltext catalog ft
/*查看数据库所有的全文目录*/
select* from sys.fulltext_catalogs
/*
fulltext_catalog_id name                                                                                                                             path                                                                                                                                                                                                                                                             is_default is_accent_sensitivity_on data_space_id file_id     principal_id is_importing
------------------- -------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------- ---------- ------------------------ ------------- ----------- ------------ ------------
5                   test                                                                                                                             NULL