예제 #1
0
        private static AbstractField CreateField(IndexFieldInfo fieldInfo)
        {
            NumericField nf;

            switch (fieldInfo.Type)
            {
            case FieldInfoType.StringField:
                return(new Field(fieldInfo.Name, fieldInfo.Value, fieldInfo.Store, fieldInfo.Index, fieldInfo.TermVector));

            case FieldInfoType.IntField:
                nf = new NumericField(fieldInfo.Name, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
                nf.SetIntValue(Int32.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
                return(nf);

            case FieldInfoType.LongField:
                nf = new NumericField(fieldInfo.Name, 8, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
                nf.SetLongValue(Int64.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
                return(nf);

            case FieldInfoType.SingleField:
                nf = new NumericField(fieldInfo.Name, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
                nf.SetFloatValue(Single.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
                return(nf);

            case FieldInfoType.DoubleField:
                nf = new NumericField(fieldInfo.Name, 8, fieldInfo.Store, fieldInfo.Index != Field.Index.NO);
                nf.SetDoubleValue(Double.Parse(fieldInfo.Value, CultureInfo.InvariantCulture));
                return(nf);

            default:
                throw new NotImplementedException("IndexFieldInfo." + fieldInfo.Type);
            }
        }
예제 #2
0
        public IndexDocumentInfo Complete(Node node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var allTextFieldIndex = -1;

            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Name == LucObject.FieldName.AllText)
                {
                    allTextFieldIndex = i;
                    break;
                }
            }
            var allTextField = this.fields[allTextFieldIndex];
            var textEtract   = new StringBuilder(allTextField.Value);

            var ixnode = node as IIndexableDocument;

            if (ixnode != null)
            {
                var fieldNames = new List <string>();
                foreach (var field in ixnode.GetIndexableFields())
                {
                    if (ForbiddenFields.Contains(field.Name))
                    {
                        continue;
                    }
                    if (PostponedFields.Contains(field.Name))
                    {
                        continue;
                    }
                    if (node.SavingState != ContentSavingState.Finalized && (field is BinaryField || SkippedMultistepFields.Contains(field.Name)))
                    {
                        continue;
                    }
                    if (!(field is BinaryField))
                    {
                        continue;
                    }
                    if (!TextExtractor.TextExtractingWillBePotentiallySlow((BinaryData)((BinaryField)field).GetData()))
                    {
                        continue;
                    }

                    string extract;
                    var    lucFields = field.GetIndexFieldInfos(out extract);

                    try
                    {
                        textEtract.AppendLine(extract);
                    }
                    catch (OutOfMemoryException)
                    {
                        Logger.WriteWarning(ContentRepository.EventId.Indexing.FieldIndexingError, "Out of memory error during indexing.", properties: new Dictionary <string, object>
                        {
                            { "Path", node.Path },
                            { "Field", field.Name }
                        });
                    }

                    if (lucFields != null)
                    {
                        foreach (var lucField in lucFields)
                        {
                            fieldNames.Add(lucField.Name);
                            this.AddField(lucField);
                        }
                    }
                }
            }

            fields[allTextFieldIndex] = new IndexFieldInfo(LucObject.FieldName.AllText, textEtract.ToString(), FieldInfoType.StringField, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO);

            return(this);
        }
예제 #3
0
 public void AddField(IndexFieldInfo fieldInfo)
 {
     fields.Add(fieldInfo);
 }