SharePoint search 功能的定制开发
2011-07-10 22:33
357 查看
概要
客户要求改善SharePoint2007的搜索功能,我们要自定义开发搜索功能,一翻调查和研究,sharepoint的搜索用到KeywordSearchQuery和FullTextSearchQuery两种方式,因为我们要用到自定义的sharepointlist字段做为过虑条件,所以采用FullTextSearchQuery来开发。
设计
FullTextSearchQuery做sharepoint2007二次开发要用到以下组件:
在sharepoint2007中,我们如下scope():
默认的有people和allsites两个scope。我们以Allsites举例。
sharepointContentsources在爬虫时的流程图(方便理解scope()内容的来源)
以下是查询的流程图:
用户使用查询时,sharepoint对于用户的安全检查:
以上说明仅供读者了解sharepoint查询时要做的工作.
Microsoft.SharePoint.Search.Query命名空间包括三个查询类:
FullTextSqlQuery使用此类可执行SQL语法搜索查询。
KeywordQuery使用此类可执行关键字语法搜索查询。
为自定义搜索应用程序选择查询类
若要确定用于自定义搜索应用程序(FullTextSqlQuery或KeywordQuery)的适当的类,请考虑希望应用程序代码支持的搜索查询中的复杂级别。
下面的列表标识仅受使用FullTextSqlQuery类的SQL搜索语法支持的附加查询元素:FREETEXT、CONTAINS、LIKE和ORDERBY.
代码设计
而为什么FullTextSqlQuery的属性是这样设置的,因为能过moss工具产生的xml结果图如下:
如果sharepoint里item内容语言是en-us的话,一定要在IE浏览器里设置:
把english[en]放到最上面。
作者:springyang
出处:http://www.cnblogs.com/springyangwc/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
客户要求改善SharePoint2007的搜索功能,我们要自定义开发搜索功能,一翻调查和研究,sharepoint的搜索用到KeywordSearchQuery和FullTextSearchQuery两种方式,因为我们要用到自定义的sharepointlist字段做为过虑条件,所以采用FullTextSearchQuery来开发。
设计
FullTextSearchQuery做sharepoint2007二次开发要用到以下组件:
1 | using Microsoft.Office.Server; |
2 | using Microsoft.Office.Server.Search; |
3 | using Microsoft.Office.Server.Search.Query; |
默认的有people和allsites两个scope。我们以Allsites举例。
sharepointContentsources在爬虫时的流程图(方便理解scope()内容的来源)
以下是查询的流程图:
用户使用查询时,sharepoint对于用户的安全检查:
以上说明仅供读者了解sharepoint查询时要做的工作.
Microsoft.SharePoint.Search.Query命名空间包括三个查询类:
FullTextSqlQuery使用此类可执行SQL语法搜索查询。
KeywordQuery使用此类可执行关键字语法搜索查询。
为自定义搜索应用程序选择查询类
若要确定用于自定义搜索应用程序(FullTextSqlQuery或KeywordQuery)的适当的类,请考虑希望应用程序代码支持的搜索查询中的复杂级别。
下面的列表标识仅受使用FullTextSqlQuery类的SQL搜索语法支持的附加查询元素:FREETEXT、CONTAINS、LIKE和ORDERBY.
代码设计
01 | public class SharePointSearch |
02 | { |
03 |
04 | #regionFields |
05 |
06 | string queryStr= @"selecthitHighlightedProperties,size,Write,author,path, |
07 | hitHighlightedSummary,title,contentclass |
08 | fromscope()where" + |
09 | "\"scope\"='{0}'ANDFREETEXT(defaultproperties,'{1}')" ; |
10 | string conditionSearchSource= "ANDCONTAINS(path,'{0}')" ; |
11 |
12 | #endregion |
13 |
14 | #regionConstructor |
15 |
16 | ///<summary> |
17 | ///Defaultconstructor. |
18 | ///</summary> |
19 | public SharePointSearch() |
20 | { |
21 | } |
22 |
23 | #endregion |
24 |
25 | #regionPublicMethods |
26 |
27 | ///<summary> |
28 | /// |
29 | ///</summary> |
30 | ///<paramname="scope"></param> |
31 | ///<paramname="searchSource"></param> |
32 | ///<paramname="keyword"></param> |
33 | ///<paramname="rowLimit"></param> |
34 | ///<returns></returns> |
35 | public DataTableGetSearchResultByKeyWord( string scope, string searchSource, string keyword, int rowLimit) |
36 | { |
37 | string query= string .Format( this .queryStr,scope,keyword); |
38 | if (! string .IsNullOrEmpty(searchSource)) |
39 | query+= string .Format( this .conditionSearchSource,searchSource); |
40 |
41 | return this .CustomSearch(query,rowLimit); |
42 | } |
43 |
44 | ///<summary> |
45 | /// |
46 | ///</summary> |
47 | ///<paramname="query"></param> |
48 | ///<paramname="rowLimit"></param> |
49 | ///<returns></returns> |
50 | public DataTableGetSearchResultByQuery( string query, int rowLimit) |
51 | { |
52 | return this .CustomSearch(query,rowLimit); |
53 | } |
54 |
55 | #endregion |
56 |
57 | #regionPrivateMethods |
58 |
59 | ///<summary> |
60 | ///Excutesearchquery |
61 | ///</summary> |
62 | ///<paramname="query"></param> |
63 | ///<paramname="rowLimit"></param> |
64 | ///<returns></returns> |
65 | private DataTableCustomSearch( string query, int rowLimit) |
66 | { |
67 | DataTableresult= new DataTable(); |
68 | string url=SPContext.Current.Web.Url; |
69 |
70 | using (SPSitesite= new SPSite(url)) |
71 | { |
72 | ServerContextcontext=ServerContext.GetContext(site); |
73 |
74 | FullTextSqlQueryfullQuery= new FullTextSqlQuery(site); |
75 | fullQuery.Culture=System.Globalization.CultureInfo.InvariantCulture; |
76 | fullQuery.QueryText=query; |
77 | fullQuery.ResultTypes=ResultType.RelevantResults; |
78 | fullQuery.EnableStemming= false ; |
79 | fullQuery.IgnoreAllNoiseQuery= true ; |
80 | fullQuery.TrimDuplicates= true ; |
81 |
82 | fullQuery.KeywordInclusion=KeywordInclusion.AnyKeyword; |
83 | fullQuery.RowLimit=rowLimit; |
84 | if (SPSecurity.AuthenticationMode!=System.Web.Configuration.AuthenticationMode.Windows) |
85 | fullQuery.AuthenticationType=QueryAuthenticationType.PluggableAuthenticatedQuery; |
86 | else |
87 | fullQuery.AuthenticationType=QueryAuthenticationType.NtAuthenticatedQuery; |
88 |
89 | ResultTableCollectionrt=fullQuery.Execute(); |
90 | ResultTableresultTable=rt[ResultType.RelevantResults]; |
91 | result.Load(resultTable,LoadOption.OverwriteChanges); |
92 | } |
93 |
94 | return result; |
95 | } |
96 |
97 | #endregion |
98 | } |
01 | <?xmlversion= "1.0" encoding= "utf-8" ?> |
02 | <QueryPacketxmlns= "urn:Microsoft.Search.Query" Revision= "1000" > |
03 | <Querydomain= "QDomain" > |
04 | <SupportedFormats><Format>urn:Microsoft.Search.Response.Document.Document</Format></SupportedFormats> |
05 | <Context> |
06 | <QueryTextlanguage= "en-US" type= "MSSQLFT" ><![CDATA[SELECTTitle,Rank,Size,Description,Write,PathFROMportal..scope()WHEREFREETEXT(DefaultProperties, 'test' )AND(( "SCOPE" = 'AllSites' ))ORDERBY "Rank" DESC]]></QueryText> |
07 | </Context> |
08 | <Range><StartAt>1</StartAt><Count>20</Count></Range> |
09 | <EnableStemming> false </EnableStemming> |
10 | <TrimDuplicates> true </TrimDuplicates> |
11 | <IgnoreAllNoiseQuery> true </IgnoreAllNoiseQuery> |
12 | <ImplicitAndBehavior> false </ImplicitAndBehavior> |
13 | <IncludeRelevanceResults> true </IncludeRelevanceResults> |
14 | <IncludeSpecialTermResults> false </IncludeSpecialTermResults> |
15 | <IncludeHighConfidenceResults> false </IncludeHighConfidenceResults> |
16 | </Query></QueryPacket> |
把english[en]放到最上面。
作者:
出处:
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
相关文章推荐
- SharePoint search 功能的定制开发
- SharePoint search 功能的定制开发
- SharePoint WebPart开发实战(一):定制属性及配置界面
- 使用SharePoint Designer定制开发员工工作日志系统实例!
- 使用SharePoint Designer定制开发专家库系统实例!
- SharePoint WebPart开发实战(一):定制属性及配置界面
- 转:探寻SharePoint Services中为开发人员提供的重大改进功能
- 探寻 SharePoint Services 中为开发人员提供的重大改进功能
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 Excel Services中新功能
- 怎样在Sharepoint 2010中定制开发SharePoint Designer Workflows Activities
- 探寻 SharePoint Services 中为开发人员提供的重大改进功能
- 探寻 SharePoint Services 中为开发人员提供的重大改进功能
- Microsof Office SharePoint 2007 工作流开发环境搭建(用VS2005开发Moss2007工作流)
- 国内的第三本SharePoint技术书籍:《亮剑.NET:SharePoint Server 2007开发实战》发布
- SharePoint Framework 配置你的SharePoint客户端web部件开发环境
- FAST SEARCH FOR SHAREPOINT 2010 特点
- 深入浅出SharePoint——定制SharePoint UE系列
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方案开发集成Apps 集成SP和Office App
- 搭建SharePoint开发环境——如何在Win7安装SharePointFoundation
- SharePoint Portal Server 2003 Search does't like .Net Framework 2.0!!! (for Error in PortalCrawl Web Service solution)