Questions tagged «lucene.net»

2
在ASP.NET MVC的静态字段内使用Server.MapPath()
我正在建立一个ASP.NET MVC网站,在其中使用Lucene.Net进行搜索查询。我在这里问了一个有关如何在ASP.NET MVC应用程序中正确构造Lucene.Net用法的问题,并被告知最好的方法是将my声明为IndexWriteras public static,以便可以重新使用它。 这是我的SearchController顶部的一些代码: public static string IndexLocation = Server.MapPath("~/lucene"); public static Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(); public static IndexWriter writer = new IndexWriter(IndexLocation,analyzer); 由于writer是静态的,IndexLocation因此也必须是静态的。因此,编译器给我以下错误Server.MapPath(): 非静态字段,方法或属性“ System.Web.Mvc.Controller.Server.get”需要对象引用。 有没有一种方法可以使用Server.MapPath()或类似的静态字段?如何解决此错误?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.