Tuesday, September 8, 2009

SPSiteDataQuery limited to 10 document libraries or lists

Technorati Tags:

In previous posts I talked about the pitfalls of searching in WSS or MOSS. I wanted to report one more limitation we have discovered when doing cross-list searches in WSS using the SPSiteDataQuery object. The SPWeb.GetSiteData method is used to execute cross-list searches within a site collection. This method takes a SPSiteDataQuery object which contains properties which need to be populated prior to sending it to the GetSiteData method. Using CAML (Collaborative Application Markup Language) you can construct a cross-list query. Subsets of the CAML query are then used to set the properties of the SPSiteDataQuery object, for example the Query property.

                        <FieldRef Name="InvoiceNumber"/>
                        <Value Type="Number">125555</Value>
                        <FieldRef Name="MNEMONIC"/>
                        <Value Type="Text">AAA</Value>
                    <FieldRef Name="FSObjType"/>
                    <Value Type="Lookup">1</Value>
        <FieldRef Name="FileRef" Nullable="TRUE"/>
        <FieldRef Name="EncodedAbsUrl" Nullable="TRUE"/>
        <FieldRef Name="FileDirRef" Nullable="TRUE"/>
        <FieldRef Name="Title" Nullable="TRUE"/>
        <FieldRef Name="InvoiceNumber" Nullable="TRUE"/>
        <FieldRef Name="MNEMONIC" Nullable="TRUE"/>
    <Lists ServerTemplate="101"/>
    <Webs Scope="Recursive"/>


This query will not return all the results if your site collection has more than 10 document libraries and any of the columns are in different order in the document libraries. This applies to lists also. Microsoft has confirmed this to be a bug. According to Microsoft when the site collection contains more than 10 document libraries the internal code escalates to use a temporary table. If document library(1).Column1 is not the same physical column as document library(2).Column1 then results are incorrect. Microsoft does not plan to fix this in SP1 but hopefully in SP2.



You can make sure you limit your site collection to 10 document libraries and 10 lists. Alternatively, you can strictly control column creation within your site collections via security and the use of a well planned content type strategy (http://technet2.microsoft.com/Office/f/?en-us/library/63bb092a-00fe-45ff-a4b8-d8be998d1a3c1033.mspx). The bottom line is to not  let your document library metadata columns get out of order. Finally, if you are developing on MOSS use the Microsoft.Office.Server.Search.KeywordQuery or FullTextSQLQuery classes to do your searching. If you have only a WSS 3.0 install you could use the Microsoft.SharePoint.Search.Query.KeywordQuery or FullTextSQLQuery classes. Unfortunately, you are limited to built in metadata searching and custom metadata is not supported. Ahhh, but there is a way around this which could be in a future post.

No comments:

Post a Comment