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

Thursday, May 23, 2013

SharePoint 2013: Consistent Search Results with Synonyms and Query Rules

When I took a class called "Information Retrieval Systems" back in the 90's at Drexel University I never thought I would have to deal with what we learned directly. While the course covered things like stop words (noise words), lingusitics, synonyms, and basic retrieval of information, it really was the foundation for what search engines are built around today.

My professor's classic example was "Time Flies Like an Arrow" and "Fruit Flies Like an Apple". In the first phrase we want "flies" to be a verb but in the second phrase we want "flies" to be a plural noun. Also, "like" means similiar in the first phrase but means enjoys in the second. Hmmm...to a computer-based search engine they are words that will be searched against a content index and there really is no context around the meanings.

Same problem exists today when users want searches to produce the results they expect versus what the search engine actually finds and deems relevant. The specific problem I solved in SharePoint 2013 Search dealt with searching for "401K".

There are several ways someone may search for 401K ->  401K, 401 K, 401-K, and 401(K). Each of these phrases without any tinkering will produce a different set of results. I found that 401K and 401(K) produced the same number of results essentially because the parenthesis are ignored. So at least I had that covered.

The main problem is "401 K" because of the space. This produces results where there is just a 401 by itself or maybe a K by itself (as a middle initial for example). The "401-K" also produced different results as some content may actually contain the dash.

I originally thought this could all be solved just by using synonyms in my SharePoint 2013 Search thesaurus file (which you upload into Search using PowerShell). That was not the case. Then I thought I could solve the problem with a query rule - also not the case.

It turns out I needed to use a combination of thesaurus entries and a query rule to get the exact same number of results for any 401K combination. The ranking may change based on which version the user enters but as long as they get all of the possible results for each version we are making fruit fly.

Since 401K and 401(K) are treated the same, my thesaurus file contained the following:

Key,Synonym,Language
401 K,401K
401 K,401-K
401K,401 K
401K,401-K
401-K,401K
401-K,401 K

My condition for the query rule was based on if any version of 401K was entered:


The action for the query rules was to change the ranked results by changing the query:

 
 
Essentially I am using quotes to produce exact matches in the content which eliminates any extra results and, by combining with OR statements, I am assuring I get everything out there no matter how 401K is represented.
 
I really thought the query rule by itself would solve the problem but the synonyms helped seal the deal:
 
 
 
My SharePoint 2013 Search instance is now displaying the same number of results with each version of the search term.


 

Wednesday, October 3, 2012

SharePoint 2013: Document Library and Search Results Document Preview with Office Web Apps Server


Check out the whole SharePoint 2013 Solution Series
New Titles Added Weekly!

I kept reading that if you have Office Web Apps Server up and running, you can connect it to your SharePoint farm and then, automagically, document previews will start appearing both in Search and in Document Libraries. I have not found any examples of what this document preview looks like so I had to take matters into my own hands.

I finally installed Office Web Apps Server on one of our staging servers and connected it to a SharePoint 2013 farm in stage. After some warming up, the document previews for Office documents started working like a charm. For the Search Results, I needed to run a full crawl again. This is because the javascript in the Display Templates uses alternate URLs (defined by crawled properties) which take the Office Web Apps server and the document preview into consideration.

I essentially followed the steps here: http://technet.microsoft.com/en-us/library/jj219455(v=office.15).aspx and used the standalone test environment section using Internal HTTP. I have some screenshots of the steps so I will probably post my installation journey as well. (UPDATE: The installation post is here.)

However, I was so excited that the Office document preview worked that I wanted to share the results. Below are some screenshots.

Search Results - Hovering over a Word document (click image to enlarge)




Document Library - Selecting the elipsis (...) on a Word document library item (click image to enlarge)
 
The previews under Office Web Apps server is only for Microsoft Office documents. Therefore PDF previews do not render. However, at least for the search results, I have a PDF Preview solution.

 

The document preview is the "cool" part about Office Web Apps server but not the business value part. The business value is the ability to edit and work with Office documents in the browser without the need for local Office applications.

