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

Monday, December 12, 2011

Powershell and search metadata properties

Scenario:
While working with one of client we created a quick script for creating / recreating metadata properties for search. Thought of sharing :)

This script will drop exiting property with same name [ if exist ] and create it again. Also I have provided samples of different field types.

Code:


#####################################################################
# Main Function
#####################################################################

function PromptUser {param($message)

write-host -f Red $message

write-host -f Red "Press enter to continue ... and N to exit"

$keyentered = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

If ($keyentered.VirtualKeyCode -eq 78)
{
exit
}
}

function DropMetadataProperties {param ($ServiceApplicationName, $MetadataPropertyName)

$category = Get-SPEnterpriseSearchMetadataCategory –Identity "Business Data" -SearchApplication $searchapp

If (Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $MetadataPropertyName -ea "silentlycontinue")
{
write-host -f Green "MetaProperty already exists, we delete it so it can be reacreated."
$prop = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $MetadataPropertyName
$prop.DeleteAllMappings()
$prop.Delete()
$searchapp.Update()
}

if (!$?)
{
PromptUser("An error has occurred")
}
}

function CreateMetadataProperties {param ( $ServiceApplicationName, $MetadataPropertyName, $CrawledProperty, $VariantType, $Type, $HasMultipleValues, $IsSortable)

$category = Get-SPEnterpriseSearchMetadataCategory –Identity "Business Data" -SearchApplication $searchapp

$crawledproperty = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category -VariantType $VariantType -Name $CrawledProperty
If (!($crawledproperty -eq $null))
{
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $MetadataPropertyName -Type $Type

If ($IsSortable -eq $True)
{
$managedproperty.MaxCharactersInPropertyStoreIndex = 64
$managedproperty.Update()
}

If ($HasMultipleValues -eq $True)
{
$managedproperty.HasMultipleValues = $true
$managedproperty.Update()
}


New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty
}
else
{
write-host -f Red "Crawl property is missing, you might need to recrawl your content source to get it."
}

if (!$?)
{
PromptUser("An error has occurred")
}
}

###################################################################################
# Drop metadata properties
###################################################################################

$searchapp = Get-SPEnterpriseSearchServiceApplication
if (!$?)
{
PromptUser("Could not find a valid Search Service Application.")
EXIT
}

$searchAppName = $searchapp.Name


# Client Metadata properties
DropMetadataProperties $searchAppName "xxClientName"

###################################################################################
# Create metadata properties
###################################################################################

# VariantType = (31 for string , 20 for integer , 11 for boolean , 64 for datetime )
# Type = (1 for string , 2 for integer , 5 for Yes/No , 4 for datetime )

### Text Field
DropMetadataProperties $searchAppName "xxClientName"
CreateMetadataProperties $searchAppName "xxClientName" "Client.ClientName" 31 1 $False $True

### Integer Field
DropMetadataProperties $searchAppName "xxClientID"
CreateMetadataProperties $searchAppName "xxClientID" "Clients.ClientID" 20 2 $False $False

### YES/No Field
DropMetadataProperties $searchAppName "xxIsActive"
CreateMetadataProperties $searchAppName "xxIsActive" "Clients.IsActive" 11 5 $False $False

### Date Field
DropMetadataProperties $searchAppName "xxEndDate"
CreateMetadataProperties $searchAppName "xxEndDate" "Clients.EndDate" 64 4 $False $False
Please do leave comments on if it worked for you or any suggestion to improve it.

Saturday, December 4, 2010

Noise keywords in search

Scenario:
Here's a quick list of noise keywords in search

search noise

Please note this file is editable and you can go to Index server and add some more if required

Friday, December 3, 2010

Sharepoint scopes update now option

Scenario:
I certainly have not posted this but I read in blogs and twitter people complaining that SP2010 is missing option to kick off instant update of scopes.Only option is not wait for 10-15 min.

Solution:
Not right, there is an option.

