alirezanet/Gridify

Support EF.Functions.FreeText

sebdm opened this issue ยท 10 comments

sebdm commented

I'd like free text searches to (optionally) be able to use EF.Functions.FreeText rather than a LIKE with wildcards. This would greatly improve the performance of free text searches with wildcards on both sides of the search string.

Hi,
To add this feature first we need to answer a few questions.

  1. How should we optionally switch between FreeText and the normal Contains method (Like)?
  2. Should we drop Dotnet Framework EF6 support?
  3. Because gridify is not limited to a specific database, do all databases or EF core providers support this function?
  4. How much do we gain a performance boost, is that worth the effort?

I'll do a research about this later, feel free to answer these questions if you already have the answers.

Thank you for the feedback

support EF.Property like x=> EF.Property<string>(x,\"Name\") == \"Ford\"

is it possible ? @alirezanet

support EF.Property like x=> EF.Property<string>(x,\"Name\") == \"Ford\"

is it possible ? @alirezanet

Yes, kind of...
This idea to support EF functions can solve a lot of problems, but implementing this is not so simple, because it can cause breaking changes in other gridify features. (the main problem is replacing gridify operators with ef function)

I will check it out later to see what can I do,

Hi,
Check out v2.6.0 and the new CustomOperator feature.

e.g

   internal class FreeTextOperator : IGridifyOperator
   {
      public string GetOperator() => "#=";

      public Expression<OperatorParameter> OperatorHandler()
      {
         return (prop, value) => EF.Functions.FreeText(prop, value.ToString());
      }
   }

   [Fact]
   public void ApplyFiltering_EFFunction_FreeTextOperator()
   {
      // Arrange
      GridifyGlobalConfiguration.CustomOperators.Register(new FreeTextOperator());
      var expected = _dbContext.Users.Where(q => EF.Functions.FreeText(q.Name, "test")).ToQueryString();

      // Act
      var actual = _dbContext.Users.ApplyFiltering("name #= test").ToQueryString();

      // Assert
      Assert.Equal(expected, actual);
   }

I would highly appreciate your feedback

cool ~~

I really like this feature! It adds a lot of flexibility

What should I do if I want to support EfCore's shadow property? like x=> EF.Property<string>(x,\"Name\") == \"Ford\" @alirezanet

Hi @Nokecy
I think having an operator for shadow properties doesn't make sense, It should be supported via GridifyMapper.
Open a new issue I'll look into this if the below example didn't work.

e.g

var mapper = new GridifyMapper<User>()
   .AddMap("shadow1", (User q) => EF.Property<string>(q, "shadow1"));  

use var mapper = new GridifyMapper<User>(true).AddMap("shadow1", q => EF.Property<string>((User)q, "shadow1"),v=>v); is work