我正在使用IIS索引服务在我的网站中拥有搜索功能。我使用下面的代码来构建结果查询
string query = String.Format(@"SELECT Rank, VPath, DocTitle, Filename, Characterization, Write FROM SCOPE('DEEP TRAVERSAL OF ""{0}""') WHERE NOT CONTAINS(VPath, '""_vti_"" OR "".pdf"" OR "".config"" OR "".js"" OR "".txt""')", "/");
// Conditionally construct the rest of the WHERE clause.
string type = "any";//this.cboQueryType.SelectedItem.Value.ToLower();
// string fmt = @" AND (filename NOT LIKE '%.doc') AND (filename NOT LIKE '%.txt') AND (filename NOT LIKE '%.js') AND (filename NOT LIKE '%.pdf') AND (filename NOT LIKE '%.ppt') AND (CONTAINS('{0}') OR CONTAINS(DocTitle, '{0}'))";
string fmt = @" AND (filename NOT LIKE '%.doc') AND (filename NOT LIKE '%.aspx') AND (filename NOT LIKE '%.xml') AND (filename NOT LIKE '%.txt') AND (CONTAINS('{0}') OR CONTAINS(DocTitle, '{0}'))";
// Get the query string and remove all semi-colons, which should stop
// attempt to run malicious SQL code.
if (type == "all" || type == "any" || type == "boolean")
{
string[] words = text.Split(' ');
int len = words.Length;
for (int i = 0; i < len; i++)
{
string word = words[i];
if (type == "boolean")
if (String.Compare(word, "and", true) == 0 ||
String.Compare(word, "or", true) == 0 ||
String.Compare(word, "not", true) == 0 ||
String.Compare(word, "near", true) == 0)
continue;
words[i] = String.Format(@"""{0}""", word);
if (i < len - 1)
{
if (type == "all") words[i] += " AND";
else if (type == "any") words[i] += " OR";
}
}
query += String.Format(fmt, String.Join(" ", words));
}
else if (type == "exact")
{
query += String.Format(fmt, text);
}
else if (type == "natural")
{
query += String.Format(" AND FREETEXT('{0}')", text);
}
// Sort the results.
query += String.Format(" ORDER BY {0} {1}","Rank","DESC");
//Trace.Write("Query", query);
return query;
这对我来说很好。现在我想减少结果的数量。怎么做?我正在寻找来自客户的SELECT top 15之类的东西。我的搜索查询结果只需要10条记录。有什么想法????
答案 0 :(得分:0)
您可以使用MaxRecords
属性。