首页 新闻 会员 周边 捐助

用lucene搜索时问什么报对文件夹无法访问

0
悬赏园豆:5 [已关闭问题]

我用的lucene全文检索在给索引库指定目录,有的时候会提示对文件夹无法访问,所以报错

 

我是创建索引是这样建的,那错了啊

谢谢

  //创建索引
        private IndexWriter CreateIndex()
        {
            IndexWriter writer = null;
            try
            {
                writer = new IndexWriter(Server.MapPath("~/Lucene/goods"), new StandardAnalyzer(), true);//////////

                if (Convert.ToInt32(this.ddlInfo.SelectedValue) == 0)///////////
                {

                    IList<Goods> goods = GoodsManager.GetAllGoods();////////////
                    foreach (Goods g in goods)
                    {
                        Document doc = new Document();
                        doc.Add(new Field("id", g.Id.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.Add(new Field("CompanyID", g.CompanyID.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.Add(new Field("goodsname", g.GoodsName, Field.Store.YES, Field.Index.TOKENIZED));
                        writer.AddDocument(doc);
                    }
                }

                writer.Optimize();
            }
            catch (Exception e)
            {
                Server.Execute("~/default.aspx");
            }
            finally
            {
                writer.Close();
            }
            return writer;
        }

 

     public Hits Search()
        {
            Hits hits = null;
            IndexSearcher mysea = new IndexSearcher(Server.MapPath("~/Lucene/goods"));//////////////
            //对单一字段搜索
            QueryParser parser = new QueryParser("goodsname", new StandardAnalyzer());/////////////////
            Query query = parser.Parse(this.txtKey.Text.Trim());
            //Query query = MultiFieldQueryParser.Parse(new string[] { this.TextBox1.Text.Trim() }, new string[] { "title" }, new YurowAnalyzer.YurowAnalyzer("f:\\index"));
            hits = mysea.Search(query);
            return hits;
        }

protected void imgSearch_Click(object sender, ImageClickEventArgs e)
        {
            if (this.ddlInfo.SelectedIndex == 0)
            {
                if (this.txtKey.Text.Trim() == "")
                {
                    return;
                }
                //IndexWriter writer = CreateIndex();
                IList<Goods> goods = new List<Goods>();
                Hits hits = Search();
                //Response.Write("关于搜索到" + hits.Length() + "条记录!");
                if (hits != null)
                {
                    for (int i = 0; i < hits.Length(); i++)
                    {
                        Document doc = hits.Doc(i);
                        Goods g = new Goods();
                        g.Id = Convert.ToInt32(doc.Get("id"));
                        g.CompanyID = Convert.ToInt32(doc.Get("CompanyID"));
                        g.GoodsName = Convert.ToString(doc.Get("goodsname"));
                        goods.Add(g);
                    }
                }
                //Session["goods"] = "";
                Session["goods"] = goods;
                Response.Redirect("~/searchGoods.aspx");
            }
                        
        }

rains的主页 rains | 小虾三级 | 园豆:860
提问于:2010-05-27 17:44
< >
分享
其他回答(1)
0

检查你的文件夹是不是有 aspnet 这个账号的读写权限

eaglet | 园豆:17139 (专家六级) | 2010-05-27 18:46
0

有时会出错,可能是防火墙的原因。我的服务器上索引文件以前老是被norton罩住。

邀月 | 园豆:25475 (高人七级) | 2010-05-27 22:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册