Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Incomplete results when using FullTextSqlQuery and NULL predicate

$
0
0

I have a site collection with content types that have site columns mapped onto managed properties. The managed properties are set up as managed search terms in the search centre. I have application code that executes a search using FullTextSearchQuery class to return pages from the content database that match a given managed property, e.g. Place=United Kingdom. I actually use GUID values, not the label text, so the GUID of United Kingdom is 'a2ce9dd7-f801-4403-affb-1944bf253255'.

What I have found is that when there is an exact match all is well, so if I search doing this:

CONTAINS(PlacesId, 'a2ce9dd7-f801-4403-affb-1944bf253255')

I get all of the pages that have United Kingdom. However, what I want to do is get all pages where either Place=United Kingdom or Place has no value set. For this I do the following:

(CONTAINS(PlacesId, 'a2ce9dd7-f801-4403-affb-1944bf253255') OR (PlacesId IS NULL))

What I have found is that the search returns some results but not all of them and it always returns the items that were created first.

This makes no sense. If it returned no items at all I could believe it was a bug in the code, but for it to return some items, and for a given page always the same items, and those are the first created items (i.e. Created field in ascending order) makes me think there is something not right about the search.

For reference, the code that executes this is:

FullTextSqlQuery myQuery = new FullTextSqlQuery(SPContext.Current.Site)
{
	QueryText = query,
	ResultTypes = ResultType.RelevantResults,
	TrimDuplicates = false
};
ResultTable queryResultsTable = null;
try
{
	ResultTableCollection queryResults = myQuery.Execute();
	queryResultsTable = queryResults[ResultType.RelevantResults];
	queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
}
catch (Exception ex)
{
	ULSLogger.Log("XXX.SharePoint.YYY.Controls (" + DateTime.Now + "):RelatedContent.GetDataFromList:" + ex.Message);
}

The query text is:

SELECT url, Title, LastModifiedTime, ArticleStartDate, ShortTitle FROM Scope() WHERE "scope" = 'XXX' 
	AND (CONTAINS(PlacesId, 'a2ce9dd7-f801-4403-affb-1944bf253255') OR (PlacesId IS NULL)) 
	AND (CONTAINS(ContentLanguageId, '6e2857f6-364f-4df5-b272-20150d79ef71')) 
	ORDER BY ContentTitle ASC
The extra CONTAINS is because I am matching on specific languages - that works fine.

Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>