diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index 9c22f0ba3..8cc3eebac 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -57,7 +57,7 @@ GEM jekyll (>= 3.5, < 5.0) jekyll-feed (~> 0.9) jekyll-seo-tag (~> 2.1) - nokogiri (1.13.4) + nokogiri (1.13.6) mini_portile2 (~> 2.8.0) racc (~> 1.4) pathutil (0.16.2) @@ -76,7 +76,7 @@ GEM rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) thread_safe (0.3.6) - tzinfo (1.2.5) + tzinfo (1.2.10) thread_safe (~> 0.1) tzinfo-data (1.2019.3) tzinfo (>= 1.0.0) diff --git a/docs/searching.md b/docs/searching.md index f3ea7609c..1a4c51f36 100644 --- a/docs/searching.md +++ b/docs/searching.md @@ -31,8 +31,8 @@ be searched. In most cases the field value type will be 'Full Text', others may ## Per field ```csharp -_var searcher = myIndex.GetSearcher(); // Get a searcher - var results = searcher.CreateQuery() // Create a query +var searcher = myIndex.GetSearcher(); // Get a searcher +var results = searcher.CreateQuery() // Create a query .Field("Address", "Hills") // Look for any "Hills" addresses .Execute(); // Execute the search ``` @@ -105,12 +105,10 @@ var filter = criteria.Field("nodeTypeAlias", "CWS_Home".Boost(20)); ```csharp var searcher = indexer.GetSearcher(); - //Arrange var criteria = searcher.CreateQuery("content"); - //get all nodes that contain the words warren and creative within 5 words of each other var filter = criteria.Field("metaKeywords", "Warren creative".Proximity(5)); ``` diff --git a/src/Examine.Lucene/ExamineReplicator.cs b/src/Examine.Lucene/ExamineReplicator.cs index 68f0f94b1..247e28430 100644 --- a/src/Examine.Lucene/ExamineReplicator.cs +++ b/src/Examine.Lucene/ExamineReplicator.cs @@ -50,11 +50,14 @@ public ExamineReplicator( var destDir = destinationDirectory as FSDirectory; // Callback, can be used to notifiy when replication is done (i.e. to open the index) - _logger.LogDebug( - "{IndexName} replication complete from {SourceDirectory} to {DestinationDirectory}", - sourceIndex.Name, - sourceDir?.Directory.ToString() ?? "InMemory", - destDir?.Directory.ToString() ?? "InMemory"); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug( + "{IndexName} replication complete from {SourceDirectory} to {DestinationDirectory}", + sourceIndex.Name, + sourceDir?.Directory.ToString() ?? "InMemory", + destDir?.Directory.ToString() ?? "InMemory"); + } } }), @@ -119,7 +122,10 @@ public void StartIndexReplicationOnSchedule(int milliseconds) private void SourceIndex_IndexCommitted(object sender, EventArgs e) { var index = (LuceneIndex)sender; - _logger.LogDebug("{IndexName} committed", index.Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} committed", index.Name); + } var rev = new IndexRevision(_sourceIndex.IndexWriter.IndexWriter); _replicator.Publish(rev); } diff --git a/src/Examine.Lucene/Indexing/IndexFieldValueTypeBase.cs b/src/Examine.Lucene/Indexing/IndexFieldValueTypeBase.cs index a9e8aac40..30a490ea2 100644 --- a/src/Examine.Lucene/Indexing/IndexFieldValueTypeBase.cs +++ b/src/Examine.Lucene/Indexing/IndexFieldValueTypeBase.cs @@ -91,8 +91,10 @@ protected bool TryConvert(object val, out T parsedVal) } catch (Exception ex) { - Logger.LogDebug(ex, "An conversion error occurred with from inputConverter.ConvertTo {FromValue} to {ToValueType}", val, typeof(T)); - + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug(ex, "An conversion error occurred with from inputConverter.ConvertTo {FromValue} to {ToValueType}", val, typeof(T)); + } parsedVal = default(T); return false; } @@ -109,8 +111,10 @@ protected bool TryConvert(object val, out T parsedVal) } catch (Exception ex) { - Logger.LogDebug(ex, "An conversion error occurred with outputConverter.ConvertFrom from {FromValue} to {ToValueType}", val, typeof(T)); - + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug(ex, "An conversion error occurred with outputConverter.ConvertFrom from {FromValue} to {ToValueType}", val, typeof(T)); + } parsedVal = default(T); return false; } @@ -124,8 +128,10 @@ protected bool TryConvert(object val, out T parsedVal) } catch (Exception ex) { - Logger.LogDebug(ex, "An conversion error occurred with Convert.ChangeType from {FromValue} to {ToValueType}", val, typeof(T)); - + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug(ex, "An conversion error occurred with Convert.ChangeType from {FromValue} to {ToValueType}", val, typeof(T)); + } parsedVal = default(T); return false; } diff --git a/src/Examine.Lucene/LoggingInfoStream.cs b/src/Examine.Lucene/LoggingInfoStream.cs index b47062cdd..62fed0700 100644 --- a/src/Examine.Lucene/LoggingInfoStream.cs +++ b/src/Examine.Lucene/LoggingInfoStream.cs @@ -11,6 +11,11 @@ internal class LoggingInfoStream : InfoStream public override bool IsEnabled(string component) => Logger.IsEnabled(LogLevel.Debug); public override void Message(string component, string message) - => Logger.LogDebug("{Component} - {Message}", component, message); + { + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("{Component} - {Message}", component, message); + } + } } } diff --git a/src/Examine.Lucene/Providers/LuceneIndex.cs b/src/Examine.Lucene/Providers/LuceneIndex.cs index 0013906d7..6ac9124eb 100644 --- a/src/Examine.Lucene/Providers/LuceneIndex.cs +++ b/src/Examine.Lucene/Providers/LuceneIndex.cs @@ -320,7 +320,10 @@ public void EnsureIndex(bool forceOverwrite) if (!indexExists) { - _logger.LogDebug("Initializing new index {IndexName}", Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Initializing new index {IndexName}", Name); + } //if there's no index, we need to create one CreateNewIndex(dir); @@ -328,8 +331,10 @@ public void EnsureIndex(bool forceOverwrite) else { //it does exists so we'll need to clear it out - - _logger.LogDebug("Clearing existing index {IndexName}", Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Clearing existing index {IndexName}", Name); + } if (_writer == null) { @@ -679,11 +684,14 @@ private bool DeleteFromIndex(Term indexTerm, bool performCommit = true) /// The writer that will be used to update the Lucene index. protected virtual void AddDocument(Document doc, ValueSet valueSet) { - _logger.LogDebug("{IndexName} Write lucene doc id:{DocumentId}, category:{DocumentCategory}, type:{DocumentItemType}", + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} Write lucene doc id:{DocumentId}, category:{DocumentCategory}, type:{DocumentItemType}", Name, valueSet.Id, valueSet.Category, valueSet.ItemType); + } //add node id IIndexFieldValueType nodeIdValueType = FieldValueTypeCollection.GetValueType(ExamineFieldNames.ItemIdFieldName, FieldValueTypeCollection.ValueTypeFactories.GetRequiredFactory(FieldDefinitionTypes.Raw)); @@ -901,8 +909,10 @@ private TrackingIndexWriter CreateIndexWriterInternal() { if (IsLocked(dir)) { - _logger.LogDebug("Forcing index {IndexName} to be unlocked since it was left in a locked state", Name); - + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Forcing index {IndexName} to be unlocked since it was left in a locked state", Name); + } //unlock it! Unlock(dir); } @@ -1089,14 +1099,20 @@ private void QueueTask(Func op, Action onComplete, { if (_asyncTask.IsCanceled) { - _logger.LogDebug("{IndexName} Indexing cancellation requested, cannot proceed", Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} Indexing cancellation requested, cannot proceed", Name); + } onComplete?.Invoke(new IndexOperationEventArgs(this, 0)); } else { if (_asyncTask.IsCompleted) { - _logger.LogDebug("{IndexName} Queuing a new background thread", Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} Queuing a new background thread", Name); + } } // The task is initialized to completed so just continue with @@ -1129,12 +1145,18 @@ private void QueueTask(Func op, Action onComplete, if (t.IsCanceled) { - _logger.LogDebug("{IndexName} Task was cancelled before it began", Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} Task was cancelled before it began", Name); + } onComplete?.Invoke(new IndexOperationEventArgs(this, 0)); } else if (t.IsFaulted) { - _logger.LogDebug(_asyncTask.Exception, "{IndexName} Task was cancelled before it began", Name); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug(_asyncTask.Exception, "{IndexName} Task was cancelled before it began", Name); + } onComplete?.Invoke(new IndexOperationEventArgs(this, 0)); } @@ -1159,7 +1181,10 @@ public void WaitForChanges() if (_latestGen.HasValue && !_disposedValue && !_cancellationToken.IsCancellationRequested) { var found = _nrtReopenThread?.WaitForGeneration(_latestGen.Value, 5000); - _logger.LogDebug("{IndexName} WaitForChanges returned {GenerationFound}", Name, found); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} WaitForChanges returned {GenerationFound}", Name, found); + } } } @@ -1293,7 +1318,12 @@ protected virtual void Dispose(bool disposing) void ReferenceManager.IRefreshListener.BeforeRefresh() { } void ReferenceManager.IRefreshListener.AfterRefresh(bool didRefresh) - => _logger.LogDebug("{IndexName} searcher refreshed? {DidRefresh}", Name, didRefresh); + { + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("{IndexName} searcher refreshed? {DidRefresh}", Name, didRefresh); + } + } }