Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into release/3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Sep 7, 2022
2 parents f51fdae + 249e4c7 commit 908721b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions docs/searching.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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));
```
Expand Down
18 changes: 12 additions & 6 deletions src/Examine.Lucene/ExamineReplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

}),
Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 12 additions & 6 deletions src/Examine.Lucene/Indexing/IndexFieldValueTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ protected bool TryConvert<T>(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;
}
Expand All @@ -109,8 +111,10 @@ protected bool TryConvert<T>(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;
}
Expand All @@ -124,8 +128,10 @@ protected bool TryConvert<T>(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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Examine.Lucene/LoggingInfoStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ internal class LoggingInfoStream<T> : 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);
}
}
}
}
54 changes: 42 additions & 12 deletions src/Examine.Lucene/Providers/LuceneIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,21 @@ 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);
}
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)
{
Expand Down Expand Up @@ -679,11 +684,14 @@ private bool DeleteFromIndex(Term indexTerm, bool performCommit = true)
/// <param name="writer">The writer that will be used to update the Lucene index.</param>
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));
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1089,14 +1099,20 @@ private void QueueTask(Func<int> op, Action<IndexOperationEventArgs> 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
Expand Down Expand Up @@ -1129,12 +1145,18 @@ private void QueueTask(Func<int> op, Action<IndexOperationEventArgs> 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));
}

Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}


Expand Down

0 comments on commit 908721b

Please sign in to comment.