Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Can anybody please point me in the right direction of searching the Pages library using FullTextSqlQuery? I've successfully instanced a new FullTextSqlQuery and have dealt with all of the necessary properties. It retrieves data just fine but as it stands my query is:

SELECT Title FROM Scope()

Simply for me to test it's working. How do I refine this to add a where a clause to search only Pages library?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

If you're querying multiple Site Collections use FullTextSQLQuery since it searches across the farm and if you plan to query Pages Library of a single Site Collection, use SPSiteDataQuery instead. I think you might need SPSiteDataQuery?

    SPSiteDataQuery queryObj = new SPSiteDataQuery();      
    //query Pages libraries
    queryObj.Lists = "<Lists ServerTemplate='850' />"; 
    queryObj.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='FileRef' />";
    queryObj.Webs = "<Webs Scope='Recursive' />";
    DataTable dt = SPContext.Current.Web.GetSiteData(query);

    foreach (DataRow row in dt.Rows)
    {
        //do something else
    }

P.S. FullTextSqlQuery may not always return the freshest of data but you can reduce the incremental crawl schedule to 15 mins or 30 mins.

Update:

Set the QueryText property of your FullTextSQLQuery object like this:

fullTextSqlQuery.QueryText =
"select title, ContentClass from scope() where (contentclass = 'STS_List_850')";

"STS_List_850": // denotes a Page Library

share|improve this answer
    
Thanks Falak. For a few reasons, it's been specified that I use a FullTextSQLQuery. Thanks anyway. –  DeeMac Jun 25 '12 at 12:20
    
Thanks a LOT Falak! –  DeeMac Jun 25 '12 at 12:33
1  
I have update my response –  Falak Mahmood Jun 25 '12 at 12:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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