1. Create a new scope or edit an exiting one.
2. Click on 'Search Administration' from the left menu to navigate to home page.
3. Here's the option to start instant update of scope.

scopeupdate

While I feel Microsoft should have added this option within Scope Administrative screen's. But ... :)

Wednesday, April 7, 2010

SharePoint 2010 Search Core Result webpart raw output

Scenario:
This is for my reference as I always need to see the raw output of search results before I can format it.

Solution:
Here's the XSLT to get RAW output as well as Sample output

XSL for RAW output:

<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>
SP2010 Output :
<All_Results>
<Result>
<id>1</id>
<workid>2338</workid>
<rank>72021170</rank>
<title>Documents</title>
<author></author>
<size>0</size>
<url>http://sp2010/Documents/Forms/AllItems.aspx</url>
<urlEncoded>http%3A%2F%2Fsp2010%2FDocuments%2FForms%2FAllItems%2Easpx</urlEncoded>
<description>This system library was created by the Publishing feature to store documents that are used on pages in this site.</description>
<write>4/7/2010</write>
<sitename>http://sp2010</sitename>
<collapsingstatus>0</collapsingstatus>
<hithighlightedsummary>This system library was created by the Publishing feature to store documents that are used on pages in this site. <ddd /> <c0>ScriptGenerator</c0> <ddd /> </hithighlightedsummary>
<hithighlightedproperties>
<HHTitle>Documents</HHTitle>
<HHUrl>http://sp2010/Documents/Forms/AllItems.aspx</HHUrl>
</hithighlightedproperties>
<contentclass>STS_List_DocumentLibrary</contentclass>
<isdocument>False</isdocument>
<picturethumbnailurl></picturethumbnailurl>
<popularsocialtags />
<picturewidth>0</picturewidth>
<pictureheight>0</pictureheight>
<datepicturetaken></datepicturetaken>
<serverredirectedurl></serverredirectedurl>
<ows_metadatafacetinfo></ows_metadatafacetinfo>
<fileextension>ASPX</fileextension>
<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_List_DocumentLibrary16.gif</imageurl>
</Result>
</All_Results>
MOSS 2007 Output :
<All_Results> 
<Result>
<id>1</id>
<workid>194189</workid>
<rank>1000</rank>
<title>Some Title</title>
<author>Last, First</author>
<size>64436</size>
<url>http://yourserver/yourfile</url>
<urlEncoded>http%3A%2F%2Fyourserver%2Fyourfile</urlEncoded> <description></description>
<write>1/7/2010</write> <sitename>http://yourserver/yoursite</sitename>
<collapsingstatus>0</collapsingstatus> <hithighlightedsummary>Summary</hithighlightedsummary>
<hithighlightedproperties>
<HHTitle>Title</HHTitle>
<HHUrl>http://yourserver/yoursite</HHUrl>
</hithighlightedproperties>
<contentclass>STS_ListItem_PictureLibrary</contentclass>
<isdocument>0</isdocument>
<picturethumbnailurl>/_layouts/images/icgen.gif</picturethumbnailurl>
<imageurl imageurldescription="Result of type: document">/_layouts/images/STS_ListItem16.gif</imageurl>
</Result>
</All_Results>

Sunday, March 28, 2010

A-Z Navigation for Core Search Result Webpart

Scenario:
XSLT means flexibility , and so for one of the requirement I was given the task to display Core Search Result Webpart results to support A-Z navigation.

Solution:
You need to patient first. I am providing the modified copy of Core Search Result Webpart XSLT which supports this. So download and use it as it is.

Download ( free ) for SP 2007

Download ( free ) for SP 2010


Result will look like :
az

Added Variables and Templates:

  <!-- Added some new variables : Start -->
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

