Tag Archives: Search

SharePoint number fields and search

If you are having problems making searches with number fields then you have to add them to a managed property in the Search Schema in your Search Service. Make sure that you tap the check boxes that the property is searchable. Also, make sure that the managed property data type is set to text.

How to display all of the refinement options in SharePoint 2013 Search results

By default for some reason, I could not show all of the items, I could define how many items are shown and but not get rid of the “show more” links under the refinements.

This JavaScript snippet can help you. It will hide the “short list” containing a minimum of items to be displayed, then it will show the long list and finally it will hide the “show more” link.

</pre>
<script>
 $( document ).ready(function() {
$('#unselLongList').show();
$('#unselShortList').hide();
$('#unselToggle').hide();

});
</script> 

SharePoint Search and changing the Created and LastModified fields

If you want to change the LastModified and Created fields of a list item or a document you can use this code to do that:


SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("site + web url"))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPListItem listItem = web.GetListItem(this.tbItemURL.Text);

if (this.cCreatedDate.SelectedDate != new DateTime())
listItem[SPBuiltInFieldId.Created] = this.cCreatedDate.SelectedDate;
else
listItem[SPBuiltInFieldId.Created] = listItem[SPBuiltInFieldId.Created];

if (this.cModifiedDate.SelectedDate != new DateTime())
listItem[SPBuiltInFieldId.Modified] = this.cModifiedDate.SelectedDate;
else
listItem[SPBuiltInFieldId.Modified] = listItem[SPBuiltInFieldId.Modified];

listItem.UpdateOverwriteVersion();
if (listItem.ParentList.EnableMinorVersions)
{
listItem.File.Publish("SPFileUpload");
}
if (listItem.ModerationInformation != null)
{
listItem.File.Approve("SPFileUpload");
}




web.AllowUnsafeUpdates = false;
}
}
});

The reason why the above is done is because if you simply change the date values and use the UpdateOverwireVersion() it will not be enough. The search will not be able to index right values EVEN if you check the UI or use PowerShell or SharePoint Manager etc. All of those show that the value is OK but actually is not. The manually inserted dates will not show up in search unless the item or document is published and approved. So no matter that SP says remember this :).

another thing is that this code above does not allow to set a LastModified IF you have publishing/versioning enabled. After calling the UpdateOverwriteVersion function the item or document will be checked out and remains in that state until something is done. Once you do that you are back to where you started the modified date is changed automatically by SP.

Do not have a solution yet. Maybe you have?

SharePoint Seach Query: Include or Exclude empty or null dates

This was a tricky one for me. I had to search and figure out by trial and error what works.

To filter out a datetime managed property you could use definition:

-ExpirationTime:1900-01-01..{Today}

Notice the following important things:

  • the minus sign (-) => is to not include someting that is a certain definition
  • ExpirationTime => will be replaced with your managed property name
  • 1900-01-01..{Today} => is a range, the minimum value is the “empty” or “null” value in a SharePoint datetime field. In other words the lowest possible datetime value which is 1900-01-01.

 

To include “null” or “empty” date time values just remove the minus (-) sign

SharePoint 2013 Search and Search Index Problems

If you find yourself in a situation where your search does not work you have some options:

  1. Do a full crawl
  2. Reset the search index and Do a full crawl
  3. Maybe along the way restart the SharePoint search service and/or the SharePoint timer service
  4. And if none of the above then you have to get creative

In the third option usually you get errors on your search webpart or search results. These errors do not go away and nothing seem to help, like the option one and two above.

One of the last things which you can do before going crazy 🙂 would be to manually empty the configuration cache. You do this in the following way:

  1. Find the the folder named with a GUID which has cache.ini file under the C:\ProgramData\Microsoft\SharePoint\Config
  2. Stop SharePoint Server Search 15 and SharePoint Timer Services
  3. Backup the cache.ini file
  4. Delete all files except the cache.ini file
  5. Edit the cache.ini and make sure it has only 1
  6. Save and Close the file.
  7. Start SharePoint Server Search 15 and SharePoint Timer Services
  8. Start Index Reset from SharePoint Central Administration\Application Management\Manage Service Applications\SearchServiceApplication\Index Reset
  9. You will see your  C:\ProgramData\Microsoft\SharePoint\Config\YourGUID folder will be filled up new .xml files and your cache.ini file will be modified.
  10. Next I run a full search crawl to get some search results.

