views:

27

answers:

1

I am using IIS index service to have a search feature in my website. I used the below code to build the query for results

  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;

This is working fine for me.Now i want to reduce the number of results .How to do that ? I am looking for something like SELECT top 15 from customer . I need only 10 records for my search query result . Any thoughts ????

A: 

use the MaxRecords property

Christine Perry