Ejemplo n.º 1
0
 internal void PopulateAnalyzers(ComboBox cbAnalyzers)
 {
     cbAnalyzers.BeginUpdate();
     cbAnalyzers.Items.Clear();
     cbAnalyzers.Items.AddRange(Analyzing.GetAnalyzerNames().ToArray());
     cbAnalyzers.EndUpdate();
 }
Ejemplo n.º 2
0
        private void btnUpdateParsedQuery_Click(object sender, System.EventArgs e)
        {
            string analyzerName = Analyzing.GetAnalyzerName((string)comboAnalyzer.SelectedItem);

            comboAnalyzer.SelectedItem = analyzerName;
            QueryParser qp     = CreateQueryParser(analyzerName);
            String      queryS = textSearch.Text;

            if (queryS.Trim() == "")
            {
                textParsed.Enabled = false;
                textParsed.Text    = _luke.resources.GetString("EmptyQuery");
                return;
            }
            textParsed.Enabled = true;

            try
            {
                Query q = qp.Parse(queryS);
                textParsed.Text = q.ToString();
            }
            catch (Exception exc)
            {
                textParsed.Text = exc.Message;
            }
        }
Ejemplo n.º 3
0
        internal void Search()
        {
            if (_luke.IndexReader == null)
            {
                _luke.ShowStatus(_luke.resources.GetString("NoIndex"));
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            string analyzerName = Analyzing.GetAnalyzerName((string)comboAnalyzer.SelectedItem);

            comboAnalyzer.SelectedItem = analyzerName;
            queryParser = CreateQueryParser(analyzerName);

            string queryString = textSearch.Text;

            if (queryString == string.Empty)
            {
                _luke.ShowStatus(_luke.resources.GetString("EmptyQuery"));
                return;
            }

            IndexSearcher searcher = null;

            listSearch.BeginUpdate();
            listSearch.Items.Clear();

            listSearch.EndUpdate();
            try
            {
                Query q = queryParser.Parse(queryString);

                if (searcher != null)
                {
                    searcher.Close();
                }
                searcher = new IndexSearcher(_luke.Directory, true);

                textParsed.Text = q.ToString();
                _Search(q, searcher);
            }
            catch (Exception e)
            {
                _luke.ErrorMessage(e.Message);
            }
            finally
            {
                if (searcher != null)
                {
                    try { searcher.Close(); }
                    catch (Exception) { }
                }
                ;
            }

            Cursor.Current = Cursors.Default;
        }
Ejemplo n.º 4
0
        private QueryParser CreateQueryParser(string analyzerName)
        {
            analyzer = Analyzing.GetAnalyzerForName(analyzerName);
            if (null == analyzer)
            {
                _luke.ErrorMessage(string.Format(_luke.resources.GetString("AnalyzerNotFound"), analyzerName));
                analyzer = stdAnalyzer;
            }

            string defField = (string)comboFields.SelectedItem;

            if (defField == null || defField == string.Empty)
            {
                defField = _indexFields[0];
                comboFields.SelectedItem = analyzerName;
            }

            return(new QueryParser(Luke.LUCENE_VERSION, defField, analyzer));
        }
Ejemplo n.º 5
0
        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(Luke.LUCENE_VERSION);
            }
            else
            {
                a = Analyzing.GetAnalyzerForName(analyzerName);

                if (null == a)
                {
                    luke.ShowStatus(string.Format(resources.GetString("AnalyzerNotFound"), analyzerName));
                    a = new StandardAnalyzer(Luke.LUCENE_VERSION);
                }
            }

            foreach (Field f in fields)
            {
                doc.Add(f);
            }

            IndexWriter writer = null;
            Directory   dir    = luke.IndexReader.Directory();

            try
            {
                luke.IndexReader.Close();
                writer = new IndexWriter(dir, a, IndexWriter.MaxFieldLength.UNLIMITED);
                writer.AddDocument(doc);
            }
            catch (Exception exc)
            {
                luke.ErrorMessage(exc.Message);
            }
            finally
            {
                try
                {
                    if (writer != null)
                    {
                        writer.Commit();
                        writer.Close();
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    luke.IndexReader = IndexReader.Open(dir, true);
                }
                catch (Exception e2)
                {
                    luke.ErrorMessage(e2.Message);
                }
            }
        }