public override void Update(IndexDefinitionBase definition, IndexingConfiguration configuration) { throw new NotSupportedException($"{Type} index does not support updating it's definition and configuration."); }
public abstract override IndexDefinitionCompareDifferences Compare(IndexDefinitionBase indexDefinition);
public CurrentIndexingScope(DocumentsStorage documentsStorage, DocumentsOperationContext documentsContext, IndexDefinitionBase indexDefinition, TransactionOperationContext indexContext, Func <string, SpatialField> getSpatialField, UnmanagedBuffersPoolWithLowMemoryHandling _unmanagedBuffersPool) { _documentsStorage = documentsStorage; _documentsContext = documentsContext; UnmanagedBuffersPool = _unmanagedBuffersPool; IndexDefinition = indexDefinition; IndexContext = indexContext; _getSpatialField = getSpatialField; }
private FaultyInMemoryIndex(Exception e, IndexingConfiguration configuration, IndexDefinitionBase definition) : base(IndexType.Faulty, definition) { _e = e; _createdAt = DateTime.UtcNow; State = IndexState.Error; Configuration = configuration; }
protected void add_index(IndexDefinitionBase definition) { AsyncHelpers.RunSync(() => _documentDatabase.IndexStore.CreateIndex(definition, Guid.NewGuid().ToString())); }
public override void Update(IndexDefinitionBase definition, IndexingConfiguration configuration) { SetLock(definition.LockMode); SetPriority(definition.Priority); }
private void add_index(IndexDefinitionBase definition) { _documentDatabase.IndexStore.CreateIndex(definition); }
private static Dictionary <string, FieldToFetch> GetFieldsToFetch(string[] fieldsToFetch, IndexDefinitionBase indexDefinition, out bool anyExtractableFromIndex) { anyExtractableFromIndex = false; if (fieldsToFetch == null || fieldsToFetch.Length == 0) { return(null); } var result = new Dictionary <string, FieldToFetch>(StringComparer.OrdinalIgnoreCase); for (var i = 0; i < fieldsToFetch.Length; i++) { var fieldToFetch = fieldsToFetch[i]; if (indexDefinition == null) { result[fieldToFetch] = new FieldToFetch(fieldToFetch, false); continue; } IndexField value; var extract = indexDefinition.TryGetField(fieldToFetch, out value) && value.Storage == FieldStorage.Yes; if (extract) { anyExtractableFromIndex = true; } result[fieldToFetch] = new FieldToFetch(fieldToFetch, extract | indexDefinition.HasDynamicFields); } if (indexDefinition != null) { anyExtractableFromIndex |= indexDefinition.HasDynamicFields; } return(result); }
public override IndexDefinitionCompareDifferences Compare(IndexDefinitionBase indexDefinition) { throw new NotImplementedException(); }
protected static RavenPerFieldAnalyzerWrapper CreateAnalyzer(Func <Analyzer> createDefaultAnalyzer, IndexDefinitionBase indexDefinition, bool forQuerying = false) { if (indexDefinition.IndexFields.ContainsKey(Constants.Documents.Indexing.Fields.AllFields)) { throw new InvalidOperationException($"Detected '{Constants.Documents.Indexing.Fields.AllFields}'. This field should not be present here, because inheritance is done elsewhere."); } Analyzer defaultAnalyzer = null; RavenStandardAnalyzer standardAnalyzer = null; KeywordAnalyzer keywordAnalyzer = null; if (indexDefinition is MapIndexDefinition mid) { if (mid.IndexDefinition.Fields.TryGetValue(Constants.Documents.Indexing.Fields.AllFields, out var value)) { switch (value.Indexing) { case FieldIndexing.Exact: defaultAnalyzer = keywordAnalyzer = new KeywordAnalyzer(); break; case FieldIndexing.Search: if (value.Analyzer != null) { defaultAnalyzer = GetAnalyzer(Constants.Documents.Indexing.Fields.AllFields, value.Analyzer, forQuerying); } if (defaultAnalyzer == null) { defaultAnalyzer = standardAnalyzer = new RavenStandardAnalyzer(Version.LUCENE_29); } break; default: // explictly ignore all other values break; } } } defaultAnalyzer = defaultAnalyzer ?? createDefaultAnalyzer(); var perFieldAnalyzerWrapper = new RavenPerFieldAnalyzerWrapper(defaultAnalyzer); foreach (var field in indexDefinition.IndexFields) { var fieldName = field.Value.Name; switch (field.Value.Indexing) { case FieldIndexing.Exact: if (keywordAnalyzer == null) { keywordAnalyzer = new KeywordAnalyzer(); } perFieldAnalyzerWrapper.AddAnalyzer(fieldName, keywordAnalyzer); break; case FieldIndexing.Search: var analyzer = GetAnalyzer(fieldName, field.Value.Analyzer, forQuerying); if (analyzer != null) { perFieldAnalyzerWrapper.AddAnalyzer(fieldName, analyzer); continue; } AddStandardAnalyzer(fieldName); break; } } return(perFieldAnalyzerWrapper); void AddStandardAnalyzer(string fieldName) { if (standardAnalyzer == null) { standardAnalyzer = new RavenStandardAnalyzer(Version.LUCENE_29); } perFieldAnalyzerWrapper.AddAnalyzer(fieldName, standardAnalyzer); } }
public CurrentIndexingScope(DocumentsStorage documentsStorage, DocumentsOperationContext documentsContext, IndexDefinitionBase indexDefinition, TransactionOperationContext indexContext, Func <string, SpatialField> getSpatialField) { _documentsStorage = documentsStorage; _documentsContext = documentsContext; IndexDefinition = indexDefinition; IndexContext = indexContext; _getSpatialField = getSpatialField; }
public void WriteIndex(IndexDefinitionBase indexDefinition, IndexType indexType) { AsyncHelpers.RunSync(() => _database.IndexStore.CreateIndex(indexDefinition)); }
protected static RavenPerFieldAnalyzerWrapper CreateAnalyzer(Func <Analyzer> createDefaultAnalyzer, IndexDefinitionBase indexDefinition, bool forQuerying = false) { if (indexDefinition.IndexFields.ContainsKey(Constants.Documents.Indexing.Fields.AllFields)) { throw new InvalidOperationException($"Detected '{Constants.Documents.Indexing.Fields.AllFields}'. This field should not be present here, because inheritance is done elsewhere."); } var analyzers = new Dictionary <Type, Analyzer>(); var hasDefaultFieldOptions = false; Analyzer defaultAnalyzerToUse = null; Analyzer defaultAnalyzer = null; if (indexDefinition is MapIndexDefinition mid) { if (mid.IndexDefinition.Fields.TryGetValue(Constants.Documents.Indexing.Fields.AllFields, out var value)) { hasDefaultFieldOptions = true; switch (value.Indexing) { case FieldIndexing.Exact: defaultAnalyzerToUse = GetOrCreateAnalyzer(typeof(KeywordAnalyzer), CreateKeywordAnalyzer); break; case FieldIndexing.Search: if (value.Analyzer != null) { defaultAnalyzerToUse = GetAnalyzer(Constants.Documents.Indexing.Fields.AllFields, value.Analyzer, analyzers, forQuerying); } if (defaultAnalyzerToUse == null) { defaultAnalyzerToUse = GetOrCreateAnalyzer(typeof(RavenStandardAnalyzer), CreateStandardAnalyzer); } break; default: // explicitly ignore all other values break; } } } if (defaultAnalyzerToUse == null) { defaultAnalyzerToUse = defaultAnalyzer = createDefaultAnalyzer(); analyzers.Add(defaultAnalyzerToUse.GetType(), defaultAnalyzerToUse); } var perFieldAnalyzerWrapper = forQuerying == false && indexDefinition.HasDynamicFields ? new RavenPerFieldAnalyzerWrapper( defaultAnalyzerToUse, () => GetOrCreateAnalyzer(typeof(RavenStandardAnalyzer), CreateStandardAnalyzer), () => GetOrCreateAnalyzer(typeof(KeywordAnalyzer), CreateKeywordAnalyzer)) : new RavenPerFieldAnalyzerWrapper(defaultAnalyzerToUse); foreach (var field in indexDefinition.IndexFields) { var fieldName = field.Value.Name; switch (field.Value.Indexing) { case FieldIndexing.Exact: var keywordAnalyzer = GetOrCreateAnalyzer(typeof(KeywordAnalyzer), CreateKeywordAnalyzer); perFieldAnalyzerWrapper.AddAnalyzer(fieldName, keywordAnalyzer); break; case FieldIndexing.Search: var analyzer = GetAnalyzer(fieldName, field.Value.Analyzer, analyzers, forQuerying); if (analyzer != null) { perFieldAnalyzerWrapper.AddAnalyzer(fieldName, analyzer); continue; } AddStandardAnalyzer(fieldName); break; case FieldIndexing.Default: if (hasDefaultFieldOptions) { // if we have default field options then we need to take into account overrides for regular fields if (defaultAnalyzer == null) { defaultAnalyzer = createDefaultAnalyzer(); } perFieldAnalyzerWrapper.AddAnalyzer(fieldName, defaultAnalyzer); continue; } break; } } return(perFieldAnalyzerWrapper); void AddStandardAnalyzer(string fieldName) { var standardAnalyzer = GetOrCreateAnalyzer(typeof(RavenStandardAnalyzer), CreateStandardAnalyzer); perFieldAnalyzerWrapper.AddAnalyzer(fieldName, standardAnalyzer); } Analyzer GetOrCreateAnalyzer(Type analyzerType, Func <Analyzer> createAnalyzer) { if (analyzers.TryGetValue(analyzerType, out var analyzer) == false) { analyzers[analyzerType] = analyzer = createAnalyzer(); } return(analyzer); } KeywordAnalyzer CreateKeywordAnalyzer() { return(new KeywordAnalyzer()); } RavenStandardAnalyzer CreateStandardAnalyzer() { return(new RavenStandardAnalyzer(Version.LUCENE_29)); } }
public FieldsToFetch(IndexQueryServerSide query, IndexDefinitionBase indexDefinition) : this(query.Metadata.SelectFields, indexDefinition) { IsDistinct = query.Metadata.IsDistinct && IsProjection; }
public override IndexDefinitionCompareDifferences Compare(IndexDefinitionBase indexDefinition) { return(Definition.Compare(indexDefinition)); }
private static FieldToFetch GetFieldToFetch( IndexDefinitionBase indexDefinition, SelectField selectField, Dictionary <string, FieldToFetch> results, out string selectFieldKey, ref bool anyExtractableFromIndex, ref bool extractAllStoredFields) { selectFieldKey = selectField.Alias ?? selectField.Name; var selectFieldName = selectField.Name; if (selectField.ValueTokenType != null) { return(new FieldToFetch(string.Empty, selectField, selectField.Alias, canExtractFromIndex: false, isDocumentId: false)); } if (selectField.Function != null) { var fieldToFetch = new FieldToFetch(selectField.Name, selectField, selectField.Alias, canExtractFromIndex: false, isDocumentId: false) { FunctionArgs = new FieldToFetch[selectField.FunctionArgs.Length] }; for (int j = 0; j < selectField.FunctionArgs.Length; j++) { bool ignored = false; fieldToFetch.FunctionArgs[j] = GetFieldToFetch(indexDefinition, selectField.FunctionArgs[j], null, out _, ref ignored, ref ignored ); } return(fieldToFetch); } if (selectFieldName == null) { if (selectField.IsGroupByKey == false) { return(null); } if (selectField.GroupByKeys.Length == 1) { selectFieldName = selectField.GroupByKeys[0].Name; if (selectFieldKey == null) { selectFieldKey = selectFieldName; } } else { selectFieldKey = selectFieldKey ?? "Key"; return(new FieldToFetch(selectFieldKey, selectField.GroupByKeyNames)); } } if (indexDefinition == null) { return(new FieldToFetch(selectFieldName, selectField, selectField.Alias, canExtractFromIndex: false, isDocumentId: false)); } if (selectFieldName.Value.Length > 0) { if (selectFieldName == Constants.Documents.Indexing.Fields.DocumentIdFieldName) { anyExtractableFromIndex = true; return(new FieldToFetch(selectFieldName, selectField, selectField.Alias, canExtractFromIndex: false, isDocumentId: true)); } if (selectFieldName.Value[0] == '_') { if (selectFieldName == Constants.Documents.Indexing.Fields.AllStoredFields) { if (results == null) { ThrowInvalidFetchAllStoredDocuments(); } Debug.Assert(results != null); results.Clear(); // __all_stored_fields should only return stored fields so we are ensuring that no other fields will be returned extractAllStoredFields = true; foreach (var kvp in indexDefinition.MapFields) { var stored = kvp.Value.Storage == FieldStorage.Yes; if (stored == false) { continue; } anyExtractableFromIndex = true; results[kvp.Key] = new FieldToFetch(kvp.Key, null, null, canExtractFromIndex: true, isDocumentId: false); } return(null); } } } var extract = indexDefinition.MapFields.TryGetValue(selectFieldName, out var value) && value.Storage == FieldStorage.Yes; if (extract) { anyExtractableFromIndex = true; } return(new FieldToFetch(selectFieldName, selectField, selectField.Alias, extract | indexDefinition.HasDynamicFields, isDocumentId: false)); }
public FieldsToFetch(IndexQueryServerSide query, IndexDefinitionBase indexDefinition, Transformer transformer) : this(query.FieldsToFetch, indexDefinition, transformer) { IsDistinct = query.IsDistinct && IsProjection; }