惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
S
Security @ Cisco Blogs
V
Visual Studio Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
B
Blog RSS Feed
Recorded Future
Recorded Future
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
博客园 - 司徒正美
U
Unit 42
G
Google Developers Blog
博客园 - Franky
阮一峰的网络日志
阮一峰的网络日志
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
博客园 - 【当耐特】
腾讯CDC
博客园 - 聂微东
IT之家
IT之家
Martin Fowler
Martin Fowler
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
PCI Perspectives
PCI Perspectives
C
Check Point Blog
AI
AI
Webroot Blog
Webroot Blog
I
Intezer
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
L
LangChain Blog
C
Cybersecurity and Infrastructure Security Agency CISA
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
Forbes - Security
Forbes - Security
S
Secure Thoughts
Y
Y Combinator Blog
Google Online Security Blog
Google Online Security Blog
H
Heimdal Security Blog
有赞技术团队
有赞技术团队
L
Lohrmann on Cybersecurity

博客园 - 追梦华仔

Openfire服务器MySQL优化 放开Linux内核对用户进程可打开文件数和TCP连接的限制 SSL 握手协议 非对称密码学(Asymmetric Cryptography)- 转载 Visual Studio 2008下载 Visual Studio 2008 提示“无法识别工具版本4.0” 改造MUC实现Openfire群 Openfire S2S 经验分享 注册Jmail组件的三种方法 读取excel文件的时候 出错提示:外部表不是预期的格式 - 追梦华仔 - 博客园 System.Runtime.InteropServices.COMException: 服务器出现意外情况 Excel表格导入出错,提示“拒绝访问”的错误,ExcelObj = new Excel.Application(); 在 ASP.NET 中执行 URL 重写 XP下如何解决“ASP.NET 未被授权访问所请求的资源”的问题 - 追梦华仔 - 博客园 无法在web服务器上启动调试 您不具备调试此应用程序的权限 - 追梦华仔 - 博客园 Server Application Error ---Http 500错误解决方法 用Lucene实现在检索结果中再检索 [转载]Ruby on Rails:开源技术将深入企业 Lucene.Net中按时间范围查询,结果没有查到数据
Lucene.Net.Search.Highlight.FragmentQueue 中的派生方法 LessThan 不能减少访问
追梦华仔 · 2007-06-22 · via 博客园 - 追梦华仔

今天运用Lucene.net做全文索引查询时,碰到了这个问题。在baidu搜索了一下,也有朋友碰到同样的问题:

我在ASP.NET中使用Lucene.NET组件实现高亮显示..可是出现问题..说什么不能访问(如下图),另外如果在ASP.NET中建立索引后..搜索时有些东西搜索不到,在WinForm中又没事..这又是什么问题呢??请牛人们帮忙
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.TypeLoadException: 程序集 Highlighter, Version=1.3.2.1, Culture=neutral, PublicKeyToken=null 的类型 Lucene.Net.Search.Highlight.FragmentQueue 中的派生方法 LessThan 不能减少访问。
源错误:
行 169: row["title"] = doc.Get("title");
行 170: row["path"] = "http://www.dotlucene.net/documentation/api/1.4/" + path.Replace("\\", "/");
行 171: row["sample"] = highlighter.GetBestFragments(plainText, 80, 2, "...");
行 172:
行 173: this.Results.Rows.Add(row);
以上是在ASP.NET中使用高亮显示时出现的问题


后来自己找到了解决办法:
原因出于Lucene.Net.dll 和 Highlighter.Net.dll的版本不一致。你要检查一下,你的项目中引用的Lucene.Net.dll是2.0的,而 Highlighter.Net.dll不是2.0的,这一点从上面“ row["sample"] = highlighter.GetBestFragments(plainText, 80, 2, "..."); ” 这句可以看出。因为2.0的GetBestFragments方法的参数列表不同,在我的解决方案中是用了
public System.String GetBestFragment ( Lucene.Net.Analysis.TokenStream tokenStream , System.String text )方法

关键代码如下:
   using Lucene.Net.Documents;
   using Lucene.Net.Analysis.Standard;
   using Lucene.Net.Search;
   using Lucene.Net.QueryParsers;
   using Lucene.Net.Index;
   using Lucene.Net.Store;
   using Lucene.Net.Highlight;
   using Lucene.Net.Analysis;
   using System.IO;

      //内容
      string text = doc.GetField("Content").StringValue();
      //某数据记录对象
     Result result = new Result();      
      // 高亮显示设置
      SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color=\"red\">", "</font>");
      highlighter = new Highlighter(simpleHTMLFormatter, new QueryScorer(query));     
      //关键内容显示大小设置 
      highlighter.SetTextFragmenter(new SimpleFragmenter(200));      
      //取出高亮显示内容
      TokenStream tokenStream = analyzer.TokenStream("Content", new StringReader(text));
      result.Content = highlighter.GetBestFragment(tokenStream,text);

 参考文章:http://blog.sina.com.cn/u/54c1567b010008st
http://hi.baidu.com/buliu/blog/item/115ee83d542735c59e3d6225.html
http://www.tianyablog.com/blogger/post_show.asp?BlogID=114714&PostID=2852189