예제 #1
0
        public static IndexDocumentInfo Create(Node node, bool skipBinaries)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (!Indexable(node))
            {
                return(NotIndexedDocument);
            }

            var textEtract = new StringBuilder();
            var doc        = new IndexDocumentInfo();

            doc._hasCustomField = node is IHasCustomIndexField;

            var ixnode = node as IIndexableDocument;

            if (ixnode == null)
            {
                doc.AddField(LucObject.FieldName.NodeId, node.Id, Field.Store.YES, true);
                doc.AddField(LucObject.FieldName.VersionId, node.VersionId, Field.Store.YES, true);
                doc.AddField(LucObject.FieldName.Version, node.Version.ToString().ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED);
                doc.AddField(LucObject.FieldName.CreatedById, node.CreatedById, Field.Store.YES, true);
                doc.AddField(LucObject.FieldName.ModifiedById, node.ModifiedById, Field.Store.YES, true);
            }
            else
            {
                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 (skipBinaries && (field is BinaryField))
                    {
                        if (TextExtractor.TextExtractingWillBePotentiallySlow((BinaryData)((BinaryField)field).GetData()))
                        {
                            doc.HasBinaryField = true;
                            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);
                            doc.AddField(lucField);
                        }
                    }
                }
            }

            //doc.AddField(LucObject.FieldName.NodeTimestamp, node.NodeTimestamp, Field.Store.YES, true);
            //doc.AddField(LucObject.FieldName.VersionTimestamp, node.VersionTimestamp, Field.Store.YES, true);
            doc.AddField(LucObject.FieldName.IsInherited, node.IsInherited ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.AddField(LucObject.FieldName.IsMajor, node.Version.IsMajor ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.AddField(LucObject.FieldName.IsPublic, node.Version.Status == VersionStatus.Approved ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.AddField(LucObject.FieldName.AllText, textEtract.ToString(), Field.Store.NO, Field.Index.ANALYZED);

            ValidateDocumentInfo(doc);

            return(doc);
        }
예제 #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 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 faultedFieldNames = new List <string>();

            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;
                    }

                    IEnumerable <IndexFieldInfo> lucFields = null;
                    string extract = null;
                    try
                    {
                        lucFields = field.GetIndexFieldInfos(out extract);
                    }
                    catch (Exception)
                    {
                        faultedFieldNames.Add(field.Name);
                    }

                    if (!String.IsNullOrEmpty(extract)) // do not add extra line if extract is empty
                    {
                        try
                        {
                            textEtract.AppendLine(extract);
                        }
                        catch (OutOfMemoryException)
                        {
                            SnLog.WriteWarning("Out of memory error during indexing.",
                                               EventId.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);

            if (faultedFieldNames.Any())
            {
                if (!this.fields.Any(f => f.Name == LucObject.FieldName.IsFaulted))
                {
                    this.AddField(LucObject.FieldName.IsFaulted, BooleanIndexHandler.YES, Field.Store.YES, Field.Index.NOT_ANALYZED);
                }
                foreach (var faultedFieldName in faultedFieldNames)
                {
                    this.AddField(LucObject.FieldName.FaultedFieldName, faultedFieldName, Field.Store.YES, Field.Index.ANALYZED);
                }
            }

            return(this);
        }