<xsl:key name="keyTitle" match="Result" use="translate(substring(title,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
<!-- Added some new variables : End -->
<xsl:template name="Alphabets">
<Alpha>A</Alpha>
<Alpha>B</Alpha>
<Alpha>C</Alpha>
<Alpha>D</Alpha>
<Alpha>E</Alpha>
<Alpha>F</Alpha>
<Alpha>G</Alpha>
<Alpha>H</Alpha>
<Alpha>I</Alpha>
<Alpha>J</Alpha>
<Alpha>K</Alpha>
<Alpha>L</Alpha>
<Alpha>M</Alpha>
<Alpha>N</Alpha>
<Alpha>O</Alpha>
<Alpha>P</Alpha>
<Alpha>Q</Alpha>
<Alpha>R</Alpha>
<Alpha>S</Alpha>
<Alpha>T</Alpha>
<Alpha>U</Alpha>
<Alpha>V</Alpha>
<Alpha>W</Alpha>
<Alpha>X</Alpha>
<Alpha>Y</Alpha>
<Alpha>Z</Alpha>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<xsl:param name="Rows" />
<xsl:for-each select="$Rows[generate-id(.) = generate-id(key('keyTitle', translate(substring(title,1,1),$smallcase,$uppercase))[1])]">
<xsl:sort select="translate(substring(title,1,1),$smallcase,$uppercase)" order="ascending" />
<xsl:if test ="string-length(title) &gt; 0">
<tr>
<td class="letterHeading" colspan="7">
<a>
<xsl:attribute name ="name">
<xsl:value-of select="translate(translate(substring(title,1,1),$smallcase,$uppercase),$smallcase, $uppercase)" />
</xsl:attribute>
</a>
<xsl:value-of select="translate(substring(title,1,1),$smallcase,$uppercase)" />
</td>
</tr>
<tr>
<td>
<xsl:variable name="thisTitle" select="translate(substring(title,1,1),$smallcase,$uppercase)"/>
<xsl:call-template name="DisplayItemRow">
<xsl:with-param name="curTitle" select="$thisTitle" />
</xsl:call-template>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="DisplayItemRow">
<xsl:param name="curTitle" />
<xsl:for-each select="key('keyTitle', translate(substring(title,1,1),$smallcase,$uppercase))[translate(substring(title,1,1),$smallcase,$uppercase) = $curTitle]">

<!-- Copied the content of OOTB Result template : Start -->
<xsl:variable name="id" select="id"/>
<xsl:variable name="url" select="url"/>

<span class="srch-Icon">
<a href="{$url}" id="{concat('CSR_IMG_',$id)}" title="{$url}">
<img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
</a>
</span>
<span class="srch-Title">
<a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">
<xsl:choose>
<xsl:when test="hithighlightedproperties/HHTitle[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
</a>
<br/>
</span>

<xsl:choose>
<xsl:when test="$IsThisListScope = 'True' and contentclass[. = 'STS_ListItem_PictureLibrary'] and picturethumbnailurl[. != '']">
<div style="padding-top: 2px; padding-bottom: 2px;">
<a href="{$url}" id="{concat('CSR_P',$id)}" title="{title}">
<img src="{picturethumbnailurl}" alt="" />
</a>
</div>
</xsl:when>
</xsl:choose>
<div class="srch-Description">
<xsl:choose>
<xsl:when test="hithighlightedsummary[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedsummary" />
</xsl:call-template>
</xsl:when>
<xsl:when test="description[. != '']">
<xsl:value-of select="description"/>
</xsl:when>
</xsl:choose>
</div >
<p class="srch-Metadata">
<span class="srch-URL">
<a href="{$url}" id="{concat('CSR_U_',$id)}" title="{$url}" dir="ltr">
<xsl:choose>
<xsl:when test="hithighlightedproperties/HHUrl[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="url"/>
</xsl:otherwise>
</xsl:choose>
</a>
</span>
<xsl:call-template name="DisplaySize">
<xsl:with-param name="size" select="size" />
</xsl:call-template>
<xsl:call-template name="DisplayString">
<xsl:with-param name="str" select="author" />
</xsl:call-template>
<xsl:call-template name="DisplayString">
<xsl:with-param name="str" select="write" />
</xsl:call-template>
<xsl:call-template name="DisplayCollapsingStatusLink">
<xsl:with-param name="status" select="collapsingstatus"/>
<xsl:with-param name="urlEncoded" select="urlEncoded"/>
<xsl:with-param name="id" select="concat('CSR_CS_',$id)"/>
</xsl:call-template>
</p>

