Pages

Showing posts with label SharePoint Search. Show all posts
Showing posts with label SharePoint Search. Show all posts

Tuesday, August 19, 2014

SharePoint site content doesn’t show in search results in SharePoint 2013

Problem

A site collection (Its a Search Center site collection. We had some lists and list items under the site collection) and its contents are not listed in search results; though I have added site url as a content source in search service application.

Solution

Go to Site setting and Click on Search and offline availability.

image 

Then select the radio button under “Allow this site to appear in search results?”

image Run the crawler again and you content will be listed under search results.

Solution Background

By default “Yes” option will be selected if we create a site collection with a template other than the “Basic Search Center”. 

Friday, January 3, 2014

Show SharePoint Search Results in SPGrid View - programmatically

Introduction

As I said in my earlier post I was working and trying some stuff related to SharePoint 2013 search server. Today I was trying to query and display search results in SPGrid view. I have uploaded my solution package in my drive; Please download and look for the code if you need. (Download)
I used certain blog posts as references.


Solution

Create a web part (I have created visual web part). On the .ascx page initiate a SPGridView. (For that you can use the below code)
On the ascx.cs page do the blow
On page load



   

        protected void Page_Load(object sender, EventArgs e)
        {

           string query = string.Format("Project*"); //You can give what ever query you need
           ExecuteFederatedQuery(query);
        }

 


And also you need below both methods. So please paste them also on the ascx.cs page


   

        void ExecuteFederatedQuery(string queryText)
        {
            long lastupdate;
            bool crawl;

            //Create Search service proxy
            SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy
       (SPServiceContext.GetContext(SPContext.Current.Site));

            
            LocationConfiguration locationConfig = null;
        
            LocationConfiguration[] locationConfigurations = proxy.GetLocationConfigurations(out lastupdate, out crawl);//Get all federated search locations. 
            Location location;
            LocationList locationList = new LocationList();
            QueryManager queryManager = new QueryManager();
            foreach (LocationConfiguration locationConfiguration in locationConfigurations)
            {
                //Specify any federated search location. Here default search location will be captured.  
                if (locationConfiguration.InternalName.Equals("LocalSearchIndex"))
                {
                    locationConfig = locationConfiguration;
                    break;
                }
            }
            location = new Location(locationConfig.InternalName, proxy);
            //Set the userQuery
            location.UserQuery = queryText;
            locationList.Add(location);
            queryManager.Add(locationList);
            queryManager.IsTriggered(locationList);
            XmlDocument xDoc = queryManager.GetResults(locationList);//Return the query
            if (xDoc != null)
            {
                DataSet resultSet = new DataSet();
                resultSet.ReadXml(new XmlNodeReader(xDoc));

                SortData(resultSet.Tables[1]);

            }


        }

        private void SortData(DataTable resultTable)
        {

            //Sort the results by Title name
            DataView dataView = resultTable.DefaultView;
            dataView.Sort = "Title ASC";
            DataTable resuDataTable = dataView.ToTable();


            var fileTable = new DataTable();

            DataRow fileRow;
            fileTable.Columns.Add("Title");
            fileTable.Columns.Add("Modified_Date");
            fileTable.Columns.Add("Authors");
            fileTable.Columns.Add("DocURL");

            foreach (DataRow resultRow in resuDataTable.Rows)
            {

                fileRow = fileTable.NewRow();
                fileRow["Title"] = resultRow["title"];
                fileRow["DocURL"] = resultRow["url"];
                fileRow["Modified_Date"] = resultRow["lastmodifiedtime"];
                fileRow["Authors"] = resultRow["author"];

                fileTable.Rows.Add(fileRow);
            }

            //Assign the datasource
            spGridView.DataSource = fileTable;
            spGridView.DataBind();

            
        }

 

Conclusion

The results will look something like this.


Wednesday, January 1, 2014

SharePoint 2013 Search is not working - "Search has encountered a problem that prevents results from being returned"

Introduction

Happy New Year! I was working on SharePoint search where our client had a requirement on retrieving data through SharePoint search. Hopefully my upcoming posts will be related to SharePoint Search Server.

Problem Background

Suddenly my Search Service stopped working and it didn’t return results. My “Search Results” Web part show the error with the message “Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.” See the screenshot below. Please note that I couldn’t capture the screenshots from my server and the screenshots are taken from the net.

Then when I try to open Search Service Application there also, I was able to see some error message.

Under “System Status (Name of Search application service => search administration => System Status)”; “Searchable items” showed “All Errors”.

And also Search Application Topology showed a error message as 
“Search Issue Unable to load the topology from the Search Administration component”. Ideally this should show something like this (See the below Screenshot).


When I try to see ULS log; I got the below error log

Content Plugin can not be initialized - list of CSS addresses is not set.


Solution Background

The issue is that SharePoint Search is unable to load the topology from the Search Administration component.

Solution 01

Recreate the Search Service Application using the Central Administration

Solution 02

The first Option didn't work for me. So I created the Search Service Application through the PowerShell which worked fine. Please go to the below Url and you can find the script to create service application from the scratch. http://melcher.it/2012/07/sharepoint-2013-create-a-search-service-application-and-topology-with-powershell/

Conclusion

There are plenty of suggestions on msdn. Please check for this solution as well. If this works say thanks to Maximilian Melcher (http://melcher.it/about-me/)