sps Search for FullText

转载 2007年09月28日 00:36:00

This post is a description of how to use the Microsoft.Office.Server.Search.Query.FullTextSqlQuery class for searching with the MOSS 2007 search engine using the Enterprise Search SQL syntax. I will at the end of this posting explain how to execute queries for optimal results rankings. 

But let me first establish the basics of using the FullTestSqlQuery class. You will only need to employ it for one of the following reasons:

  • You need to support Wildcard searches.
  • You need to search with date ranges.
  • You need to search properties with different operators (CONTAINS, =, >=, <=, <, >, LIKE).
  • You need to search properties for NULL values.
  • You need to use the NEAR operator.
  • You need nested Boolean queries.
  • You like the most flexible (or complicated ;-) ) solution.

Simple keyword and property queries are easier done with the Microsoft.Office.Server.Search.Query.KeywordQuery class. I will, however, not cover this class here.

Ok, let us get started. I have outlined the format of the SQL Syntax accepted by the MOSS 2007 search engine below. After that I will show how to talk to the search engine via the official .NET API.

SQL Syntax
A SQL query is a string that must adhere to the following structure:
SELECT <columns>
FROM <content source>
WHERE <conditions>
ORDER BY <columns>

SQL Syntax Examples

  1. Finds relevant results containing the keyword SharePoint.

    SELECT WorkId,Path,Title,Write,Author,HitHighlightedSummary,
    HitHighlightedProperties,CollapsingStatus
    FROM Scope()
    WHERE FREETEXT(defaultproperties, 'SharePoint')
    ORDER BY Rank Desc
  2. Finds relevant results containing at least one of the keywords SharePoint and Search.
    SELECT WorkId,Path,Title,Write,Author,...
    FROM Scope()
    WHERE FREETEXT(defaultproperties, 'SharePoint Search')
    ORDER BY Rank Desc
  3. Finds relevant results containing both the keywords SharePoint and Search.
    SELECT WorkId,Path,Title,Write,Author,...
    FROM Scope()
    WHERE FREETEXT(defaultproperties, '+SharePoint +Search')
    ORDER BY Rank Desc
  4. Finds relevant results containing the exact phrase SharePoint Search.
    SELECT WorkId,Path,Title,Write,Author,...
    FROM Scope()
    WHERE FREETEXT(defaultproperties, ' "SharePoint Search" ')
    ORDER BY Rank Desc
  5. Finds relevant results containing both the keywords SharePoint and Search but not the keyword WSS
    SELECT WorkId,Path,Title,Write,Author,...
    FROM Scope()
    WHERE FREETEXT(defaultproperties, '+SharePoint +Search -WSS')
    ORDER BY Rank Desc
  6. Finds relevant SharePoint results authored by persons named John.
    SELECT WorkId,Path,Title,Write,Author,...
    FROM Scope()
    WHERE FREETEXT(defaultproperties, 'SharePoint') AND CONTAINS(Author,' "John" ')
    ORDER BY Rank Desc
  7. Finds relevant SharePoint results modified within the last 30 days.
    SELECT WorkId,Path,Title,Write,Author,...
    FROM Scope()
    WHERE FREETEXT(defaultproperties, 'SharePoint') AND Write<=DATEADD(DAY,30,GETGMTDATE())
    ORDER BY Rank Desc

 .NET API
The following code should give you some inspiration how to execute a SQL query against the MOSS 2007 search engine.


ResultTableCollection results = null;
using (FullTextSqlQuery query = new FullTextSqlQuery(ServerContext.Current))
{
query.StartRow = 0;
query.RowLimit = 10;
query.HighlightedSentenceCount = 3;
query.EnableStemming = true;
query.TrimDuplicates = true;
query.Culture = CultureInfo.CurrentCulture;

query.KeywordInclusion = KeywordInclusion.AnyKeyword;
query.SiteContext = new Uri("http://yourserver/sites/asite");




if (SPSecurity.AuthenticationMode != AuthenticationMode.Windows)

query.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery;
else

    query.AuthenticationType = QueryAuthenticationType.NtAuthenticatedQuery;
query.QueryText = "SELECT ... FROM Scope() WHERE ... ORDER BY ...";
results = query.Execute();
}


StringBuilder buffer = new StringBuilder(10240);
ResultTable relevantResults = results[ResultType.RelevantResults];
using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(buffer)))
{
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Results");
writer.WriteAttributeString("hits", relevantResults.TotalRows.ToString());
while (relevantResults.Read())
{
writer.WriteStartElement("Result");
for (int i=0; i<relevantResults.FieldCount; i++)
{
writer.WriteStartElement(relevantResults.GetName(i));
object val = relevantResults.GetValue(i);
if (val != null)
writer.WriteString(val.ToString());
else
writer.WriteString("null");
writer.WriteEndElement();
}     
writer.WriteEndElement();
}
  writer.WriteEndElement();
  string xml = buffer.ToString();
...






}

