private void LoadExistingSuggesionsExtentions(string indexName, Index indexImplementation) { var suggestionsForIndex = Path.Combine(configuration.IndexStoragePath, "Raven-Suggestions", indexName); if (!Directory.Exists(suggestionsForIndex)) { return; } foreach (var directory in Directory.GetDirectories(suggestionsForIndex)) { IndexSearcher searcher; using (indexImplementation.GetSearcher(out searcher)) { var key = Path.GetFileName(directory); var decodedKey = MonoHttpUtility.UrlDecode(key); var lastIndexOfDash = decodedKey.LastIndexOf('-'); var accuracy = float.Parse(decodedKey.Substring(lastIndexOfDash + 1)); var lastIndexOfDistance = decodedKey.LastIndexOf('-', lastIndexOfDash - 1); StringDistanceTypes distanceType; Enum.TryParse(decodedKey.Substring(lastIndexOfDistance + 1, lastIndexOfDash - lastIndexOfDistance - 1), true, out distanceType); var field = decodedKey.Substring(0, lastIndexOfDistance); var extension = new SuggestionQueryIndexExtension( Path.Combine(configuration.IndexStoragePath, "Raven-Suggestions", indexName, key), searcher.IndexReader, SuggestionQueryRunner.GetStringDistance(distanceType), field, accuracy); indexImplementation.SetExtension(key, extension); } } }
private void ReadIndexesFromDisk() { foreach (var index in Directory.GetFiles(path, "*.index")) { try { var indexDefinition = JsonConvert.DeserializeObject <IndexDefinition>(File.ReadAllText(index), Default.Converters); if (indexDefinition.Name == null) { indexDefinition.Name = MonoHttpUtility.UrlDecode(Path.GetFileNameWithoutExtension(index)); } AddAndCompileIndex(indexDefinition); } catch (Exception e) { logger.WarnException("Could not compile index " + index + ", skipping bad index", e); } } }
public IndexDefinitionStorage( ITransactionalStorage transactionalStorage, string path, IEnumerable <AbstractViewGenerator> compiledGenerators, AbstractDynamicCompilationExtension[] extensions) { this.extensions = extensions; // this is used later in the ctor, so it must appears first this.path = Path.Combine(path, IndexDefDir); if (Directory.Exists(this.path) == false) { Directory.CreateDirectory(this.path); } foreach (var index in Directory.GetFiles(this.path, "*.index")) { try { AddAndCompileIndex( MonoHttpUtility.UrlDecode(Path.GetFileNameWithoutExtension(index)), JsonConvert.DeserializeObject <IndexDefinition>(File.ReadAllText(index), new JsonEnumConverter()) ); } catch (Exception e) { logger.Warn("Could not compile index " + index + ", skipping bad index", e); } } //compiled view generators always overwrite dynamic views foreach (var generator in compiledGenerators) { var copy = generator; var displayNameAtt = TypeDescriptor.GetAttributes(copy) .OfType <DisplayNameAttribute>() .FirstOrDefault(); var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name; transactionalStorage.Batch(actions => { if (actions.Indexing.GetIndexesStats().Any(x => x.Name == name)) { return; } actions.Indexing.AddIndex(name); }); var indexDefinition = new IndexDefinition { Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName, // need to supply this so the index storage will create map/reduce index Reduce = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName, Indexes = generator.Indexes, Stores = generator.Stores, IsCompiled = true }; indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy); indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition); } }