Content Queries Using SharePoint Enterprise Search API

February 15 2010 75 comments

In an earlier post to SharePoint Blues Juho wrote about the challenge of – how to find anything from the sea of content. One way of solving this issue is to use SharePoint Enterprise Search API and the FullTextSqlQuery class. This class allows you to query SharePoint content using SQL syntax. FullTextSqlQuery queries always query from SCOPE(). In the where clause you set the target scope. Here is an example how the query is formed:

SELECT Title FROM SCOPE() WHERE "scope" = 'All Sites'

As you can see the syntax is SQL and this makes querying content pretty easy. At this point I want to point out that you can only query data that has been indexed by SharePoint so you need to crawl content before you can get any results. This is also a thing that might make using FullTextSqlQuery class impossible – the content isn’t realtime because it needs to be indexed first.

For the following example I created two SharePoint pages. One with a title ‘Example’ and second with a title ‘Example of FullTextSqlQuery’. Below is the example code in which I query content from All Sites scope and where Title field must contain the word ‘Example’:

var query = new FullTextSqlQuery(SPContext.Current.Site)
{
    QueryText = "SELECT Title FROM SCOPE() WHERE \"scope\" = 'All Sites'
        AND CONTAINS(Title, 'Example')"
,
    ResultTypes = ResultType.RelevantResults
};
var queryResults = query.Execute();
var queryResultsTable = queryResults[ResultType.RelevantResults];
var results = new DataTable();
results.Load(queryResultsTable, LoadOption.OverwriteChanges);

After running the code the results DataTable contains both of the pages I had created earlier. In the query I used predicate CONTAINS and with that I was able to look for word ‘Example’ in the Title field. FullTextSqlQuery uses managed properties in its queries and in the example query Title is an managed property. You can also easily create custom managed properties from your Shared Services Provider under Search Settings.

I think using FullTextSqlQuery is one way to find essential information from the sea of content.

Couple more things to add:

- Remember to use following using statement to make FullTextSqlQuery work:

using Microsoft.Office.Server.Search.Query;

- I found out that boolean fields in where clause behave bit strangely. I couldn’t get =true working, but I found a workaround for this. You can use !=false instead of =true

Popularity: 100% [?]

75 comments to “Content Queries Using SharePoint Enterprise Search API”

  1. Everything published made a great deal of sense.

    But, think about this, what if you typed a catchier title?
    I ain’t suggesting your information isn’t solid, however suppose you added a title that makes people want more?
    I mean Content Queries Using SharePoint Enterprise Search API | SharePoint Blues is kinda vanilla.
    You might peek at Yahoo’s home page and note how they create
    post headlines to get viewers to open the links. You might add a related video or a related
    picture or two to grab people excited about what you’ve got to say.
    In my opinion, it could bring your website a little livelier.

  2. Hello there I am so glad I found your site,
    I really found you by accident, while I was searching on Bing for something else,
    Regardless I am here now and would just like to say thank
    you for a marvelous post and a all round
    thrilling blog (I also love the theme/design), I don’t have time
    to read it all at the moment but I have bookmarked it and also included your
    RSS feeds, so when I have time I will be back to read a
    lot more, Please do keep up the awesome b.

  3. Very good article. I definitely appreciate this website.
    Continue the good work!

  4. I think this is among the so much important information for
    me. And i’m glad studying your article. But should statement
    on some common issues, The web site style is wonderful, the articles is really great :
    D. Excellent activity, cheers

  5. steemfilter says:

    steemfilterUsing SharePoint Enterprise Search API | SharePoint Blues is kinda vanilla.
    You might peek at Yahoo’s home page

  6. With our handy online scheduling and truthful pricing, we’re right here to assist.
    By shopping on-line, you get rid of all of this frustration

  7. tobuweb says:

    this is among the so much important information for
    me. And i’m glad studying your article. But should statement
    on some common issues

  8. kuzin says:

    It make take several minutes for the service to move from the starting stated to started state. The system service starts two Windows services with the farm account: first the ForeFront Identity Manager Synchronization Service and then the ForeFront Identity Manager service. While these are launched,

  9. my iframe says:

    я немедленно запишу ваш rss
    адрес, поскольку я бессилен отыскать ваш
    e-mail link или e-newsletter. Можно ли попросить ваши контакты?
    Будьте добры, разрешите мне переговорить с вами для того, чтобы я мог
    бы подписаться.

  10. But should statement
    on some common issues, The web site style is wonderful

  11. I was able to look for word ‘Example’ in the Title field. FullTextSqlQuery uses managed properties in its queries and in the example query Title is an managed property. You can also easily create cus

  12. SharePoint site structure hierarchy is document or item. Document and item permissions can also be granted just like you did with structures above that

  13. сейчас же кину в закладки ваш rss, поскольку я бессилен найти ваш e-mail hyperlink или newsletter.
    Можно ли попросить ваши контакты?
    Пожалуйста, разрешите мне общаться с вами для того, чтобы я
    мог бы подписаться. Б

  14. Peculiar article, totally what I wanted to find.

  15. Annoncelight says:

    Annoncelight har et rent og elegant design, så du nemt kan gennemse alle escortpersonernes profiler. Du kan også bruge filtre til avancerede søgninger.

  16. Klubb6 says:

    Klubb6 är en mycket lättillgänglig dejtingsajt där det inte alltid behöver vara seriöst att dejta. Även om den här dejtingsajten i första hand är till för att hitta ett förhållande är det också rätt ställe för andra typer av roliga och spännande kontakter.

  17. Themenladies says:

    Themenladies bietet Ihnen die Möglichkeit, schnell mit Menschen in Kontakt zu kommen, die auf der Suche nach Sex sind. Wenn Sie auf der Suche nach einer ernsthaften Beziehung sind, ist diese Website wahrscheinlich nichts für Sie, aber wenn Sie schnell einen aufregenden Kontakt finden wollen, ist dies eine ausgezeichnete Wahl.

  18. Sex Dresden says:

    Sex Dresden ist eine Casual-Dating-Seite, auf der Sie MILFs treffen können – Frauen mittleren Alters, die wirklich heiß aussehen. Wenn Sie jedoch auf der Suche nach einer Ehe sind, ist es eine schlechte Idee, diese Seite zu wählen – sie wurde ursprünglich für Leute geschaffen, die nichts anderes wollen als ein Treffen.

  19. Gilfs says:

    Gilfs ist der seriöseste und heißeste Ort, um Oma-Sexkontakte mit Profilen zu finden, die 100% authentisch sind. Sicherheit und Diskretion sind wichtig für dich und werden von uns sehr respektiert. Mit einer hochmodernen Benutzeroberfläche wird es für Sie einfach sein, die sexy Oma Ihrer Träume zu suchen und zu finden, für die heißeste Begegnung, die Sie je erlebt haben!

  20. Parenclub says:

    Parenclub heeft singles, swingers en stellen uit alle lagen van de bevolking voor zich gewonnen, en wij denken dat de snelle inschrijving en de gratis functies je goed van pas zullen komen, ongeacht je relatiedoelen of seksuele fantasieën.

  21. Jordan says:

    Tree removal should always be done with responsibility and a long-term sustainability in mind. Try to inquire now for more details!

Leave a Reply