The using statement around the usage scope of the FullTextSqlQuery class is very important to remember as you will otherwise get an OutOfMemoryException after running a good number of queries. This is so because the search engine is a COM server that the .NET API maintains a handle to.

A closer look at the FREETEXT predicate
Take a look at following two keyword searches using the FREETEXT predicate (rest of SQL string omitted for simplicity):

FREETEXT(defaultproperties, '+sharepoint +search')
FREETEXT(defaultproperties, 'sharepoint') AND FREETEXT(defaultproperties, 'search')

Both queries are valid and yield the same results buth with different ranking. Which one yields the best results ranking? Answer: The first one! It is recommended that you only use one FREETEXT predicate in a search query. Results ranking will otherwise not be optimal.

The defaultproperties keywords references the default set of properties to include in the ranking algorithm. This is also recommended for optimal ranking of results. You can alternatively use the WITH predicate to define your own set of properties if you are not happy with the default one. This is helpful if you need to promote results containing the keywords on your own custom properties. Note: The standard MOSS 2007 search center simply uses the defaultproperties.

The FREETEXT predicate can also be configured for implicit AND search or implicit OR search. This means that a query like:

FREETEXT(defaultproperties, 'sharepoint search')

can respectively find results containing both the keywords sharepoint and search or find results containing at least one of the keywords. Use the the KeywordInclusion property on the FulltextSqlQuery object to control this behavior. See the code example earlier in this posting.

Conclusion
I have just described the key concepts of using the FulltextSqlQuery class. I have not described all of its features nor have I described the SQL Syntax in full. I refer you to the MOSS 2007 SDK for a complete reference.

Stay stuned for more postings on the inner workings of the MOSS 2007 search engine! 

MYSQ LFULLTEXT索引实现全文搜索

使用FULLTEXT索引 MySQL具备全文搜索的能力。全文搜索引擎可以在不使用模板匹配操作的情况下查找单词或短语。全文搜索分为3种模式,如下所示。 自然语言模式。把搜索字符串解释为一系列单词并查找...
  • dongdongzzcs
  • dongdongzzcs
  • 2014年01月19日 20:41
  • 8474

H264帧的分析sps pps

帧格式 H264帧由NALU头和NALU主体组成。 NALU头由一个字节组成,它的语法如下:       +---------------+       |0|1|2|3|4|5|6|7|    ...
  • hbuxiaofei
  • hbuxiaofei
  • 2016年01月12日 10:47
  • 2991

嵌入式 H264参数语法文档: SPS、PPS、IDR以及NALU编码规律

H.264码流第一个 NALU 是 SPS(序列参数集Sequence Parameter Set) 对应H264标准文档 7.3.2.1 序列参数集的语法进行解析 SPS参数解析// fil...
  • skdkjxy
  • skdkjxy
  • 2014年09月30日 16:59
  • 1963

h265 sps 数据解析

typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned long uint32; typedef un...
  • ww506772362
  • ww506772362
  • 2015年10月27日 18:14
  • 2738

HEVC编码结构:序列参数集SPS、图像参数集PPS、视频参数集VPS

1、序列参数集SPS——H.264/H.265 背景:在码流结构方面,H.265压缩数据采用了类似于H.264的分层结构,将属于图像组GOP(Group Of picture)层、Slice层中共用...
  • lin453701006
  • lin453701006
  • 2016年10月12日 14:38
  • 1743

从sps中解析分辨率

static UINT Ue(BYTE *pBuff, UINT nLen, UINT &nStartBit) { //计算0bit的个数 UINT nZeroNum = 0; while (...
  • ljh081231
  • ljh081231
  • 2016年09月14日 09:33
  • 727

H264参数SPS(序列参数集)和PPS(图像参数集)说明

在文章开始之前,先看图一: 图一 从图一中我们看到SPS,PPS。这是符合H.264码流中第一个NALU是SPS,第二个NALU是PPS。SPS和PPS包含了 初始化H.264解码器所需...
  • H514434485
  • H514434485
  • 2016年04月05日 11:53
  • 2844

Android 用MediaCodec实现视频硬解码

Android 用MediaCodec实现视频硬解码 本文向你讲述如何用android标准的API (MediaCodec)实现视频的硬件编解码。例程将从摄像头采集视频开始,然后进行H264...
  • wzwind
  • wzwind
  • 2015年06月03日 22:51
  • 1609

在MP4文件中提取H264的SPS、PPS及码流

在MP4文件中提取H264的SPS、PPS及码流
  • DaveBobo
  • DaveBobo
  • 2016年04月11日 20:44
  • 1252

H264解码SPS获取宽高和帧率

#include    #include    #include    #include       typedef  unsigned int UINT;   typedef  unsi...
  • gangyankui7140
  • gangyankui7140
  • 2017年07月13日 14:01
  • 442
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:sps Search for FullText
举报原因:
原因补充:

(最多只允许输入30个字)