NOTICE: Do not do this if you are tight on time. Depending on the amount of data in your target environment running a full crawl will take a looon long time. All depends on the server resources and the amount of data in your target environment.

There is also a script from this at codeplex:

https://spcachecleaner.codeplex.com/

Hope this helps someone. I know I have spent enough time with this problem and it is anoying.

 

SharePoint Search Service Application Errors: The search application ‘Search Service Application’ on server did not finish loading. View the event logs on the affected server for more information

If you get this (annoying) error then a possible solution is to check if your account which you use to administrate(or use the search service application) on the SQL Server side.

The search application ‘Search Service Application’ on server did not finish loading. View the event logs on the affected server for more information

Open Your SQL Server Management studio. Go to your Security folder, then Logins and then double click on your account which needs search privileges. Then go to user mapping in the new window and check that the following search service databases has privileges to your account and that the account has the “SPSearchDBAdmin” rights assigned:

Search Databases:

SharePoint_Service_Search

SharePoint_Service_Search_AnalyticsReportingStore

SharePoint_Service_Search_CrawlStore

SharePoint_Service_Search_LinksStore

Search Service Application Error
Search Service Application Error

SharePoint 2010 Full Text SQL Query – Ranged query results through Search Web Service

If you are wondering how to do a ranged search query through the SP search service pass to the query service something below where the ranged functionality is in the green color. Just specify the start position at the StartAt, notice that the minimum start position is number one not zero. Then you pass in the Count part how many items to retrieve starting from the specified location. To do a paging like functionality you have to keep count in you code what is your paging range, current position and what to retrieve.

<QueryPacket><Query domain=”QDomain”><Context><QueryText type=”MSSQLFT”><![CDATA[ SELECT your fields here FROM Scope() WHERE IsDocument = 1 AND “SCOPE” = ‘your scope name’ AND CONTAINS (some sample field,’field data to contain’) ORDER BY some field name]]></QueryText></Context><Range><StartAt>1</StartAt><Count>3</Count></Range><TrimDuplicates>false</TrimDuplicates></Query></QueryPacket>

 

Resources for SharePoint Search Results Customization

Recently I had to modify a clients search results page to show the search results as a table and not as a list. After a long battle I found a few sources which I would like to share with other people. They might come in handy.

 

First link:

http://sharepoint2010search.codeplex.com/

This is a great link from which I got alot of help. With this XSL file you can show your search results as a table.

Second link:

When you are working with search result you need sometimes to get a hold of the actual search results in XML format that is used by the xsl to be displayed to your page users. The following XSL piece of code copied and pasted in the search results webpart is going to show you the result in XML.

<xsl:stylesheet version=”1.0″
  xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:output method=”xml” version=”1.0″ encoding=”UTF-8″ indent=”yes”/>
<xsl:template match=”/”>
  <xmp><xsl:copy-of select=”*”/></xmp>
</xsl:template>
</xsl:stylesheet>

I recommend the following link for more info:

http://zimmergren.net/technical/moss-2007-customize-the-search-result-using-xslt-part-3-customize-using-sharepoint-designer-2007

It is a bit old 🙂 BUT still the information applies.

Lastly I want to share a solution I had to conjure up for the XSL file. My client wanted to have a link to a search document so that when you press that link it does not open you the document BUT it opens the document metadata properties in view mode. This was simple enough, just make an URL that points to the documents location, add the item ID to the view page of that library to show you the documents properties. One of the problems it that out of the box the ID field of the XSL is not the ID of the document in its library BUT the ID of the search result. Meaning that if you get 14 search results the ID is the position of the search result in the order it is in the retrieved through the search.

So to get it to work I had to create a new search “Metadata property” named ListItemID. This property uses the crawled property named “ows_ID” to get the documents REAL ID in the library it is located. Then I simply used this new search metadata property in my XSL and everything worked like a charm.

ANYWAY 🙂 below if the piece of XSL and HTML to display a link that allows a user to access the document properties in view mode. Alter it to get your desired functionality.

<a href=”{sitename}/Forms/DispForm.aspx?ID={number(ListItemID)}”>
View
</a>

I’ll explain a bit the above piece of code. The {sitename} will retrieve the list location where this item is located. The DispForm.aspx is a page that can be used to view documents. {number(ListItemID)} is simply a function that converts the ListItemID metadata property value into a number. You have to provide the document ID value to the aspx page. This way the ASPX page will retrieve the proper document information.

Sharepoint search results are incomplete or not working

