public object GetIndexDocumentInfo(Node node, bool skipBinaries, out bool hasBinary) { var x = IndexDocumentInfo.Create(node, skipBinaries); hasBinary = x.HasBinaryField; return(x); }
// caller: IndexPopulator.Populator public void RepopulateTree(string path) { using (var traceOperation = Logger.TraceOperation("IndexPopulator RepopulateTree")) { var writer = IndexManager.GetIndexWriter(false); writer.DeleteDocuments(new Term(LucObject.FieldName.InTree, path.ToLowerInvariant())); try { foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath(path)) { var doc = IndexDocumentInfo.GetDocument(docData); if (doc == null) // indexing disabled { continue; } writer.AddDocument(doc); OnNodeIndexed(docData.Path); } writer.Optimize(); } finally { writer.Close(); } traceOperation.IsSuccessful = true; } }
private static void ValidateField(IndexDocumentInfo doc, string fieldName) { var field = doc.Fields.FirstOrDefault(f => f.Name == fieldName); if (field == null || string.IsNullOrEmpty(field.Value)) { throw new InvalidOperationException("Invalid empty field value for field: " + fieldName); } }
private IEnumerable <Fieldable> GetFieldsPrivate(IndexDocumentInfo info, IndexDocumentData docData) { var fields = new List <Fieldable>(); foreach (var provider in _providers) { var f = provider.GetFields(docData); if (f != null) { fields.AddRange(f); } } return(fields.Count == 0 ? null : fields); }
/*======================================================================================================= IIndexPopulator Members */ // caller: IndexPopulator.Populator, Import.Importer, Tests.Initializer, RunOnce public void ClearAndPopulateAll(bool backup = true) { var lastActivityId = IndexingActivityManager.GetLastActivityId(); var commitData = IndexManager.CreateCommitUserData(lastActivityId); using (var traceOperation = Logger.TraceOperation("IndexPopulator ClearAndPopulateAll")) { //-- recreate var writer = IndexManager.GetIndexWriter(true); try { foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath("/Root")) { var doc = IndexDocumentInfo.GetDocument(docData); if (doc == null) // indexing disabled { continue; } writer.AddDocument(doc); OnNodeIndexed(docData.Path); } RepositoryInstance.Instance.ConsoleWrite(" Commiting ... "); writer.Commit(commitData); RepositoryInstance.Instance.ConsoleWriteLine("ok"); RepositoryInstance.Instance.ConsoleWrite(" Optimizing ... "); writer.Optimize(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } finally { writer.Close(); } RepositoryInstance.Instance.ConsoleWrite(" Deleting indexing activities ... "); IndexingActivityManager.DeleteAllActivities(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); if (backup) { RepositoryInstance.Instance.ConsoleWrite(" Making backup ... "); BackupTools.BackupIndexImmediatelly(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } traceOperation.IsSuccessful = true; } }
internal static IEnumerable <Fieldable> GetFields(IndexDocumentInfo info, ContentRepository.Storage.Data.IndexDocumentData docData) { Debug.WriteLine("%> adding custom fields for " + docData.Path); return(Instance.GetFieldsPrivate(info, docData)); }
private static void ValidateDocumentInfo(IndexDocumentInfo doc) { ValidateField(doc, LucObject.FieldName.NodeId); ValidateField(doc, LucObject.FieldName.VersionId); }
internal static Document CreateDocument(IndexDocumentInfo info, IndexDocumentData docData) { if (info is NotIndexedIndexDocumentInfo) { return(null); } var doc = new Document(); foreach (var fieldInfo in info.fields) { if (fieldInfo.Name != "Password" && fieldInfo.Name != "PasswordHash") { doc.Add(CreateField(fieldInfo)); } } var path = docData.Path.ToLowerInvariant(); doc.Add(CreateStringField(LucObject.FieldName.Name, RepositoryPath.GetFileName(path), NameFieldIndexingInfo)); doc.Add(CreateStringField(LucObject.FieldName.Path, path, PathFieldIndexingInfo)); //LucObject.FieldName.Depth var nf = new NumericField(LucObject.FieldName.Depth, Field.Store.YES, true); nf.SetIntValue(DepthIndexHandler.GetDepth(docData.Path)); doc.Add(nf); //LucObject.FieldName.InTree //var fields = InTreeIndexHandlerInstance.GetIndexFields(LucObject.FieldName.InTree, docData.Path); var fields = CreateInTreeFields(LucObject.FieldName.InTree, docData.Path); foreach (var field in fields) { doc.Add(field); } //LucObject.FieldName.InFolder doc.Add(CreateInFolderField(LucObject.FieldName.InFolder, path)); //LucObject.FieldName.ParentId nf = new NumericField(LucObject.FieldName.ParentId, Field.Store.NO, true); nf.SetIntValue(docData.ParentId); doc.Add(nf); //LucObject.FieldName.IsSystem //doc.RemoveFields(LucObject.FieldName.IsSystem); doc.Add(new Field(LucObject.FieldName.IsSystem, docData.IsSystem ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO)); // flags doc.Add(new Field(LucObject.FieldName.IsLastPublic, docData.IsLastPublic ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO)); doc.Add(new Field(LucObject.FieldName.IsLastDraft, docData.IsLastDraft ? BooleanIndexHandler.YES : BooleanIndexHandler.NO, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO)); // timestamps nf = new NumericField(LucObject.FieldName.NodeTimestamp, Field.Store.YES, true); nf.SetLongValue(docData.NodeTimestamp); doc.Add(nf); nf = new NumericField(LucObject.FieldName.VersionTimestamp, Field.Store.YES, true); nf.SetLongValue(docData.VersionTimestamp); doc.Add(nf); // custom fields if (info.HasCustomField) { var customFields = CustomIndexFieldManager.GetFields(info, docData); if (customFields != null) { foreach (var field in customFields) { doc.Add(field); } } } return(doc); }
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); }