Excluding empty text values in SharePoint Search

, , ,

Last week I got an opportunity to work with SharePoint Search. As you could imagine it didn’t go that easy at all and to be honest the SQL-like statements didn’t make it for me at all. And unless I’ve seriously missed something, I’ve found out that there is no easy way to exclude empty text results in SharePoint Search. At least it seemed so…

In my case I’ve had a MultiLookup field (Tags) attached to some Content Types. What I wanted to achieve is to obtain a list of all tags and the number of times they were used. SQL Syntax for Windows SharePoint Services Search doesn’t provide any grouping mechanism as far as I can tell. And even if it would, I don’t think it would allow you to group all results by particular values of a MultiLookup and perform a count.

To get the result described above I would have to use a rather slow while loop to iterate through all the results. Minimizing the number of results would improve this part of the process.

In my scenario not all items were tagged. Excluding items without tags from the search results would decrease the collection of items which would have to be iterated.

For the purpose of the case I have created a Text Managed Property based on Tags field. I assumed that the value of the Tags field, for all items without tags would be NULL. According to MSDN you can exclude NULL values using the IS NOT NULL predicate. Wrong!

Running the query:

SELECT Tags FROM portal..scope() WHERE "SCOPE" = 'My scope' AND Tags IS NOT NULL

would result in the following exception:

Exception from HRESULT: 0×80044100

Query machine 'VPC-MOSSDEV' has been taken out of rotation due to this error: Values of this type are not turned into strings necessary to generate scope information. The item will not be locatable in all of the appropriate scopes but this is not a serious error.   0×80044100.  It will be retried in 15 seconds.

I’m not really sure what the reason of such behavior is. Is it by-design SharePoint behavior, does it have anything to do with the MultiLookup field being converted to a Text Managed Property or is it even something else?

What I’ve found out by trial and error is that changing the IS NOT NULL predicate to > ‘’ works!

SELECT Tags FROM portal..scope() WHERE "SCOPE" = 'My scope' AND Tags > ''

After having modified the query as displayed above, the query returned results as expected. So if you ever find yourself having troubles with NULL values, the above might perhaps help you as well.

Possibly related posts

5 Responses to “Excluding empty text values in SharePoint Search”

  1. Yohan Says:

    Hi Waldek,
    This is an interesting post since I was experiencing the same problem… thing is though, I want to search for NULL values, not exclude them! I've tried quite a few different methods without success… I think I have more trouble since my column is of type system.double. This prevents me from being able to use the text predicates etc….

    Using (column > 0) returns the non-null values.
    Using (column < 0) doesn't return anything.

    If you have any clue as to how I can work around this, I would much appreciate!

    Thanks,
    Yohan

  2. Waldek Mastykarz Says:

    @Yohan: Have you tried using column = " (just a sanity check)?

  3. Sridhar Says:

    Interesting post but have the same problem as Yohan where I need to search for NULL values. Please help !

  4. Sridhar Says:

    I have a similiar problem as @Yohan. I want to search for NULL or empty column values. Please help!

  5. Waldek Mastykarz Says:

    @Sridhar: As I mentioned: have you tried searching for = " values?

Leave a Reply

Security Code:

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS
Copyright © 2007 - 2010 Waldek Mastykarz

Creative Commons License