I decided to write a few words about this problem. Mostly on a couple of a more weird situations.

This is a broad topic and I am sure people have many different kinds of problems with the SharePoint search but I’ll write here a couple of them that I encountered and have not found a clear answer yet on the web(well last time I checked 🙂 ).

Problem number 1 – Search results point to a different domain name:

This problem I first encountered a few years back. The client had created their application under a certain domain name and later they wanted to use another one. Well things were configured so that overall everything worked except search results kept pointing to the old domain name even though we indexed using the new domain name.

The problem turned out to be related to SharePoint settings in Alternate Access Mapping. Once updated the application default zone to use the new domain name search results showed up correctly. Part of the problem was created by the clients request to still keep the old domain name in use but this is another story. Eventually the clients application ended up using only one domain name.

So if you encounter problems with your search results pointing to odd places it should not point then check your AAM, check your bindings in IIS and definitely be sure that the DNS server is configured properly.

Problem number 2 – Refinement configurations do not show results when filtering by site:

This is a problem I am working currently on right now so I’ll be updating this one soon BUT it seems that after many attempts to fix this issues everything seems to be OK everywhere EXCEPT I am thinking of HTTPS. The filtering is working for sites that do not have HTTPS enabled BUT does not work on the site with HTTPS enabled. So if you have a similar problem you might want to check your search settings and overall settings regarding your SharePoint application related to HTTPS.

But I’ll be back on this one later.

Resources: SharePoint Search Center and Searching

SharePoint Server 2007 Search – How to create a fully functioning Search Center: Part 1 – UK SharePoint Team – Site Home – MSDN Blogs

SharePoint Server 2007 Search – How to create a fully functioning Search Center: Part 2

sharepoint.H@ck : Redirect Contextual Search Results to Search Centre Results Page

People Search: Use a custom Ranking Model to search in added Profile Properties

Configuring Scopes Dropdown | SharePoint Use Cases

Configuring scopes in Microsoft Search Server 2008 – Part 2 | SharePoint Use Cases

Chapter 3: Customizing and Extending the Microsoft Office SharePoint 2007 Search (Part 1 of 2)

Chapter 3: Customizing and Extending the Microsoft Office SharePoint 2007 Search (Part 2 of 2)

How to Search on Last Modified By field in SharePoint Advanced Search » SharePoint Insight

How to: Exclude part of a page from being indexed by SharePoint Search – Corey Roth

MOSS 2007: Customize the Search Result (using XSLT) – Tobias Zimmergren’s thoughts on development

MOSS 2007: Customizing the Search Results Page (XSLT) – Part 2 – Add highlighting – Tobias Zimmergren’s thoughts on development

Search for people – SharePoint Server – Microsoft Office

Excluding folders from search results in MOSS 2007 | Mrin’s Blog

What’s new for end users in SharePoint Search 2010

Customize the People Search Results – Part 2 | Sharepointology

Programmatically Disabling or Enabling Site Search Visibility « Geoff Varosky’s Blog

How to: Change the Properties Returned in the Core Search Results

SharePoint People Search – Lessons learned. Part 1: Covering the basics – Waldek Mastykarz

SharePoint People Search – Lessons learned. Part 2: Programmatically running search queries – Waldek Mastykarz

Using Enterprise Search Property Filters in SharePoint Server 2007

Using the SharePoint Search API with URL Query String Parameters – SharePoint for End Users

Mystery Solved – Crawled Properties in SharePoint (Part 1) – Anne Stenberg’s Blog – Site Home – TechNet Blogs

Enterprise Search SQL Syntax Reference

WSS Custom Search – The Bamboo Team Blog – Bamboo Nation

Leverage Search Crawl rules and Content Class property to refine SharePoint Search result « Chris’s SharePoint Reflections

Indexing pdf documents with Adobe Reader v.8 and MOSS 2007 – Filter Central – Site Home – MSDN Blogs

Index PDF documents on SharePoint using Adobe PDF IFilter 9 – Harold van de Kamp’s Blog

Excluding Various SharePoint Items from Search Results on Internet-Facing MOSS Sites – Random Musings of Jeremy Jameson – Site Home – MSDN Blogs

Contentclass Property

Limiting the Search Scope using contentclass in a Property Query Scope Rule «                    Are you a user?

SharePoint Server 2007 Search – How to create a fully functioning Search Center: Part 2 – The SharePoint Guys – Site Home – MSDN Blogs