<!-- Copied the content of OOTB Result template : End -->

</xsl:for-each>
</xsl:template >

<xsl:template name="Header">
<tr>
<th>Title</th>
</tr>
</xsl:template>

<xsl:template name="Footer">
<tr>
<th>Title</th>
</tr>
</xsl:template>
Modified Templates:
 <xsl:template name="dvt_1.body">
<!-- Added some more new variables : Start-->
<xsl:variable name="Rows" select="All_Results/Result" />
<xsl:variable name="dvt_RowCount" select="count($Rows)" />
<xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
<!-- Added some more new variables : Start-->

<div class="srch-results">
<xsl:if test="$ShowActionLinks">
<div class="srch-sort">
<xsl:value-of select="$ResultsBy" />
<xsl:if test="$ViewByUrl">
|
<a href ="{$ViewByUrl}" id="CSR_RV" title="{$ViewByValue}">
<xsl:value-of select="$ViewByValue" />
</a>
</xsl:if>
<xsl:if test="$AlertMeLink">
|
<span class="srch-alertme" >
<a href ="{$AlertMeLink}" id="CSR_AM2" title="{$AlertMeText}">
<img style="vertical-align: middle;" src="/_layouts/images/bell.gif" alt="" border="0"/>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:value-of select="$AlertMeText" />
</a>
</span>
</xsl:if>
<xsl:if test="string-length($SrchRSSLink) &gt; 0">
|
<a type="application/rss+xml" href ="{$SrchRSSLink}" title="{$SrchRSSText}" id="SRCHRSSL">
<img style="vertical-align: middle;" border="0" src="/_layouts/images/rss.gif" alt=""/>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:value-of select="$SrchRSSText"/>
</a>
</xsl:if>
</div>
<br />
<br />
</xsl:if>
</div>

<!-- Added to render the A-Z Navigation Bar : Start-->
<ul>

<xsl:variable name="AlphabetNodes">
<xsl:call-template name="Alphabets"></xsl:call-template>
</xsl:variable >

<xsl:variable name ="AlphabetName">
<xsl:apply-templates select="msxsl:node-set($AlphabetNodes)/Alpha">
<xsl:sort select="." order ="ascending"/>
</xsl:apply-templates>
</xsl:variable>

<xsl:variable name="TitleNames">
<xsl:for-each select="$Rows[generate-id(.) = generate-id(key('keyTitle', translate(substring(title,1,1),$smallcase,$uppercase))[1])]">
<xsl:value-of select="translate(substring(title,1,1),$smallcase,$uppercase)" />
</xsl:for-each >
</xsl:variable>

<xsl:for-each select="msxsl:node-set($AlphabetNodes)/Alpha">
<xsl:if test ="position() &lt;= count(msxsl:node-set($AlphabetNodes)/Alpha)">
<xsl:variable name ="char" select ="child::node()[position()]"/>
<li style="display:inline;list-style-type:none;padding-right:3px;">
<xsl:choose>
<xsl:when test="contains($TitleNames,$char)">
<span>
<a>
<xsl:attribute name ="href">
#<xsl:value-of select ="child::node()[position()]"/>
</xsl:attribute>
<xsl:value-of select ="child::node()[position()]"/>
</a>
</span>
</xsl:when >
<xsl:otherwise >
<span class="empty">
<xsl:value-of select ="child::node()[position()]"/>
</span>
</xsl:otherwise>
</xsl:choose >
</li>
</xsl:if>
</xsl:for-each >

