对多个请求使用相同的 indexSearcher 实例时出现问题 [英] Problem using same instance of indexSearcher for multiple requests

查看:27
本文介绍了对多个请求使用相同的 indexSearcher 实例时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .net Web 应用程序中使用 Lucene API.我想对所有请求使用相同的 Indexsearcher 实例.因此我将 indexsearcher 实例存储在 http 缓存中.

Am using Lucene API in a .net web application. I want to use the same instance of Indexsearcher for all the requests.Hence am storing indexsearcher instance in http cache.

这是我的代码:

if (HttpRuntime.Cache["IndexSearcher"] == null)
                {
                    searcher = new IndexSearcher(jobIndexFolderPath);
                    HttpRuntime.Cache["IndexSearcher"] = searcher;
                }
                else
                {
                    searcher = (IndexSearcher)HttpRuntime.Cache["IndexSearcher"];
                }

当我执行下面的语句时,我得到一个运行时错误:Object reference not set to an instance of an object."

When I execute the statement below, I get a runtime error :"Object reference not set to an instance of an object."

点击次数 = searcher.Search(myQuery);

Hits hits = searcher.Search(myQuery);

我在这里错过了什么?

感谢阅读!

推荐答案

试试下面的方法:

protected static IndexSearcher searcher = null;
...

if (searcher == null)
{
    searcher = new IndexSearcher(jobIndexFolderPath);
}

这篇关于对多个请求使用相同的 indexSearcher 实例时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