Example #1
0
        private void SaveFieldContent(int fieldIndex)
        {
            if (fieldIndex > fields.Count - 1)
            {
                return;
            }

            float boost,
                  oldBoost = ((Field)fields[fieldIndex]).GetBoost();
            Field field    = Legacy.CreateField((string)lstFields.SelectedItem,
                                                txtContent.Text,
                                                chStored.Checked,
                                                chIndexed.Checked,
                                                chTokenized.Checked,
                                                chTVF.Checked);

            try
            {
                boost = Single.Parse(txtBoost.Text, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            catch (Exception)
            { boost = oldBoost; }
            field.SetBoost(boost);

            fields[fieldIndex] = field;
        }
Example #2
0
        void BeginAsyncReconstruction(int docNum, Document document, Hashtable doc)
        {
            // get stored fields
            ArrayList sf = new ArrayList();

            for (int i = 0; i < _indexFields.Length; i++)
            {
                Field[] f = document.GetFields(_indexFields[i]);
                if (f == null || f.Length == 0 || !f[0].IsStored())
                {
                    continue;
                }
                StringBuilder sb = new StringBuilder();
                for (int k = 0; k < f.Length; k++)
                {
                    if (k > 0)
                    {
                        sb.Append('\n');
                    }
                    sb.Append(f[k].StringValue());
                }
                Field field = Legacy.CreateField(_indexFields[i], sb.ToString(), f[0].IsStored(), f[0].IsIndexed(), f[0].IsTokenized(), f[0].IsTermVectorStored());
                field.SetBoost(f[0].GetBoost());
                doc[_indexFields[i]] = field;
                sf.Add(_indexFields[i]);
            }
            String term = null;
            GrowableStringArray terms = null;

            try
            {
                int i     = 0;
                int delta = (int)Math.Ceiling(((double)_numTerms / 100));

                TermEnum      te = _luke.IndexReader.Terms();
                TermPositions tp = _luke.IndexReader.TermPositions();
                while (te.Next())
                {
                    if ((i++ % delta) == 0)
                    {
                        // update UI - async
                        UpdateProgress(i / delta);
                    }

                    // skip stored fields
                    if (sf.Contains(te.Term().Field()))
                    {
                        continue;
                    }
                    tp.Seek(te.Term());
                    if (!tp.SkipTo(docNum) || tp.Doc() != docNum)
                    {
                        // this term is not found in the doc
                        continue;
                    }
                    term  = te.Term().Text();
                    terms = (GrowableStringArray)doc[te.Term().Field()];
                    if (terms == null)
                    {
                        terms = new GrowableStringArray();
                        doc[te.Term().Field()] = terms;
                    }
                    for (int k = 0; k < tp.Freq(); k++)
                    {
                        int pos = tp.NextPosition();
                        terms.Set(pos, term);
                    }
                }
            }
            catch (Exception exc)
            {
                // Update UI - async
                _luke.ShowStatus(exc.Message);
            }
        }
Example #3
0
        private void buttonCopyAll_Click(object sender, System.EventArgs e)
        {
            if (document == null)
            {
                return;
            }

            StringBuilder copyText = new StringBuilder();
            int           i        = 0;
            bool          store    = false,
                          index    = false,
                          token    = false,
                          tvf = false;
            float boost;

            foreach (ListViewItem item in listDocFields.Items)
            {
                boost = 0;

                if (item.SubItems[1].Text == "+")
                {
                    index = true;
                }
                else
                {
                    index = false;
                }
                if (item.SubItems[2].Text == "+")
                {
                    token = true;
                }
                else
                {
                    token = false;
                }
                if (item.SubItems[3].Text == "+")
                {
                    store = true;
                }
                else
                {
                    store = false;
                }
                if (item.SubItems[4].Text == "+")
                {
                    tvf = true;
                }
                else
                {
                    tvf = false;
                }
                try
                {
                    boost = Single.Parse(item.SubItems[5].Text, NumberFormatInfo.InvariantInfo);
                }
                catch (Exception) { }

                if (!index && !token && !store && !tvf &&
                    item.SubItems[item.SubItems.Count - 1].Text == _luke.resources.GetString("FieldNotAvailable"))
                {
                    continue;
                }

                if (i++ > 0)
                {
                    copyText.Append(Environment.NewLine);
                }

                Field field = Legacy.CreateField(item.SubItems[0].Text.Trim().Substring(1, item.SubItems[0].Text.Trim().Length - 2),
                                                 item.SubItems[item.SubItems.Count - 1].Text,
                                                 store,
                                                 index,
                                                 token,
                                                 tvf);
                field.SetBoost(boost);

                copyText.Append(field.ToString());
            }

            Clipboard.SetDataObject(copyText.ToString());
        }