- Search can only get results inside a site collection (works only on a single site collection at a time)
- Does not index external data source
-
There are 2 query option
-
Query Object Model reside in the Microsoft.SharePoint.Search.Query namespace
-
There are 3 option to build a search queries
-
Keyword Syntax – search terms are passed directly to the Search service (basic query)
-
There are 2 type of terms
-
Keywords
- A word
- A phrase (more than one word separated by space and enclosed with ” “)
- A prefix (a part of word the beginning of the word( “+followed by this word” or “-not followed by this word”))
- Property filters (narrow the focus of the keyword search by manipulating the metadata, e.g. author:John or author:”John Cena” if there’s space)
-
-
-
SQL syntax – extension of SQL syntax for querying database (constructing complex queries)
-
Same syntax as normal SQL query
-
Dissecting the SQL structure
- SELECT – must specify at least one column and SELECT * won’t work
- FROM – specify where to search, FROM scope where “scope” = ‘All Site’ (the only available scope for SPF)
-
WHERE – specify condition, support two search predicate
-
FREETEXT = search the query everywhere
- use FREETEXT(*,”‘+txtsearch+'”) or FREETEXT(defaultproperties, “‘+txtsearch+'”) for all columns of the metadata or FREETEXT(columnName,”‘+txtsearch+'”) for a specific metadata
- CONTAIN = does an exact match
- LIKE = ModifiedBy LIKE ‘%”+txtsearch+”%’
- ORDER BY = ORDER By RANK DESC
-
-
Querying in SharePoint example
-
Available field or column (SELECT Size,Path..).
- Only these fields are available in SharePoint Foundation, SharePoint Server can include our own field by going to the Central Administration -> Search Setting -> Metadata property Mappings.
- This means, if we add our own filed e.g. Meeting Date, we can perform search on this using FREETEXT(*,”‘+searchtext+'”) because this field will be indexed by SPF. But we can’t do a search on this field alone e.g. MeetingDate = “‘+searchText'” and also we can’t select this field like SELECT MeetingDate.
-
To get more details on this, check out this blog
-
-
URL syntax – search parameter are encoded in the URL and posted directly to the search page. E.g. results.aspx?k=sharepoint%20searc
-
Parameters
- A great article on how to use this technique to generate FullTextSqlQuery
-
-
-
-
Query Web Service based on http://Server_Name/%5BSite_Name/%5D_vti_bin/spsearch.asmx (for SharePoint Search)
-
Steps to perform the query in Console Application
-
Add service reference to the project
-
Open up the app.config file that is generated and find the security section and replace it with the text below
-
Add the code below to configure the soap client for query request
-
The “QueryServiceSoap” can be found in the app.config under the client section
-
Define and execute a query (based the query either on keyword or FullTextSqlQuery)
-
Get and display the results
- More detail can be found here and SharePoint Search forum
-
-
-
February 20, 2012
Working with SharePoint Foundation Search API
February 14, 2012
SharePoint Query Object Model – SPSiteDataQuery
- Query Lists in a site collection (SPQuery can only search item in one particular list)
- “Represents a query that can be performed across multiple lists in multiple Web sites in the same Web site collection.” – MSDN
-
Using this query
-
SPSIteDataQuery properties
-
Lists property is used to set specify which lists to include in the query :-
-
“<Lists ServerTemplate=’104′ />” – by default it is not set
Get more here
-
“<Lists BaseTemplate=’0′ />” – default is 0 which is generis list
- “<Lists Hidden=’true’ />” – include hiiden lists in the query, default is false
- “<Lists MaxListLimit=’500′ /> – default is 1000, if it set to 0 then there is no limit. The query will throw an exception if the results found exceed the limit set.
-
Lists sub elements – If you wants to include a specific lists, you can do so using the List ID
-
-
Webs property is used to set:-
- “<Web Scope=’SiteCollection’ /> – include all lists in the site collection
- “<Web Scope=’Recursive’ />” – include only lists from the current site and the site beneath it.
-
Check out his site for the performance of all the SharePoint query object model
- And also this site for using CAMLEX.Net (use Lambda expression to write CAML queries)