145private void PerformSearch()
146{
147DateTime start = DateTime.Now;
148
149	//Create the Searcher object
150	string strIndexDir = Server.MapPath("index") + "\\" + mstrURL;
151	IndexSearcher objSearcher = new IndexSearcher(strIndexDir); 
152
153	//Parse the query, "text" is the default field to search
154	Query objQuery = QueryParser.Parse(mstrQuery, 
"text", new StandardAnalyzer()); 155 156 //Create the result DataTable 157 mobjDTResults.Columns.Add("title", typeof(string)); 158 mobjDTResults.Columns.Add("path", typeof(string)); 159 mobjDTResults.Columns.Add("score", typeof(string)); 160 mobjDTResults.Columns.Add("sample", typeof(string)); 161 mobjDTResults.Columns.Add("explain", typeof(string)); 162 163 //Perform search and get hit count 164 Hits objHits = objSearcher.Search(objQuery); 165 mintTotal = objHits.Length(); 166 167 //Create Highlighter 168 QueryHighlightExtractor highlighter = new
QueryHighlightExtractor(objQuery, new
StandardAnalyzer(), "<B>", "</B>"); 169 170 //Initialize "Start At" variable 171 mintStartAt = GetStartAt(); 172 173 //How many items we should show? 174 int intResultsCt = GetSmallerOf(mintTotal,
mintMaxResults + mintStartAt); 175 176 //Loop through results and display 177 for (int intCt = mintStartAt; intCt < intResultsCt; intCt++) 178 { 179 //Get the document from resuls index 180 Document doc = objHits.Doc(intCt); 181 182 //Get the document's ID and set the cache location 183 string strID = doc.Get("id"); 184 string strLocation = ""; 185 if (mstrURL.Substring(0,3) == "www") 186 strLocation = Server.MapPath("cache") + 187 "\\" + mstrURL + "\\" + strID + ".htm"; 188 else 189 strLocation = doc.Get("path") + doc.Get("filename"); 190 191 //Load the HTML page from cache 192 string strPlainText; 193 using (StreamReader sr = new
StreamReader(strLocation, System.Text.Encoding.Default)) 194 { 195 strPlainText = ParseHTML(sr.ReadToEnd()); 196 } 197 198 //Add result to results datagrid 199 DataRow row = mobjDTResults.NewRow(); 200 if (mstrURL.Substring(0,3) == "www") 201 row["title"] = doc.Get("title"); 202 else 203 row["title"] = doc.Get("filename"); 204 row["path"] = doc.Get("path"); 205 row["score"] = String.Format("{0:f}", (objHits.Score(intCt) * 100)) + "%"; 206 row["sample"] = highlighter.GetBestFragments(strPlainText, 200, 2, "..."); 207 Explanation objExplain = objSearcher.Explain(objQuery, intCt); 208 row["explain"] = objExplain.ToHtml(); 209 mobjDTResults.Rows.Add(row); 210 } 211 objSearcher.Close(); 212 213 //Finalize results information 214 mTsDuration = DateTime.Now - start; 215 mintFromItem = mintStartAt + 1; 216 mintToItem = GetSmallerOf(mintStartAt + mintMaxResults, mintTotal); 217}