Esempio n. 1
0
        private void ReconstructFields(Hashtable doc)
        {
            fields = new ArrayList(doc.Count + 5);
            fieldsReconstructed = new ArrayList(doc.Count + 5);
            int i = 0;

            foreach (string key in doc.Keys)
            {
                Object t = doc[key];

                // create/reconstruct fields
                if (typeof(Field).IsInstanceOfType(t))
                {
                    fields.Add(t);
                    fieldsReconstructed.Add(false);
                }
                else
                {
                    fieldsReconstructed.Add(true);

                    GrowableStringArray terms = (GrowableStringArray)doc[key];
                    StringBuilder       sb    = new StringBuilder();
                    if (terms != null)
                    {
                        String sNull = "null";
                        int    k = 0, m = 0;
                        for (int j = 0; j < terms.Size(); j++)
                        {
                            if (terms.Get(j) == null)
                            {
                                k++;
                            }
                            else
                            {
                                if (sb.Length > 0)
                                {
                                    sb.Append(' ');
                                }
                                if (k > 0)
                                {
                                    sb.Append(sNull + "_" + k + " ");
                                    k = 0;
                                    m++;
                                }
                                sb.Append(terms.Get(j));
                                m++;
                                if (m % 10 == 0)
                                {
                                    sb.Append('\n');
                                }
                            }
                        }
                    }
                    Field newField = new Field(key, sb.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED, Field.TermVector.NO);
                    newField.SetBoost(document.GetBoost());
                    fields.Add(newField);
                }
                i++;
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 3
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);
            }
        }