</ul>
<!-- Added to render the A-Z Navigation Bar : End-->

<div class="directoryListing">
<table class="standardDataTable">
<xsl:call-template name="Header" />
<xsl:call-template name="dvt_1.rowview">
<xsl:with-param name="Rows" select="$Rows" />
</xsl:call-template>
<xsl:call-template name="Footer"/>
</table >
</div >
<xsl:call-template name="DisplayMoreResultsAnchor" />
</xsl:template>

Saturday, November 7, 2009

Access Denied while scheduling full crawl schedule

Scenario:
I have setup a new box and when I was trying to set up schedule for default content source in SSP and I got following Error : Acess Denied

access denied

Solution:
KB Article

Saturday, October 24, 2009

SharePoint 2010 : Search Comparision

search

Wednesday, October 14, 2009

Setting default search scope to This List

Scenario:
You want to set default search scope to This List.

Options:
#1. Either you can add a Content Editor Web Part to the page which the below script on the page where you need the search scope to be This List.

#2. Otherwise you can add it master page if you want this behavior through out you site.

Code:

<script type="text/javascript">
var a = document.getElementById('ctl00_PlaceHolderSearchArea_ctl01_SBScopesDDL');

a.options[0].selected = true ; </script>

Tuesday, September 22, 2009

Changing search scope default value

Scenario:
By default the search scope default value is set for All Sites, and we wanted it to default to People.

search scope

Solution:
Simple setting change
1. Site Action > Site Settings > Search Scope
2. Click on the link "Search Dropdown"
3. From the default scope drop down change the value to People, also you can adjust the order in which values appear in scope drop down

setting scope

Sunday, July 19, 2009

List Definition with no search results

Scenario:
Once in a while we need some hidden list to store some information which we programtically want to consume without letting end users know about it.

Another important thing is that search should not display anything from this list.

Solution:
List Definition does support a tag Privatelist to do similar to this.

Example:

<List 
Name="Private Documents"
Title="Private Documents"
Description="This library store some internal documents used with in the site."
PrivateList="TRUE"
Direction="0"
BaseType="1"
Url="PrivateDocuments"
DisableAttachments="TRUE"
Type="101"
Id="NewGUID"
xmlns="http://schemas.microsoft.com/sharepoint/">
.....
</List>
Note:
Earlier in this ( post ) I already showed you how to create an instance of any list with NoCrawl=True , making that particular instance of the list hidden from search results. Above example is different in the sense , that here list definition itself is hidden and so will be all the instances created from this list definition.

Thursday, July 9, 2009

Sharepoint Wild card property Search

Scenario:
SharePoint has out of box approximately 128 mapped properties and its very easy to add our own properties. One advantage of these properties is refined search or advanced search. One thing which is not documented is wildcard property search.

Sharepoint does support wildcard property search

Notes 1:
Only prefix matching is allowed in property searches, which means that you must have at least the first letter of the property value to complete the search.

Examples:

1. filename:program ( without any quotes )

This will return all the results with items starting with program. i.e. programming.docx , program.xslx, etc . This is kind of stem search

2. filename:"program" ( with quotes )

This will return all the results with items with program. i.e. "program.xslx" only

Note 2:
You can search for multiple property values in one query. The spaces between property:value entries are interpreted as an AND.This is only true if your query contains different properties.

Examples:
1. author:"Sandeep" filetype:docx

Search will returns Word 2007 documents that are authored by Sandeep

Note 3:
You can search for multiple property values in one query. If you use the same property Search Server interprets the space between the property:value entries as an OR.

Examples:
1. author:"Sandeep" author:"Srini"

This query will returns items authored by Sandeep and items authored by Srini.

Note 4:
You can also use wildcard characters in property searches. Wildcard searches include characters, such as “*”, which allows the search engine to substitute any number of characters and “?”, which allows the search engine to substitute any single character.

