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

Text search on document not returning any results, when desired value is an enum and required parameter is not exact match(Case Insensitive) #1327

Open
tonykaralis opened this issue Jul 30, 2019 · 0 comments
Assignees
Milestone

Comments

@tonykaralis
Copy link
Contributor

tonykaralis commented Jul 30, 2019

@oskardudycz as promised.
When running text search against documents, exact and partial words will return results but only when in string properties. Enums must be an exact match, although the case does not matter.

I would have thought that when searching a document the enums would be treated as strings and therefore partial words would be enough to return a result.

Example

  • Property value in database: PricedIdeaScreening
  • Search parameter: Priced
    This does not work when the value is of type enum, but does work on string properties.

Running PGSQL 11.1

Store options

            var options = new StoreOptions
            {             
                AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate,
                DatabaseSchemaName = schema,
                PLV8Enabled = false
            };
            options.DdlRules.TableCreation = CreationStyle.CreateIfNotExists;

            options.Serializer(SetupCustomSerializer(customBinder));

            options.Schema.For<Team>();
            options.Schema.For<Country>();
            options.Schema.For<Tool>().FullTextIndex();
            
            ....
    
            options.Schema.For<IQuestionData>().AddSubClassHierarchy(DocumentStoreConfigExtensions.GetQuestionDataTypes());          

            options.Connection(_connectionString);
            return options;
            }

Sample Json

{
    "Id": "c6ea70b2-28d9-4190-94b4-c7a79ca23a5a",
    "$id": "376",
    "Name": "Idea Screening",
    "Type": "PricedIdeaScreening",
    "$type": "Tool",
    "IsHidden": false,
    "Description": null,
    "BoostOptionIds": [
        "a1dfa0bc-28d2-4968-8783-c1191d6ac716",
        "42646489-26bb-4e00-9eba-e4a95806f008",
        "c0e89277-948d-4d41-a3d6-d79ec28c41f0",
        "4d9ad3d6-c895-419e-b078-91934a72c1de",
        "09722847-da65-4ec2-83a6-fe2900c58b64",
        "4eb7e1e7-68c4-4e5a-b94f-02adab84a82f",
        "9e1466a0-b76b-479e-aeab-5f6f0476ecb2"
    ]
}

Property and value in question: Type = PricedIdeaScreening.

**Tested Queries using .Search() and .PhraseSearch() **
Fails

var searchParam = "Priced";
_dbSession.Query<Tool>().Where(x => x.Search(searchPram)).ToListAsync();

Fails

var searchParam = "priced";
_dbSession.Query<Tool>().Where(x => x.Search(searchPram)).ToListAsync();

Passes

var searchParam = "PricedIdeaScreening";
_dbSession.Query<Tool>().Where(x => x.Search(searchPram)).ToListAsync();

Passes

var searchParam = "pricedideascreening";
_dbSession.Query<Tool>().Where(x => x.Search(searchPram)).ToListAsync();

Edit:
Adding my custom serialization:

 /// <summary>
        /// Customizes the build in JsonSerializer
        /// </summary>
        /// <param name="customBinder"></param>
        /// <returns></returns>
        private Marten.Services.JsonNetSerializer SetupCustomSerializer(ISerializationBinder customBinder = null)
        {
            var customJson = new Marten.Services.JsonNetSerializer();
            customJson.Customize(o =>
            {
                if (customBinder != null)
                {
                    o.SerializationBinder = customBinder;
                }

                o.Formatting = Formatting.Indented;
                o.TypeNameHandling = TypeNameHandling.Objects;
                o.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
                o.ObjectCreationHandling = ObjectCreationHandling.Auto;
                o.DateFormatHandling = DateFormatHandling.IsoDateFormat;
            });
            //this lets us do text searchs on enums
            customJson.EnumStorage = EnumStorage.AsString;

            return customJson;
        }

Let me know if you need any other bits.

@oskardudycz oskardudycz self-assigned this Jul 31, 2019
@jeremydmiller jeremydmiller added this to the 7.0.0 milestone Sep 8, 2023
@jeremydmiller jeremydmiller modified the milestones: 7.0.0, 7.0.1 Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants