SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Custom Cross-List Search Development Pitfalls (Part Two)

In my previous post Custom Cross-List Search Development Pitfalls (Part One) I talked about the importance of managing Meta data in order to provide effective ways for users to search for documents. Meta data can be managed via "Managed Properties" in MOSS or having some concerted policy and standards for naming of columns in WSS. In Part One I illustrated a scenario where a column could be renamed to a display name that was also was being used on another document library. This scenario produced one display name pointing to two SharePoint columns with two different internal names. So a column with the display name of "Age" pointed to two columns in the site collection one with an internal name of "Customer Age" and another with an internal name of "Age". I showed how a WSS search solution would have to generate a CAML query that "OR" the two where criteria to the two different internal columns. Unfortunately, this will not return any results.

<Where>

    <Or>

        <Eq>

            <FieldRef Name="Customer_x0020_Age" />

            <Value Type="Number">25</Value>

        </Eq>

        <Eq>

            <FieldRef Name="Age" />

            <Value Type="Number">25</Value>

        </Eq>

    </Or>

</Where>

The Problem with "OR" in WSS

The reason the above CAML query "where" will not return any results is that in order for an "OR" to return results in WSS the two columns must exist in the document library where the document is stored. For instance, if I want to query for documents in a site collection that have an "AccountType" = Consumer OR "LoanType" = Auto, the only documents that will be returned are documents that have both "AccountType" and "LoanType" columns defined in the document library. Documents that have only one of the columns defined in the document library will not be returned even if the criterion matches. Increasing the number of "OR" columns in the CAML increases the chances that no documents will be returned.

The Problem with "OR" in MOSS

The problem with "OR" also occurs in MOSS but with a different twist. A custom search solution using MOSS could use FullTextSqlQuery class which uses SQL to search. If you "OR" two managed properties in the where clause and the crawled property that is mapped to the managed property does not exist in the document library then that record will not be returned even if it matches the other managed property criteria. In addition, even if the crawled property (column) does exist in the document library the record will not be returned if the crawled property for that document contains a null value.

For example consider this scenario:

            AccountType            LoanType

Document 1        Consumer            Does not exist

Document 2        Does not exist            Auto

Document 3        Consumer            Null

Document 4        Consumer            Boat

Document 5        Corporate            Auto

SELECT Title,owsAccountType,owsLoanType,owsLinkFilename FROM SCOPE() WHERE (owsAccountType = 'Consumer' OR owsLoanType = 'Auto') ORDER BY Title

Given the above SQL only Document 4 and Document 5 will be returned.

The Problem with Sorting

So let's say you avoid the problem with "OR" in both WSS and MOSS. Unfortunately, the same problem reveals itself when sorting on columns that don't exist or have null values. If you sort by columns that don't exist then those records are not returned.

The Problem with Nulls in WSS

A custom search solution that generates CAML must make adjustments to handle columns values that may contain nulls. If a column contains a null value and it is included to be returned in the results, then it will not be returned in the results unless you add the "Nullable=true" attribute to the "FieldRef" element in the "ViewFields" element of a CAML query.

<ViewFields>

<FieldRef Name="Title" Nullable="TRUE" ></FieldRef>

<FieldRef Name="AccountType" Nullable="TRUE" ></FieldRef>

<FieldRef Name="LoanType" Nullable="TRUE" ></FieldRef>

</ViewFields>

Summary

This two part series on developing custom cross-list search solutions showed you the importance of managing Meta data and some of the problems with the "OR" logic. At this time there seems to be no work around for the "OR" logic. Hopefully, we may see either a hot fix or fix in a service pack release.


Posted 06-20-2007 3:20 PM by steveC

Comments

Sharepoint link love 06-21-2007 at Virtual Generations wrote Sharepoint link love 06-21-2007 at Virtual Generations
on 06-21-2007 3:30 AM

Pingback from  Sharepoint link love 06-21-2007 at  Virtual Generations

Mike Walsh's WSS and more wrote WSS FAQ additions and changes LX - 18th - 24th June 2007
on 06-24-2007 3:14 AM
Jonathan Patton wrote re: Custom Cross-List Search Development Pitfalls (Part Two)
on 05-15-2008 3:39 AM

That sucks in a massive way. Essentially you can alter the number or records returned by search by appending an order by clause. An order by clause should never effect the number or  records returned. This is total bullocks. Im annoyed.

Mike Morawski wrote re: Custom Cross-List Search Development Pitfalls (Part Two)
on 05-16-2008 8:01 AM

I'm looking for a solution to the orderby problem for my cross list datasource. I thought that there HAD to be some way that the SP dev team provided a workaround for the behavior... Guess not. :/

Melwin Menezes wrote re: Custom Cross-List Search Development Pitfalls (Part Two)
on 03-13-2009 3:36 AM

A nice article. Helped us to address some issues that could have raised later on in our development cycle.

Melwin Menezes wrote re: Custom Cross-List Search Development Pitfalls (Part Two)
on 03-13-2009 3:37 AM

A nice article. Helped us to address some issues that could have raised later on in our development cycle.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.