Prefix matching is also required when you use wildcard characters. This means that you cannot insert wildcard characters in the middle of a property value such as W*ton or at the beginning of a property value such as *ington.

Examples:
1. author:"Sandeep" filetype:doc*

This query will returns documents authored by Sandeep in docx or doc format.

Saturday, June 13, 2009

Sharepoint search case-sensitive url issue

Scenario:
I faced this problem long back but forget to blog about it. Sharepoint search has a known issue : case-sensitive url issue.

What that mean is , both the Url listed below will be treated as one. So if Sharepoint search hits the first Url , it will crawl the Url content but will ignore the other one.

http://localhost/_layouts/custompage.aspx?Code=axVP <--
http://localhost/_layouts/custompage.aspx?Code=AXvp <--

Situations :
Reading files from other OS based system which supports case sensitive filenames

Solution:
Microsoft hot fix to enable the case sensitive file names search.
Also I will recommend to avoid designing any custom solution with case sensitive parameters.

Note: Hotfix will not solve the issue of Url case sensitivity.It will solve the issue of document name being case sensitive.

Article:
Hotfix Details

Follow on Twitter

Friday, April 3, 2009

Office Server Search and Excel service missing

Scenario:
While installing new MOSS server , I found some of the services missing. After checking all the components, I found out the cause.

Reason:
It was my mistake. I choose Web-Front End option and not Complete install.

Take away:
Office SharePoint Server Search service missing : This can be because of more than one reasons
a. You might have installed only WSS
b. Web Front end option installed, use Complete install.

Excel Calculation Service missing : This can be because of more than one reasonsa. You might have installed only WSS
b. Web Front end option installed, use Complete install.
c. You have installed MOSS Standard edition , its only available with Enterprise version

Article
Similar post

Monday, February 16, 2009

Reading all available content sources

Scenario:
While writing a small utility I was suppose to read all the avilable content sources.

Solution:
Small console application

Code:

using System;
using System.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
class Program
{
static void Main(string[] args)
{
string siteURL = "http://localhost";
SearchContext context;
using(SPSite spSite = new SPSite(siteURL))
{
context = SearchContext.GetContext(spSite);
}
Content sspContent = new Content(context);
ContentSourceCollection sspContentSources = sspContent.ContentSources;
foreach (ContentSource contentSource in sspContentSources)
{
Console.WriteLine("Content Source: " + contentSource.Name )
}
}
}

Monday, January 26, 2009

SharePoint Search bug

Scenario:
I was trying to do a small demo for the search scope and create a new scope to only restrict results to pdf files.

So I enabled the File Extension property for Use in Scopes. Created a new Scope and added the rule to include only File Extension = pdf. When I tried searching for a file I uploaded 2 days back , I couldn't find it.

Bug :

Try 1:
a) Uploaded a file 'ITTP_SharePoint_Contents.pdf' ( underscores )
b) Search with Keyword : Sharepoint
c) File is not in the result set.

Try 2:
a) Uploaded a file 'ITTP SharePoint Contents.pdf' ( no underscores but spaces this time )
b) Search with Keyword : Sharepoint
c) File appears right on the top of result set.

Try 3:
a) Uploaded a file 'ITTPSharePointContents.pdf' ( no spaces this time )
b) Search with Keyword : Sharepoint
c) File is not in the result set.

I tried all these options in Google and I got the file in all three cases, which is what I was expecting.

Solution:
I will certainly call it a Bug, and will recommend the clients to avoid using Underscores and to keep spaces in the file name if you want to search by the file name. I know each space translate back to %20, which means 3 character space, but thats the way it is.

Update:
I got a chance to talk to my collegue Sahil over the same and he mentioned that this has been done intentionally in SharePoint Search to increase performance. Also as SharePoint search basically uses SQL Full Text, wildcard search will be limited as we have seen above.