What does this mean? This means that business users may interact with Office documents through SharePoint directly in the browser on any device. So whether it is a laptop, desktop, smart phone, or iPad - there are no constraints in making those last minute edits.


 

Tuesday, October 2, 2012

SharePoint 2013: PDF Preview in Search Results


Check out the whole SharePoint 2013 Solution Series
New Titles Added Weekly!

Introduction
One of the enhancements in SharePoint 2013 Enterprise Search results is the ability to preview documents using Office Web Apps Server. I am in the process of seeing what that looks like and will post an Office Web Apps server entry soon. UPDATE: Here is the post.

Anyway, the issue is that if you have Office Web Apps configured, the only documents that show previews are Microsoft Office documents (e.g. Word, Excel, etc.). The preview of PDF documents is not implemented or supported using Office Web Apps.

Therefore, I created my own PDF preview for Enterprise Search results by customizing the new search Display Templates. This works for local site search results too which I explain at the bottom of this post.

To understand overall PDF functionality and behaviors, read the whole story here.

Prerequisites
Here are some things you need in place before implementing this solution:

  • Enterprise Search Application configured and running
  • Crawled content that includes PDF documents
  • Enterprise Search Center site collection
  • SharePoint Designer 2013


Modifying the PDF Search Result Template
This is the main effort and is fairly easy. I found it better to modify the templates using SharePoint Designer 2013 although they are accessible through the SharePoint master page UI.

Step 1: Fire up SharePoint Designer 2013 and Open the Search Center Site

 
 
Step 2: Click on All Files from the left-hand navigation
If you attempt to get the files from the Master Pages, you will not see any items once you get to the Display Templates folders.


You will see the list of all files in the main window.

Step 3: Double-click on the _catalogs folder in the main window
This action displays the _catalogs structure under the left-hand navigation.


Expand the _catalogs folder, then the masterpage folder, and then the Display Templates folder.

Step 4: Click on the Search folder under Display Templates

 
The list of Search display templates is shown in the main window area.

Step 5: Right-click on Item_PDF_HoverPanel.html and select Edit File in Advanced Mode

 
 
Step 6: Paste the following code within the most inner <div>


    <object data="_#= ctx.CurrentItem.Path =#_" type="application/pdf" width="500px" height="630px" >
       <p>It appears you don't have a PDF plugin for this browser/device.
      You can <a href="_#= ctx.CurrentItem.Path =#_">click here to
       download the PDF file.</a></p>
    </object>


Note: You may find it better to use the following for width and height: width="100%" height="500px"


I actually replaced the Render Header and Render Body divs with the object code.

Step 7: Save the file
When saving the file, you may get a warning about breaking from the site definition. Click OK.
What happens behind the scenes is that the HTML changes are incorporated into the javascript version of the template (Item_PDF_HoverPanel.js).

Step 8: Test results
Perform a search from your search center that produces PDF document results. Hover over the PDF document to see the preview:


Currently the object tag uses hard-coded widths and heights. It is not using any responsive design styles. Me and my designer will be working on producing a more consistent respresentation for the PDF preview.

Local Search Implementation
There is still local site search results using the OSSSearchResults.aspx. You may implement the PDF Preview for these results as well but the modification is slightly different.

You open the site in SharePoint Designer 2013 and navigate to the Display Templates in the same fashion. However, for local (non Enterprise Search sites) there are no HTML templates - only the javascript files. You may simply copy the javascript that was created in your Enterprise Search Center site collection (when you modified the HTML) or paste the following code:

,'    <object data="', ctx.CurrentItem.Path ,'" type="application/pdf" width="280px" height="430px">'
,'       <p>It appears you don\'t have a PDF plugin for this browser/device.'
,'       No biggie... you can <a href="', ctx.CurrentItem.Path ,'">click here to'
,'       download the PDF file.</a></p>'
,'    </object>'

Save the file and preview the results by performing a local search in the SharePoint site.

It appears that the hover container in this case is being constrained in regards to its size. Therefore  I needed to use 280px for width and 430px for height. I will be working on making this more flexible.



To see what Office Web Apps server does for previewing of documents, see this post.
For Installation steps, see this post.

 

Matched Content