问题描述
对每张表建立索引放在不同目录,多表查询时调用多个索引查询,查询时会报错readpastEOF。具体错误如下:代码如下:#region搜索设置privatevoidSearchContent(){stringcontent=HttpContext.Current.Request.QueryString["content"];stringdate1=HttpContext.Current.Request.QueryString["date1"];stringdate2=HttpContext.Current.Request.QueryString["date2"];string[]dbnames=(HttpContext.Current.Request.QueryString["dbname"]).Split(',');stringpath=ConfigurationManager.AppSettings["indexpath"].ToString();string[]indexPaths=newstring[dbnames.Length];for(inti=0;i<dbnames.Length;i++){indexPaths[i]=@""+path+dbnames[i]+"";}stringindexPath=@""+path+dbnames[0]+"";stringkw=content;//kw=kw.ToLower();FSDirectory[]directories=newFSDirectory[dbnames.Length];IndexReader[]readers=newIndexReader[dbnames.Length];IndexSearcher[]searchers=newIndexSearcher[dbnames.Length];for(intn=0;n<indexPaths.Length;n++){directories[n]=FSDirectory.Open(newDirectoryInfo(indexPaths[n]),newNoLockFactory());readers[n]=IndexReader.Open(directories[n],true);searchers[n]=newIndexSearcher(readers[n]);}MultiSearchernewsearcher=newMultiSearcher(searchers);//过滤器TermRangeFilterfilter=newTermRangeFilter("PD",date1,date2,true,true);PhraseQueryquery=newPhraseQuery();foreach(stringwordinSearchHelper.SplitWord(kw))//将用户输入的搜索内容进行了盘古分词、{query.Add(newTerm("TI",word));}query.SetSlop(100);TopScoreDocCollectorcollector=TopScoreDocCollector.create(100000,true);//结合过滤器查询newsearcher.Search(query,filter,collector);intPageIndex=AspNetPager1.CurrentPageIndex;intPageSize=AspNetPager1.PageSize;intRowCount=collector.GetTotalHits();intPageCount=Convert.ToInt32(Math.Ceiling((RowCount*1.0)/PageSize));ScoreDoc[]docs=collector.TopDocs((PageIndex-1)*PageSize,PageSize).scoreDocs;List<SearchResult>list=newList<SearchResult>();for(inti=0;i<docs.Length;i++){intdocId=docs[i].doc;//得到查询结果文档的id(Lucene内部分配的id)Documentdoc=searcher.Doc(docId);//找到文档id对应的文档详细信息SearchResultresult=newSearchResult();result.TI=doc.Get("TI");//SearchHelper.Highlight(kw,doc.Get("TI"));result.AN=doc.Get("AN");result.id=doc.Get("id");result.PD=doc.Get("PD");result.ABST=doc.Get("ABST");list.Add(result);}this.SearchRepeater.DataSource=list;this.SearchRepeater.DataBind();AspNetPager1.RecordCount=RowCount;}protectedvoidAspNetPager1_PageChanged(objectsender,EventArgse){SearchContent();}
解决方案
本帖最后由 hxytmac 于 2014-09-02 15:35:09 编辑