Sunday, April 7, 2013

Sharepoint 2013 Search REST service and 2010 deprecated

Share/Save/Bookmark


I may be the first guy dealing with sharepoint 2013 integration with sharepoint 2010. did not that(integration instead of migration) sound little unusual? yeah, my client wants to leverage Sharepoint 2013 search features(preview/result sources) only but not ready yet for complete migration. So now that we decided to use SP2013 search i want to take advantage of it in every angle not just at configuration level but even in the code. See what sharepoint 2013 search provides in my earlier post

There is demand of webparts pulling information across sitecollections and webapplication.Below are the usual options we try having sp2010 in scope

1 Extend CQWP
2 Use SPSiteDataQuery
3 Extend Search core results webpart(Fixed query)

#1 and #2 needs to loop thorough all site collections of webapp or hardcode webapp when data is across webapp and much development effort.
#3 i may consider this option but now that search 2013 in picture i do not want to extend search results webpart as sp2013 replaces scopes with result sources so chance that many things will get deprecated when migrated.

That drives me to use sp2013 search in anyway for my custom webparts.
Note that these webparts will be deployed to SP2010 server so i cannot use Sharepoint 2013 dlls/API. being said that the only option that i can think of is using any webservices that Sharepoint 2013 search exposes.

You should know that search query webservice is deprecated along with SQL syntax and now SP2013 services are RESTful.
Find out here what are deprecated in SP2013 and be aware while you migrate.
After all this research i have decided to move ahead with Sharepoint 2013 search REST service.
Here is all that you need to know on Search REST service

http://blogs.msdn.com/b/nadeemis/archive/2012/08/24/sharepoint-2013-search-rest-api.aspx
http://msdn.microsoft.com/en-in/library/fp142385.aspx

One last thing is, search REST does not support OData like other rest services(for lists) in SP2013.



Subscribe

Sunday, March 10, 2013

Control accessed from a thread other than the thread it was created on

Share/Save/Bookmark

BackgroundWorker and some basics around it.

Never thought i would get a chance to work with win forms. Here i am dancing with it.
I think its time for me to learn some basics about it.
I developed the app but its hanging while its working i.e executing the lengthy code.
I would not worry about it much but then the running information that i'm displaying on the form is not getting displayed due to it.

So what's the solution? BackgroundWorker
Yes, App gets hung as the entire operation was running in the same thread of the process.
so to avoid it a new thread must be spawn where the operations should run asynchronously.
Instead of cracking my head on spawning threads and handling them, .Net framework already
have a Class BackgroundWorker that supports this with all necessary events.

Here it is how i used it
BackgroundWorker bgWorker = new BackgroundWorker();
bgWorker.WorkerSupportsCancellation = true;
bgWorker.DoWork += DoWork;
// run the worker in async mode to avoid the app running smoothly without hanging
bgWorker.RunWorkerAsync();

public void DoWork(object sender,DoWorkEventArgs args)
{
//time consuming operations go here
}

That makes the app run cool but brought another issue
Cross-thread operation not valid: Control 'control1' accessed from a thread other than the thread it was created on
So i have to use the below delegate methods to access the objects that are created in a
thread different from current.Be aware that delegate can set only properties of the object
but cannot call any methods on it.

 delegate void SetControlValueCallback(Control oControl, string propName, object propValue);
        private void SetControlPropertyValue(Control oControl, string propName, object propValue)
        {
            if (oControl.InvokeRequired)
            {
                SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
                oControl.Invoke(d, new object[] { oControl, propName, propValue });
            }
            else
            {
                Type t = oControl.GetType();
                PropertyInfo[] props = t.GetProperties();
                foreach (PropertyInfo p in props)
                {
                    if (p.Name.ToUpper() == propName.ToUpper())
                    {
                        // append the data
                        //string existingValue = p.GetValue(oControl, propValue).ToString(); ;
                        p.SetValue(oControl, propValue, null);
                    }
                }
            }
        }




Subscribe

Tuesday, March 5, 2013

SharePoint 2013 Search Features & Administration

Share/Save/Bookmark

SharePoint 2013 Search Preview
You must be already aware that Search in SharePoint 2013 is no more as a different license similar to FAST for SP2010. FAST is now integrated in SP2013.
Below is the screen that shows what can be done as part of search administration.
Note that all these screens are taken from Sharepoint Online(Office 365). UI might differ but the features should be same in 2013 server.


Manage Schema - Allows you to configure/map crawled/managed properties. Now each managed property got setttings that include if it can be searchable/queryable/refinable/sortable on search results page without any additional xslt or xml configuration in search webparts.


Manage Authoritative Pages - Here specific content from an url/site can be ranked top over the other urls/sites. Both promotion and demotion of ranking can be done by just providing the urls.

Query Suggestion Settings - This was already there which is similar to google auto suggestions. As in when the user types a keyword or text in search text box, suggestions gets populated.
Note that for these suggestions to work, atleast 5-6 times a content link should have been accessed or clicked that result in a search. Now you have an option in UI to export or import the suggestions.


Manage Result Resources - SP2013 replaced search scopes with result sources that includes content source configuration, federated location selection and any query transformation settings using a built in query builder(no more caml query builder). SP2013 boosted its search and is all geared up with webparts driven by search. CQWP is now replaced by Content search webpart that can have a query build on top these sources to fetch results or data.


Manage Query Rules - Rules is also a new name with few settings carried from SP2010 and much more settings. Admins can configure rules on searches and if it matches a corresponding action is taken(like promoting results or ranking). This is where Best bets will be configured as well.

Manage Query Client Types - This feature allows to prioritize the execution of search query based on the type of application the request has come from. Allows to manage query throttling based on the priorities configured here. By default this option is OFF.


Usage Reports - Here admin can see the pre configured reports on search queries that will pull the data in excel format. SP2013 now do not have an analytics service application but integrated and improved as part of search component. Analytics are two types in SP2013

  •  Search Analytics - Analyzes the content on index server to improve the search relavance and for the reports
  •  Usage Analytis - Analyzes user actions/events
  
Subscribe

Saturday, January 19, 2013

Set width of div part of iframe

Share/Save/Bookmark

How to set the width(in percentage) of the element that is part of iframe?
my first attempt :
$(document).ready(function()
{
$("#divid").css("width","50%");
});
Above script did not work as the script gets triggered immediately after document
loads but before iframe renders
So i tried the below, which did not work for me(in IE 8)
$('iframe').ready()
finally i could run the script on load of iframe with below code
though it failed to set the width property as it was not able to find the div
$('iframe').load(function()
{
   $("#divid").css("width","50%");
}

To access the contents of the iframe use
$("iframe").contents().find("#divid")
Geat!! it could get the div element but could not set the css property as i
was trying to override the css property that already has important tag set
So, how do i set my css property as important through jquery?
Here you go...
$("iframe").load(function () {
        $("iframe").contents().find("#divid").attr("style", "width:50%!important");
    });

voila!!So much learnt today :)


 Subscribe