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

查看:47
本文介绍了在多个请求中使用相同的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"];
                }

当我执行以下语句时,出现运行时错误:对象引用未设置为对象的实例."

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天全站免登陆