Develop Office2003-based information retrieval services in DOT NET

zhaozj2021-02-17  53

Office2003 adds many practical and interesting new features. Use information retrieval service is one of them. When I got around the "Bo Guest Hall" last week, I found that I was happy to release the full text search service of Bo Guest Hall. I think this is A very good feature, so I also downloaded the SDK of Office2003, I developed an example of information retrieval service, and I would like to share it.

Information Retrieval Service allows all tools in the Office to use all information retrieval functions on the network (a custom web service) as a user, can also develop or add additional information retrieval functions.

Part 1: Installation and Use Information Retrieval Service:

Screenshot of the information retrieval service: (here I use the screenshot of the English version, slightly different from the back screenshot: P)

1. System requirements for using information retrieval services:

Various Windows operating systems for Office2003 (Beta Version can also) are installed.

This feature is suitable for all components of Office2003, including in tools such as Word, Excel, Access, etc. After installation of Office2003, IE can also use this feature.

2. To install information retrieval service: Take Microsoft China MVP's blog site as an example, steps are as follows: Open Word2003, click Tool -> Information Retrieval, at this time, a stop bar will appear on the right side of Word, click on the information retrieval option below the stop bar. ", A dialog that is titled" Information Retrieval Options "is displayed, click on the" Add Service "button below, enter" http://blog.joy.com/research.asmx ", click" Add in the address bar. "Button, and you can use the information retrieval service dedicated to Boke Hall in turn. The location in IE is the main menu -> "View" -> "Browser Bar" -> Information Retrieval.

two. Development Information Retrieval Service:

1. System requirements for developing a general information retrieval service:

Microsoft office2003;

.NET framework 1.0 or subsequent version;

.NET framework SDK1.0 or subsequent version;

MS vs.net2002 or subsequent versions;

IIS5.0 or subsequent versions.

Office2003 Information Retrieves SDK (as a reference).

2. Establish a web service:

Build a C # web service application in vs.net, add two service methods:

[WebMethod]

Public String Registration (String RegistrationXML) {

}

[WebMethod]

Public String Query (String Queryxml)

{

}

Note: 1) This service class must use "URN: Microsoft.Search" namespace.

2) The Registration method and the Query method are must, and the parameters must also follow the above format.

Read the registration request (parameter registrationXML of the Registration method):

The registration request is a string, which is sent to the tool that calls the information retrieval service (such as word), which is actually an XML text, we can read this string or load an XML template file to be implemented. The specific format can refer to Office2003 Information Retrieval Service SDK. Write a registration response (return value for the Registration method)

There are three ways to choose to write a registration response, one is written using XML processing objects such as XMLTextWriter, the second is to write a StringBuilder object write response, the third is to load an XML template file and modify it as a registration response.

Simple, I am using the third method:

XMLDocument RegistrationResponse = new xmldocument ();

// Load template file

RegistrationResponse.Load ("E: //test//2ndresearch//regResponse.xml");

XMLNameSpaceManager nsm = new xmlnamespacemanager (registrationResponse.nametable);

NSM.AddNamespace ("ns", "urn: microsoft.search.registration.response");

// Return to the registration response

Return registrationResponse.innerxml.toString ();

Note: In the registration response, the service provider must have a unique ID, which means that the service provider's ID cannot be the same as the ID of the service provider in the registration response to the client, otherwise The service will be registered.

Read the search request (parameter queryxml in the query method).

Similarly, the retrieval request is also a string that is formatted to XML, including the search information of the client retrieval tool. We can still do in both ways to read and load template documents.

Here I use it directly to read the request:

XmlDocument mydoc = new xmldocument ();

MyDoc.Load (queryxml);

In the formatted XML document MYDOC, there are several nodes worth noting that they are:

QueryID node, OriginatorID node, querytext node, and keyword nodes.

The QueryID node and the content of the OriginatorID node indicate the ID of the client information retrieve the request, and the QueryText node and the keyword node represent keyword information you want to retrieve.

Here, a piece of code is used to remove the contents of the QueryText node (similar to the processing method of other nodes):

XMLNameSpaceManager XNM = New XMLNameSpaceManager (MyDoc.nametable);

XNM.AddNamespace ("URN", "URN: Microsoft.Search.Query);

String searchword = mydoc.selectsinglenode ("// URN: querytext", xnm) .innertext;

Write search response (return value of the Query method)

After reading the retrieval request, you can write the results according to its information, write retrieval response can still be carried out in accordance with three ways similar to writing registration responses, here I mixed several methods.

First loading template document:

XMLDocument QueryResponse = new xmldocument (); queryResponse.load ("E: //test//2ndresearch//QueryResult.xml"); then add some content to make it complete:

In the search response, the information displayed on the client interface is determined by the content of the RANGE node, so I have a simple query on the Northwind database in SQL Server. This query is to return to the customer name in the Customer table contains retrieval. Keyword record:

Private Dataset FindInfo (String SearchText)

{

Sqlconnection conn = new sqlConnection ("Workstation ID = localhost; packet size = 4096; user ID = sa; data source = localhost; persist security info = false; initial catalog = northwind");

Sqldataadapter Da = New SqldataAdapter ("Select * from customer" SearchText "% '", CONN);

DataSet DS = New Dataset ();

Da.fill (DS);

Return DS;

}

Generate an XML documentation for retrieval results:

Public String CreateResult (DataSet DS)

{

StringWriter ResultWriter = new stringwriter ();

XmlTextWriter Xmlcreator = New XmlTextWriter (ResultWriter);

IF (DS.TABLES [0] .Rows.count> 0)

{

For (int i = 0; i

{

Xmlcreator.writestartElement ("results");

/ / Medium is slightly ...

Xmlcreator.writeEndelement ();

}

}

Else

{

Xmlcreator.writestartElement ("results");

/ /

Xmlcreator.writeEndelement ();

}

Return resultwriter.tostring ();

}

Then fill the search result document into the response document (queryResponse):

XMLNameSpaceManager nsmresponse = new xmlnamespacemanager (queryResponse.nametable);

NSMRESPONSE.ADDNAMESPACE ("NS", "URN: Microsoft.search.Response"); queryResponse.selectsinglenode ("// ns: range", nsmresponse) .INNNNNML = this.createresult (DS);

Finally returns a response document:

Return queryResponse.innerxml.tostring ();

Note: The retrieval response document must have a result (not you write a "finding content" result), otherwise the client will report an exception. Also retrieved response documents must be consistent with the ID of the retrieval request information, otherwise the error that cannot be found cannot be found. 3. Compile, debug, and generate information retrieval services:

In the commissioning environment, you can debug information retrieval service J in the way by using the displayed IE.

4. The following is the final result:

Part III. Summary and reference:

Information retrieval is a powerful and effective function, which implements only an extremely simple example. Based on Office information Retrieval SDK reference, more complex retrieval services can be implemented.

Information Retrieval Service XML Format Document can be easily found in Office information Retrieval SDK, users can use SDK as a reference, including HelloWorld, Google and other examples.

Note: 1. Bo Hall: Microsoft China MVP blog site, address is: http://blog.joycode.com

2. Happy: Bo Guest Hall's moderator, Microsoft MVP. 3.Office Information Retrieval SDK (English) Download address: http://download.microsoft.com/download/Download/

0/1/8

/ 018EC82D-A764-

4471-AC

0F

-6a

08cca4cfcc / rssdk.msi

.

转载请注明原文地址:https://www.9cbs.com/read-29078.html

New Post(0)