B2026 053 find unlinked values of selected #795
@@ -7279,33 +7279,10 @@ namespace VEPROMS.CSLA.Library
|
||||
_ByWordSuffix = byWordSuffix;
|
||||
}
|
||||
}
|
||||
private string checkPercentChar(string SearchString)
|
||||
{
|
||||
string ss = "";
|
||||
string pattern = "%"; // Pattern to match the percentage sign
|
||||
Match match = Regex.Match(SearchString, pattern);
|
||||
if (match.Success)
|
||||
{
|
||||
int sl = SearchString.Length;
|
||||
int precentIdx = SearchString.IndexOf('%');
|
||||
int startIndex = 0;
|
||||
if (sl == precentIdx + 1) // % the last char.
|
||||
{
|
||||
ss = SearchString.Substring(startIndex, sl - 1);
|
||||
var isNumeric = int.TryParse(ss, out int n);
|
||||
if (isNumeric == true) // other that a % are the rest of the characters numbers.
|
||||
{
|
||||
ss = ' ' + SearchString; //add a space prefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ss;
|
||||
}
|
||||
|
||||
|
mschill marked this conversation as resolved
Outdated
|
||||
private void DataPortal_Fetch(ItemListSearchCriteria criteria)
|
||||
{
|
||||
this.RaiseListChangedEvents = false;
|
||||
//criteria.SearchString = checkPercentChar(criteria.SearchString);
|
||||
try
|
||||
{
|
||||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||||
|
||||
@@ -2078,8 +2078,9 @@ namespace Volian.Controls.Library
|
||||
|
||||
if (cbxFndUnLnkROVals.Enabled && cbxFndUnLnkROVals.Checked)
|
||||
{
|
||||
string ROSearchList2 = checkPercentChar(ROSearchList); // match exact string
|
||||
// B2022-031 - added a cbxProcSectSrch to filter out procedure and section titles from global search results.
|
||||
SearchResults = ItemInfoList.GetListFromTextSearch(DVISearchList, TypeSearchList, ROSearchList, cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, cbxProcSectSrch.Checked ? 1 : 0, ItemSearchIncludeLinks.Nothing, includeRTFformat, includeSpecialChars, unitPrefix, string.Empty, string.Empty);
|
||||
SearchResults = ItemInfoList.GetListFromTextSearch(DVISearchList, TypeSearchList, ROSearchList2, cbxBooleanTxtSrch.Checked ? 2 : cbxCaseSensitive.Checked ? 1 : 0, cbxProcSectSrch.Checked ? 1 : 0, ItemSearchIncludeLinks.Nothing, includeRTFformat, includeSpecialChars, unitPrefix, string.Empty, string.Empty);
|
||||
cmbResultsStyleIndex = 3; // display step text in results
|
||||
|
mschill
commented
lines 2092 - 2099 - the setting of ByWordPrefeix and ByWordSuffixL Regexes are very hard on applications performance wise --- If just want to determine if a string ends in a Number, can't you use something like: char.IsNumber(ROSearchList, ROSearchList.Length - 1); There are also functions like char.IsDigit if needed. Obviously, you would need to 1st check that temp.Length > 0 Side question - if all we are doing is adding a regex prefix/suffix onto the checking code --- could we end up with stuff like 3.5 matching 3.52 since both end in a number and contain 3.5 ? -- You may be able to do something like pull back all the matches and then use LINQ to filter the list to ones that either end with the match or contain a space/bracket/parenthesis/punctuation after the match . lines 2092 - 2099 - the setting of ByWordPrefeix and ByWordSuffixL
Regexes are very hard on applications performance wise --- If just want to determine if a string ends in a Number, can't you use something like:
char.IsNumber(ROSearchList, ROSearchList.Length - 1);
char.IsLetter(ROSearchList, ROSearchList.Length - 1);
char.IsNumber(ROSearchList, 0);
char.IsLetter(ROSearchList, 0);
There are also functions like char.IsDigit if needed.
Obviously, you would need to 1st check that temp.Length > 0
Side question - if all we are doing is adding a regex prefix/suffix onto the checking code --- could we end up with stuff like 3.5 matching 3.52 since both end in a number and contain 3.5 ? -- You may be able to do something like pull back all the matches and then use LINQ to filter the list to ones that either end with the match or contain a space/bracket/parenthesis/punctuation after the match .
jjenko
commented
Matt, That same code is used above this code block for doing a By Word text search. I was going to suggest that instead of copying the code, to make it it's own function and call it in the two places. Matt,
I don't know if this makes any difference, but the byWordPrex and byWordSuffix strings get passed to a SQL stored procedure.
That same code is used above this code block for doing a By Word text search. I was going to suggest that instead of copying the code, to make it it's own function and call it in the two places.
mschill
commented
Would agree - if it is repeated code / a repeated idea - better to make it it's own function. That being said, while regexes are necessary in some places, any place that it works where we can replace a call with function calls like char.IsNumeric, it will benefit performance, Would agree - if it is repeated code / a repeated idea - better to make it it's own function. That being said, while regexes are necessary in some places, any place that it works where we can replace a call with function calls like char.IsNumeric, it will benefit performance,
|
||||
}
|
||||
else
|
||||
@@ -2190,6 +2191,34 @@ namespace Volian.Controls.Library
|
||||
OnSearchComplete(new DisplaySearchEventArgs(TimeSpan.FromTicks(DateTime.Now.Ticks - start.Ticks)));
|
||||
}
|
||||
|
||||
private string checkPercentChar(string SearchString)
|
||||
|
jjenko marked this conversation as resolved
Outdated
jjenko
commented
by always adding a space before the search text, it will not find places where the unlinked RO Value is the first thing on the line. Ex. an Equipment List might have only the unlinked RO Value. I noticed that the last two fields in the call to GetListFromTextSearch() are for a "by word" text search and passes in a Regx expression. Could that be used? - look for "if (cbxByWord.Checked)" by always adding a space before the search text, it will not find places where the unlinked RO Value is the first thing on the line. Ex. an Equipment List might have only the unlinked RO Value.
I noticed that the last two fields in the call to GetListFromTextSearch() are for a "by word" text search and passes in a Regx expression. Could that be used? - look for "if (cbxByWord.Checked)"
|
||||
{
|
||||
string ss = "";
|
||||
string pattern = "%"; // Pattern to match the percentage sign
|
||||
Match match = Regex.Match(SearchString, pattern);
|
||||
if (match.Success) // Special case for percents.
|
||||
{
|
||||
int sl = SearchString.Length;
|
||||
int precentIdx = SearchString.IndexOf('%');
|
||||
|
mschill marked this conversation as resolved
Outdated
mschill
commented
What if multiple % signs? - like search for: What if multiple % signs? - like search for:
3% or 4% --- I believe the matches returned by the Regex object will give position of what is found.
|
||||
int startIndex = 0;
|
||||
if (sl == precentIdx + 1) // % the last char.
|
||||
{
|
||||
ss = SearchString.Substring(startIndex, sl - 1);
|
||||
var isNumeric = int.TryParse(ss, out int n);
|
||||
if (isNumeric == true) // other that a % are the rest of the characters numbers.
|
||||
|
mschill marked this conversation as resolved
Outdated
mschill
commented
With working on tech debt project --- moving forward need to follow suggested code practices / suggestions by SonarLint --- if (isNumeric == true) should be With working on tech debt project --- moving forward need to follow suggested code practices / suggestions by SonarLint --- if (isNumeric == true) should be
if (isNumeric)
|
||||
{
|
||||
ss = ' ' + SearchString; //add a space prefix to make the search exact. If search is 5% this makes it excult 25% 55% etc.;
|
||||
|
mschill marked this conversation as resolved
Outdated
mschill
commented
With working on technical debt - should avoid concatenating strings & use string interpolation instead. With working on technical debt - should avoid concatenating strings & use string interpolation instead.
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
mschill marked this conversation as resolved
Outdated
mschill
commented
With working on technical debt - should avoid concatenating strings & use string interpolation instead. With working on technical debt - should avoid concatenating strings & use string interpolation instead.
|
||||
{
|
||||
ss = ' ' + SearchString + ' '; // Exact match add spaces before and after search string.
|
||||
|
||||
}
|
||||
return ss;
|
||||
}
|
||||
|
||||
private void ClearResults() // B2021-103 if no results when RNO only, clear results list. (moved from btnSearch_Click)
|
||||
{
|
||||
if (tabSearchTypes.SelectedTab != tabSearchTypes.Tabs[4])
|
||||
|
mschill marked this conversation as resolved
Outdated
mschill
commented
With working on technical debt - should avoid concatenating strings & use string interpolation instead. With working on technical debt - should avoid concatenating strings & use string interpolation instead.
|
||||
|
||||
Thinking this shouldn't be included for adding 1 blank line --- with the Tech debt project we will be changing every file in PROMS - thus we need to limit our changes to necessary ones to avoid unnecessary Merge Conflicts later on.