5

We recently deployed a new custom Search Results webpart that utilizes a search scope we setup to query specific document libraries under a site hierarchy and return the results in a web part.

The web part results are showing that documents within folders are not being returned. Is there something that needs to be added to the search query in order to 'drill down' into the folders and add the documents within to the search results?

Relevant code below:

       private DataTable GetBindingData()
    {
        DataTable dt = new DataTable();

        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
              {
                  using (SPSite site = new SPSite(getSite()))
                  {
                      SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                      SearchServiceApplicationProxy searchProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
                      if (searchProxy != null)
                      {
                          FullTextSqlQuery fullQuery = new FullTextSqlQuery(searchProxy);
                          fullQuery.QueryText = getFullTextQuery();
                          fullQuery.ResultTypes = ResultType.RelevantResults;
                          var queryResults = fullQuery.Execute();
                          var queryResultsTable = queryResults[ResultType.RelevantResults];
                          dt.Load(queryResultsTable, LoadOption.OverwriteChanges);
                          dt.Columns.Add("ModifiedDate");
                          dt = ModifyResults(dt);

                      }
                  }
              });
        }
        catch (Exception)
        {
        }

        return dt;
    }
    private string getFullTextQuery()
    {
        StringBuilder query = new StringBuilder();
        query.Append("SELECT Url, Title, Department, DepartmentService, Modified, DocumentType, FileLeafRef ");
        query.Append("FROM Scope() ");
        query.Append("WHERE ((\"SCOPE\" = 'OurDocuments')) ");

        query.Append(string.Format("AND CONTAINS (ContentType, 'OurDocs') "));

        string tax = ParentWebPart.taxValue;
        if (!string.IsNullOrEmpty(tax))
        {
            query.Append(string.Format("AND (PrimaryTopic = '{0}' ", tax));
            query.Append(string.Format("OR SecondaryTopic = '{0}')", tax));
        }

        return query.ToString();
    }
  • 1
    I'm not entirely familiar with that language, but it sounds like it isn't doing a RecursiveAll check like you'd specify in a CAML query, meaning it recurses through all the folders and finds items. IDK if there is an equivalent there that you might need. – Eric Alexander Nov 20 '15 at 19:07
3

I figured this out. It seems there is a hard limit to the amount of items returned via the FullTextQuery (or the proxy - i cannot determine).

The 'fixed' code is below. A simple addition of an increase to the RowLimit (fullQuery.RowLimit = 1000;) was all I needed. Folders was a red herring:

        private DataTable GetBindingData()
    {
        DataTable dt = new DataTable();

        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
              {
                  using (SPSite site = new SPSite(getSite()))
                  {
                      SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                      SearchServiceApplicationProxy searchProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
                      if (searchProxy != null)
                      {
                          FullTextSqlQuery fullQuery = new FullTextSqlQuery(searchProxy);
                          fullQuery.QueryText = getFullTextQuery();
                          fullQuery.ResultTypes = ResultType.RelevantResults;
                          fullQuery.RowLimit = 1000;
                          var queryResults = fullQuery.Execute();
                          noItemsLabel.Text = queryResults.Count.ToString();    //50!!??
                          var queryResultsTable = queryResults[ResultType.RelevantResults];
                          dt.Load(queryResultsTable, LoadOption.OverwriteChanges);
                          dt.Columns.Add("ModifiedDate");
                          dt = ModifyResults(dt);
                      }
                  }
              });
        }
        catch (Exception)
        {
        }

        return dt;
    }
2
+25

To help troubleshoot the issue, I would suggest adding an out of the box results web part using that scope, and see if you get the same behavior or not. That will tell you if your scope definition is the issue, or the custom web part.

Typically the search engine shouldn't care about folders. I presume you specified web address paths in your search scope, typically they will include all subfolders, but I'd suggest reviewing them to see if there's some mistake there.

Also, are you sure the files are being excluded based on being in subfolders? Is it possible they are excluded for some other reason, for example I notice you are filtering further in your web part based on ContentType, PrimaryTopic and SecondaryTopic.

  • 1
    Thanks for your reply - after much sleuthing I found the solution (below). – Kolten Nov 24 '15 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.