Skip to content

Commit

Permalink
Add Search everywhere checkbox #1812
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Aug 18, 2023
1 parent f421c74 commit 4ac32bf
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 31 deletions.
53 changes: 39 additions & 14 deletions Analogy.Common/DataTypes/FilterCriteriaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class FilterCriteriaObject
public string[] ExcludedSources;
public string[] Modules;
public string[] ExcludedModules;

public bool SearchEveryWhere { get; set; }
public List<string> Columns { get; set; }
public string TextInclude { get; set; }
public string TextExclude { get; set; }
public DateTime StartTime { get; set; }
Expand All @@ -29,7 +30,6 @@ public AnalogyLogLevel[] Levels
get => _arrLevels;
set => _arrLevels = value;
}

public List<FilterCriteriaUIOption> IncludeFilterCriteriaUIOptions { get; set; }
public List<FilterCriteriaUIOption> ExcludeFilterCriteriaUIOptions { get; set; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -106,11 +106,11 @@ private void SetSources(string sources)
public string GetSqlExpression(bool orLogLevel)
{

StringBuilder sqlString = new StringBuilder();
List<string> includeTexts = new List<string> { EscapeLikeValue(TextInclude.Trim()) };
StringBuilder sqlString = new();
List<string> includeTexts = new() { EscapeLikeValue(TextInclude.Trim()) };

bool orOperationInInclude = false;
bool orOperationInexclude = false;
bool orOperationInExclude = false;
var text = EscapeLikeValue(TextInclude.Trim());
if (text.Contains('|'))
{
Expand All @@ -124,7 +124,7 @@ public string GetSqlExpression(bool orLogLevel)
var split = text.Split(new[] { '&', '+' }, StringSplitOptions.RemoveEmptyEntries).ToList();
includeTexts = split.Select(itm => itm.Trim()).ToList();
}
List<string> excludedTexts = new List<string>(0);
List<string> excludedTexts = new();
if (!string.IsNullOrEmpty(TextExclude))
{
excludedTexts.Add(EscapeLikeValue(TextExclude.Trim()));
Expand All @@ -133,7 +133,7 @@ public string GetSqlExpression(bool orLogLevel)
text = EscapeLikeValue(TextExclude.Trim());
if (text.Contains("|"))
{
orOperationInexclude = true;
orOperationInExclude = true;
var split = text.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
excludedTexts = split.Select(itm => itm.Trim()).Where(w => !string.IsNullOrEmpty(w)).ToList();
}
Expand All @@ -145,16 +145,14 @@ public string GetSqlExpression(bool orLogLevel)

sqlString.Append("(");

sqlString.Append(orOperationInInclude
? string.Join(" Or ", includeTexts.Select(t => $" Text like '%{t}%'"))
: string.Join(" and ", includeTexts.Select(t => $" Text like '%{t}%'")));
sqlString.Append(GetIncludeTextFilter(includeTexts, orOperationInInclude));

sqlString.Append(")");

if (excludedTexts.Any())
{
sqlString.Append(" and (");
sqlString.Append(orOperationInexclude
sqlString.Append(orOperationInExclude
? string.Join(" and ", excludedTexts.Select(t => $" NOT Text like '%{t}%'"))
: string.Join(" Or ", excludedTexts.Select(t => $" NOT Text like '%{t}%'")));

Expand Down Expand Up @@ -198,7 +196,7 @@ public string GetSqlExpression(bool orLogLevel)

sqlString.Append(dateFilter);

if (includeTexts.Any())
if (includeTexts.Any() && !SearchEveryWhere)
{
var includeColumns = IncludeFilterCriteriaUIOptions.Where(f => f.CheckMember);
foreach (FilterCriteriaUIOption include in includeColumns)
Expand All @@ -218,7 +216,7 @@ public string GetSqlExpression(bool orLogLevel)
foreach (FilterCriteriaUIOption exclude in excludeColumns)
{
sqlString.Append(" and (");
string op = (orOperationInexclude) ? "and" : "or";
string op = (orOperationInExclude) ? "and" : "or";
sqlString.Append(string.Join($" {op} ",
excludedTexts.Select(l =>
$" NOT [{EscapeLikeValue(exclude.ValueMember)}] like '%{EscapeLikeValue(l)}%'")));
Expand All @@ -228,6 +226,33 @@ public string GetSqlExpression(bool orLogLevel)

return sqlString.ToString();
}

private string GetIncludeTextFilter(List<string> includeTexts, bool orOperationInInclude)
{
IEnumerable<string> GenerateSingleCombinationPerColumn(string field)
{
foreach (string text in includeTexts)
{
yield return $" {field} like '%{text}%'";
}
}

if (SearchEveryWhere)
{
var entries = Columns.Select(c =>
string.Join(orOperationInInclude ? " Or " : " and ",
GenerateSingleCombinationPerColumn(c)));
var combined = string.Join(" Or ", entries);
return combined;
}
else
{
var includeTextFinal = orOperationInInclude
? string.Join(" Or ", GenerateSingleCombinationPerColumn("Text"))
: string.Join(" and ", GenerateSingleCombinationPerColumn("Text"));
return includeTextFinal;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Match(string rowLine, string criteria, PreDefinedQueryType type)
{
Expand Down
52 changes: 41 additions & 11 deletions Analogy.CommonControls/UserControls/LogMessagesUC.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 31 additions & 4 deletions Analogy.CommonControls/UserControls/LogMessagesUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private List<IAnalogyLogMessage> BookmarkedMessages
}
}
private AnalogyLogMessage? SelectedMassage { get; set; }
private FilterCriteriaObject _filterCriteria = new FilterCriteriaObject();
private readonly FilterCriteriaObject _filterCriteria = new FilterCriteriaObject();
private AutoCompleteStringCollection autoCompleteInclude = new AutoCompleteStringCollection();
private AutoCompleteStringCollection autoCompleteExclude = new AutoCompleteStringCollection();

Expand Down Expand Up @@ -202,7 +202,7 @@ public bool RealTimeMode

public LogMessagesUC()
{

InitializeComponent();
DateTimePicker = new DateTimeSelectionUC();
JsonColumnChooser = new JsonColumnChooserUC();
Expand All @@ -212,7 +212,7 @@ public LogMessagesUC()
}
Id = Guid.NewGuid();
SetupDependencies();

PopupControlContainer datePopup = new PopupControlContainer();
datePopup.Manager = this.barManager1;
datePopup.Controls.Add(DateTimePicker);
Expand Down Expand Up @@ -458,6 +458,11 @@ private void rgSearchMode_SelectedIndexChanged(object s, EventArgs e)
}
private void SetupEventsHandlers()
{
ceSearchEverywhere.CheckedChanged += async (s, e) =>
{
_filterCriteria.SearchEveryWhere = ceSearchEverywhere.Checked;
await FilterHasChanged();
};
ddbGoTo.ArrowButtonClick += (s, e) =>
{
var times = GetMessages().Select(m => m.Date).Distinct().ToList();
Expand Down Expand Up @@ -841,6 +846,7 @@ private void SetupEventsHandlers()
logGrid.CustomDrawRowIndicator += LogGrid_CustomDrawRowIndicator;
logGrid.SelectionChanged += LogGridView_SelectionChanged;
logGrid.FocusedRowChanged += logGrid_FocusedRowChanged;
logGrid.ColumnPositionChanged += LogGrid_ColumnPositionChanged;
gridViewBookmarkedMessages.RowStyle += LogGridView_RowStyle;
#endregion
ceFilterPanelFilter.CheckStateChanged += rgSearchMode_SelectedIndexChanged;
Expand Down Expand Up @@ -973,6 +979,27 @@ private void SetupEventsHandlers()

#endregion
}

private void LogGrid_ColumnPositionChanged(object? sender, EventArgs e)
{
UpdateSearchColumn();
}

public void UpdateSearchColumn()
{
_filterCriteria.Columns = logGrid.Columns.Where(c => c.Visible)
.Except(new List<GridColumn>()
{
gridColumnDate,
gridColumnTimeDiff,
gridColumnObject,
gridColumnLineNumber,
gridColumnProcessID,
gridColumnThread,
gridColumnRawText,
})
.Select(c => c.FieldName).ToList();
}
private void GridView_ShownEditor(object sender, System.EventArgs e)
{
var view = sender as GridView;
Expand Down Expand Up @@ -1427,7 +1454,7 @@ private void LoadUISettings()
btsiInlineJsonViewer.Checked = Settings.InlineJsonViewer;
bbiJsonColumn.Visibility = Settings.InlineJsonViewer ? BarItemVisibility.Always : BarItemVisibility.Never;
spltcMessages.PanelVisibility = Settings.InlineJsonViewer ? SplitPanelVisibility.Both : SplitPanelVisibility.Panel1;

UpdateSearchColumn();
}

private void SetupMessageDetailPanel()
Expand Down
4 changes: 2 additions & 2 deletions Analogy.CommonControls/UserControls/LogMessagesUC.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZ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M5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down

0 comments on commit 4ac32bf

Please sign in to comment.