internal void ShowTopTerms() { int nDoc = (int)domainTerms.SelectedItem; ListView.CheckedListViewItemCollection fields = listFields.CheckedItems; String[] selectedFields; if (fields == null || fields.Count == 0) { selectedFields = _indexFields; } else { selectedFields = new String[fields.Count]; int i = 0; foreach (ListViewItem item in fields) { // item.Text without "<", ">" selectedFields[i++] = item.Text.Substring(1, item.Text.Length - 2); } } try { TermInfo[] termInfos = HighFreqTerms.GetHighFreqTerms(_luke.Directory, null, nDoc, selectedFields); listTerms.BeginUpdate(); listTerms.Items.Clear(); if (termInfos == null || termInfos.Length == 0) { ListViewItem noResults = new ListViewItem(); noResults.SubItems.AddRange(new String[] { "", "", _luke.resources.GetString("NoResults") }); listTerms.Items.Add(noResults); return; } for (int i = 0; i < termInfos.Length; i++) { ListViewItem item = new ListViewItem((i + 1).ToString()); item.SubItems.AddRange( new String[] { termInfos[i].DocFreq.ToString(), " <" + termInfos[i].Term.Field() + "> ", termInfos[i].Term.Text() }); listTerms.Items.Add(item); } } catch (Exception e) { _luke.ErrorMessage(e.Message); } finally { listTerms.EndUpdate(); } }
private void btnExplain_Click(object sender, System.EventArgs e) { if (listSearch.SelectedItems.Count == 0) { return; } if (searchedDocIds == null || searchedDocIds.Length < listSearch.Items.Count) { return; } if (_luke.IndexReader == null) { _luke.ShowStatus(_luke.resources.GetString("NoIndex")); return; } if (query == null) { return; } IndexSearcher searcher = null; try { searcher = new IndexSearcher(_luke.Directory, true); Lucene.Net.Search.Explanation expl = searcher.Explain(query, searchedDocIds[listSearch.SelectedIndices[0]]); ExplanationDialog explDialog = new ExplanationDialog(expl); explDialog.ShowDialog(this); } catch (Exception exc) { _luke.ErrorMessage(exc.Message); } finally { searcher.Close(); } }
private void buttonShowAllDocs_Click(object sender, System.EventArgs e) { if (term == null) { return; } if (_luke.IndexReader == null) { _luke.ShowStatus(_luke.resources.GetString("NoIndex")); return; } _luke.ShowSearchTab(); Query q = new TermQuery(term); IndexSearcher searcher = null; try { searcher = new IndexSearcher(_luke.Directory, true); _luke.searchTabPage._Search(q, searcher); } catch (Exception exc) { _luke.ErrorMessage(exc.Message); } finally { if (searcher != null) { try { searcher.Close(); } catch (Exception) { } } ; } }
private void EditAdd() { Document doc = new Document(); Analyzer a; string analyzerName = (string)cmbAnalyzers.SelectedItem; if (null == analyzerName || analyzerName == string.Empty) { analyzerName = "Lucene.Net.Analysis.Standard.StandardAnalyzer"; cmbAnalyzers.SelectedItem = analyzerName; a = new StandardAnalyzer(Util.Version.LUCENE_30); } else { a = luke.AnalyzerForName(analyzerName); if (null == a) { luke.ShowStatus(string.Format(resources.GetString("AnalyzerNotFound"), analyzerName)); a = new StandardAnalyzer(Util.Version.LUCENE_30); } } foreach (Field f in fields) { doc.Add(f); } IndexWriter writer = null; Directory dir = luke.IndexReader.Directory(); try { luke.IndexReader.Dispose(); writer = new IndexWriter(dir, a, false, IndexWriter.MaxFieldLength.UNLIMITED); writer.AddDocument(doc); } catch (Exception exc) { luke.ErrorMessage(exc.Message); } finally { try { if (writer != null) { writer.Dispose(); } } catch (Exception) { } try { luke.IndexReader = IndexReader.Open(dir, true); } catch (Exception e2) { luke.ErrorMessage(e2.Message); } } }