Skip to content

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

@JDMilne

Description

@JDMilne

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions