2009-09-11 64 views
0

我正在使用IIS索引服务在我的网站中具有搜索功能。我用下面的代码来构建的结果限制在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; 

为me.Now这是工作的罚款,我想,以减少数量的结果。如何做到这一点的查询?我正在寻找诸如客户的SELECT top 15之类的东西。我的搜索查询结果只需要10条记录。有什么想法吗 ????

回答

0

您可以使用MaxRecords属性。