You can certainly try to do some modification to search webpart or can write a custom search webpart, and modifying the query keyword
i.e SharePoint --->> %SharePoint% to force wild card search.

That way you will get results in all three scenerios's but performance might become an issue then.

:-(

Monday, December 8, 2008

Search Url query string parameters

Search Query string parameters:
Search Center Url supports various query string parameters.

Here's the description :

K= Search key

http://localhost/search/results.aspx?k=sharepoint
This url searches for keyword sharepoint

v1= Order By
http://localhost/search/results.aspx?k=sharepoint&v1=date
This url searches for keyword sharepoint and orders the search results by modified date

s= Search Scope
http://localhost/search/results.aspx?k=sharepoint&s=All%20Sites
This url searches for keyword sharepoint in all sites scope

start1= Page start
http://servername/search/results.aspx?k=sharepoint&start1=15
This url searches for keyword sharepoint and returns results from 15th record

Display search xml output

Scenario:
You want to see the search results xml output
Solution:
Use the following xslt for the search web-part, this will output the raw xml output.
Code:

<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>
Article:

Sunday, November 2, 2008

Adding a new metadata property to search

Scenario:
You want to add new Managed Properties to the SharePoint Search results.

Solution:
Shared Service Administration Web Application provide you the options to add new Managed Properties

Steps:
1. Navigate to Central Administrative Web Application
2. Click on 'SharedServices1' link from the left navigation
3. Click on 'Search Settings'
4. Click on 'Metadata property mappings'
5. Click on 'New Managed Property'
6. Type a Name for the property and select the Type
7. Click on the 'Add Mapping' button from the bottom section
8. Search for the property or the column name , you want to map.
Note: If you are not able to find the column name or property you want to map, full crawl might be required for SharePoint Search to pickup the proprty.
9. Click 'OK' Button to add it
10. Run a full crawl for the Content Source containing the column infomation

Article:
http://sharepointmagazine.net/technical/customisation/customizing-search-series-creating-new-managed-properties-from-bdc-crawled-content

Friday, October 24, 2008

Programatically searching sharepoint

Scenario:
You want to write custom code to return the results of a keyword query

public ResultTableCollection Search(string keyword) {

KeywordQuery query = new KeywordQuery(ServerContext.Current);
query.QueryText = keyword;
return query.Execute();
}
This code creates an instance of the KeywordQuery class. This class allows you to search SharePoint for existing keywords. You simply set the QueryText property to a keyword query and call the Execute method.

If you want to use a SQL query, you must use the FullTextSqlQuery class.
using (SPSite site = new SPSite("http://localhost")){

using( SPWeb web = site.OpenWeb()){

FullTextSqlQuery query = new FullTextSqlQuery(site);

query.QueryText =

"Select Title, Rank, Path from Scope() where freetext('Search Keyword') AND site='http://moss2007' ORDER BY Rank desc";

query.RowLimit = 100;
query.ResultTypes = ResultType.RelevantResults;

ResultTableCollection results = query.Execute();
ResultTable result = results[ResultType.RelevantResults];

while (result.Read()){
Console.WriteLine(result[0].ToString() + ", " + result[1].ToString() + ", " + result[2].ToString());
}
}
}

Wednesday, October 15, 2008

While searching you are not getting results for a particular site or list

Scenario:
Access is denied. Check that the Default Content Access Account has access to this content, or add a crawl rule to crawl this content. (The item was deleted because it was either not found or the crawler was denied access to it.)

Solution:
Access Denied , that means its clearly a Permission Issue.

Few things to try :
1. Check for the Site Collection > Site Settings > Search Visibility > Make sure its set to Yes
2. Check for the List Settings > Advanced Options > Search option should be Yes
3. Make sure Default Content Access account have access to the site. You can check it by logging to the site using that account.
4. Create a new crawl rule for the site with a different account which can access the site.