没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
转帖|使用教程|编辑:龚雪|2014-12-15 15:03:15.000|阅读 669 次
概述:本教程介绍了在dtSearch中,如何实现搜索结果命中关键字高亮显示。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
What do you do with your search results after you have obtained them? We explore hit highlighting with dtSearch and C#.
In the first part of my exploration of the search and indexing system dtSearch, I covered the basic principles of operation. Now we consider what to do next once you have some search results.
What do you do with your search results after you have obtained them?
It is a good question. In many cases it is enough to simply list the files that contain the hits. But what if your users want to look inside the files and see where the hits have occurred? This is a nightmare of a job if you have to start from scratch. All those file formats and then there is the bother of finding out how to highlight the hits in each format.
No - it probably isn't worth the effort.
The good news is that if you are using dtSearch, which you can try for yourself by downloading the 30-day evaluation from dtsearch download page, you can use a range of file and container parsers. dtSearch has its own file parsers supporting popular file types like MS Word, Excel, Access, PowerPoint, CSV, HTML, PDF, XML/XSL, emails and attachments, ZIP files, etc. The file parsers are used by the indexing engine to look inside each document and it is also used by the FileConverter object to allow you to process documents into a standard format so that the results of searches can be presented to users.
It is assumed that you already know how to create an index and search it using say C#. If not read Getting started with dtSearch, but to give us something to work with we will perform a simple search for the single word "Jeep" in an index that has already been constructed.
First we need a SearchJob object:
SearchJob SJob1 = new SearchJob();
which we make ready to perform the search on the index:
SJob1.BooleanConditions = "Jeep"; SJob1.IndexesToSearch.Add(@"location of index"); SJob1.MaxFilesToRetrieve = 100;
You can, of course, customize to search for any target in your own index. Finally we execute the search:
SJob1.Execute();
This populates a Result object with all of the information needed about each file found. To make things easier to follow, we can create a direct reference to the results of the search:
SearchResults Results = SJob1.Results;
The search results contains a list of documents and associated properties that was returned from a search. We have encountered it before, but is is worth a few moments considering it in more detail.
You might expect SearchResults to be a simple collection object, but if you consider the problems involved in creating a collection object consisting of a range of documents you can see that it is better to only retrieve a document when it is needed. To retrieve a document and its associated properties you simply use the GetNthDoc method, which loads the Nth document in the results list into the SearchResults objects CurrentItem property.
For example, to get the first document you would use something like:
Results.GetNthDoc(0); SearchResultsItem Item=Results.CurrentItem;
Once you have the Item you can make use of its properties to work with the properties of the document and the search. For example, you can check the document's type using its TypeId property. This is an integer but its ToString method has been overridden to provide a string identifier.
So, for example:
MessageBox.Show(Item.TypeId.ToString());
displays
which indicates that the first document in the list is a PDF. You can discover the full range of document types by examining the TypeId enumeration.
As well as details of the document, the SearchItem object also contains details of the hits, i.e. the details of where the target phrase was found in the document. You can use these details to manipulate the document to show, say, where the hits occurred.
A central issue is locating where a hit occurred and this can be achieved using the Hits array which contains the offsets of the words that have been matched to the search target. If you examine the range of similar properties then you should be able to see how to highlight the hits - but you probably aren't looking forward to such detailed, and let's face it boring, coding. The good news is that it has all been done for you and in a way that does so much more than you would achieve with a basic approach.
The central object in making hit highlighting and other similar tasks very easy indeed is the FileConverter. This takes a file in any of the supported formats, and there are a lot of supported formats. and performs a transformation on it to HTML, RTF, XML or plain text. Just this feat alone is worth its weight in code but it will also "decorate" the conversion with markers that can be used to highlight the hits.
The first thing to say is that FileConverter is general and will process a document even if you acquired it by some complicated route. All you have to do is set its properties correctly and call its Execute method and the job is done.
The properties that you have to set are also fairly simple: the name of the file to process, a hits array giving the offsets from the start of the file of each of the hits, a specification of what characters constitute a word break, the index that the file was retrieved from and the document id. You also have to specify what format you want the results in and what strings you want to use to mark up the hits.
If you want to process a general file then you need to specify the file name as Inputfile or it the data is in a memory buffer then use InputBytes.
You can do this job one property at a time and it isn't difficult but if the file has been returned as the result of a search then it is even easier. The SetInputItem method can be used to set all of the necessary properties from a SearchResults object. For example:
FileConverter fc=new FileConverter(); fc.SetInputItem(Results,0);
creates a FileConverter and initializes it so as to be ready to process the first document in the results. After this the only things we need to set are the output format required, e.g. HTML, RTF, XML or plain text, and the strings to be inserted before and after each hit. For example to create an HTML document and surround every hit with an <h1> tag pair (an odd choice but still possible) you would use:
fc.OutputFormat = OutputFormats.itHTML; fc.BeforeHit = "<h1>"; fc.AfterHit = "</h1>";
Almost ready to highlight, or headline in this case, but first we need to set where the output is going. The FileConverter can either create a new file or it can return a string. In this case we will opt to display the HTML in a webBrowser control and so a string is most appropriate. Place a webBrowser control on the form and store the result of the highlighting in it using
fc.OutputToString = true; fc.Execute(); webBrowser1.DocumentText = fc.OutputString;
If you now put all this together you will find that every occurrence of the target search item is set as an <h1> headline.
In most cases it would be better to use a color code to highlight the hits but you really are free to do whatever you want with the text that constitutes the hits.
A really nice touch is the provision of the special tags - %%ThisHit%%, %%NextHit%% and %%PreviousHit%% which causes the FileConverter to place numbers into the file corresponding to the index of the hit in the array. With a little work this can be used to create hyperlinks that the user can use to navigate the document.
Also notice that while the output of the conversion is HTML (or RTF, or XML or plain text) the input file can be in any of the supported formats, making FileConverter a one-stop solution to highlighting hits in almost any type of file in the index.
This is almost too easy.
原文地址://www.i-programmer.info/programming/database/3153-highlighting-search.html
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
文章转载自:慧都控件网大型SaaS系统的自动化测试常常受制于界面变化快、结构复杂、加载机制多变等因素。从元素识别到脚本管理,SmartBear TestComplete帮助Salesforce建了可靠的自动化测试体系。
BarTender 标签管理系统,正是帮助企业轻松实现 GS1 标准化标签设计、编码生成与信息联动的强大工具。
Parasoft C/C++test 是一款功能强大的 C/C++ 软件测试工具,集成了静态代码分析、单元测试、集成测试和覆盖率分析等功能,单元测试作为其关键功能之一,为了适配多样化的目标部署环境,C/C++test 设计了灵活的测试结果收集机制。通过Socket通讯方式来收集单元测试结果,从而扩展其测试覆盖范围与应用场景。
Parasoft C/C++test作为一款功能全面的自动化代码质量保障工具,为C/C++开发者提供了静态分析、单元测试和运行时错误检测等核心功能。通过将其与轻量级且广受欢迎的VScode编辑器集成,开发团队可以在熟悉的编码环境中实时获得代码质量反馈,有效提升开发效率与代码可靠性。
全球领先的文本检索工具,支持在千兆字节数量级的数据源中进行搜索。
dtSearch Network with Spider全球领先的文本检索工具,支持在千兆字节数量级的数据源中进行搜索。
dtSearch Web with Spider全球领先的文本检索工具,能够快速地将大量的搜索内容即时发布到基于IIS的Web站点上。
dtSearch Publish全球领先的文本检索工具,能够为CD/DVD publishing提供强大的功能。
dtSearch Engine超过20年的全球领先的文本检索控件,使开发者为应用程序快速添加文本查检索功能。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