Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchOptionsProcessor.Apply not correctly handling more than one "multiple term" search term #54

Open
JDMilne opened this issue Sep 8, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@JDMilne
Copy link

JDMilne commented Sep 8, 2020

First of all, thank you very much for your code. It allowed me to prototype something in hours as opposed to days (possibly weeks),

When more than one search columns contains multiple terms the search results are not being applied correctly. Take as an example my particular implementation where I allow searches by an individual's first and last name. My data set also included MaidenName, NickName, and MiddleName so the application automatically searches these other column as follows:

  • When the user searches on LastName the application also searches MaidenName.
  • When the user searched on FirstName, the application also searches on MiddleName and NickName.

Searching of these "other" columns is disabled,

My view model contains the following definitions for the LastName and FirstName columns:

[IncludeInReport(Order = 1)]
[JqueryDataTableColumn(Order = 3)]
[SearchableString(EntityProperty = "LastName,MaidenName")]
[Sortable(EntityProperty = "LastName", Default = true)]
[DisplayName("Last Name")]
public string LastName { get; set; }

[IncludeInReport(Order = 2)]
[JqueryDataTableColumn(Order = 4)]
[SearchableString(EntityProperty = "FirstName,MiddleName,NickName")]
[Sortable(EntityProperty = "FirstName", Default = true)]
[DisplayName("First Name")]
public string FirstName { get; set; }

Searching on either FirstName or LastName works exactly as expected. Searching on one of FirstName or LastName plus any number of other column that do not have multiple terms also works as expected. Searching on both LastName and FirstName, however, does not return the expected results.

Searching for LastName = "Smith" and FirstName = "Tony" results in the following search expression (copied directly from the query object in the debugger after SearchOptionsProcessor.Apply).

{IndividualSearch => ((True AndAlso ((False OrElse IndividualSearch.LastName.Trim().ToLower().Contains("smith".Trim().ToLower())) OrElse IndividualSearch.MaidenName.Trim().ToLower().Contains("smith".Trim().ToLower())))
AndAlso (((((False OrElse IndividualSearch.LastName.Trim().ToLower().Contains("smith".Trim().ToLower())) OrElse IndividualSearch.MaidenName.Trim().ToLower().Contains("smith".Trim().ToLower())) OrElse IndividualSearch.FirstName.Trim().ToLower().Contains("tony".Trim().ToLower())) OrElse IndividualSearch.MiddleName.Trim().ToLower().Contains("tony".Trim().ToLower())) OrElse IndividualSearch.NickName.Trim().ToLower().Contains("tony".Trim().ToLower())))}

As you can see in the search expression following "AndAlso" the filter expression for the FirstName columns (FirstName,MiddleName,NickName) also includes the LastName columns (LastName,MaidenName shown in bold above) which results in the FirstName search term being ignored.

I'm using:
Visual Studio 2019
dotnetcore 3.1
EntityFrameWorkCore.SQLServer 3.1.5
MS Edge

@JDMilne JDMilne added the bug Something isn't working label Sep 8, 2020
@JDMilne
Copy link
Author

JDMilne commented Sep 9, 2020

I've tested the following change. It seems to resolve the issue. subExpression needs to be reset for each encountered compound term.

2020-09-09_15h48_20

@fingers10
Copy link
Owner

@JDMilne Many thanks for posting the issue. Will look on this and get back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants