Vidyano Documentation
HomepageDemo
  • Vidyano Documentation
  • Vidyano v6 (.NET 8.0 based)
    • Getting started
    • Documentation
      • Courier Feature
      • Managing User Secrets
      • Vidyano.Core
      • Icons
      • Reports
      • Grids
        • Grouping
      • Instant Search
      • Verbose Logs
        • Storage Provider
      • SourceGenerators
    • Migrating from v5.x
      • Migrating an existing Vidyano v5 project
      • Migration scripts for v5 Repository database
  • Release Notes
    • Client
      • 3.0
      • 2.0.0
    • Service
      • 6.0
      • Previous
        • 5.45.0+26864bd
        • 5.44.0+6e65421
        • 5.40.2+2a48896
        • 5.39.1+f04e696
        • 5.38.3+a697611
        • 5.37.1+3fd7ebea
        • 5.36.0+5338103
        • 5.35.5+2316022
        • 5.34.3+d278982
        • 5.33.1+12ad63a
        • 5.32.1+0c41761
        • 5.31.2+c8aabb2
        • 5.30.0+530afaf
        • 5.29.3+30608c3
        • 5.28.2+bc49431
        • 5.27.0+6b9495e
        • 5.26.2+bccf416
        • 5.25.3+8224b3b
        • 5.24.0+a20f7c
        • 5.23.0+9b8b99
        • 5.22.1+557c11
        • 5.21.1+923828
        • 5.20.0+95f4d1
        • 5.19.0+0964f9
        • 5.18.0+de3495
        • 5.17.0+aaa255
        • 5.16.0+aae2a8
        • 5.15.2+5ed89a
        • 5.14.1+ec0dbd
        • 5.13.1+c8fdb1
        • 5.12.0+66cbb5
        • 5.11.1+d7647c
        • 5.10.2+a3acd1
        • 5.9.0+68a51e
        • 5.8.1+67bcab
        • 5.8.0+aab7d8
        • 5.7.1+554316
        • 5.6.4+151e2e
        • 5.1.60401.4035
  • Legacy v5.x
    • Installation (Legacy)
    • Tutorial 1: Your first application (Legacy)
    • Computed attributes
    • Actions
      • Labels
      • Actions classes
    • Security
      • Architecture
      • Allow user registration
      • Forgot password
      • Best Practices
      • Azure AD SAML based Sign-on
      • SCIM 2.0 Service Provider
    • Overriding Vidyano Settings
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Vidyano v6 (.NET 8.0 based)
  2. Documentation

Instant Search

Vidyano has the ability to set any Query as Global Search which allows the end users to use a simple text search in the menu that will search through all the queries and shows those queries that returned results (or errors). This has given us an easy way to provide this kind of functionality to users.

The only problem has always been performance, the application will launch a full text search for all columns on all the queries that are defined as global search so the total time to give results has always been in the 1-10 seconds range.

Instant search has been written from the ground up with performance as the number one priority.

Example

Instant search is implemented as an advanced feature, it is up to the developer to keep the total processing time as low as possible (recommended <100ms).

public sealed class MyCRMAdvanced : Advanced
{
    public MyCRMAdvanced()
    {
        InstantSearchDelay = TimeSpan.FromMilliseconds(200d);
    }

    public override TimeSpan? GetInstantSearchDelayForUser(IUser user)
    {
        if (user.IsMemberOf("CantUseInstantSearch"))
            return null;

        // Fallback to default
        return base.GetInstantSearchDelayForUser(user);
    }

    public override void HandleInstantSearch(InstantSearchArgs args)
    {
        args.MaxResults = 12; // Defaults to 15 results

        var user = Manager.Current.User;
        if (user.IsMemberOf("Administrators"))
        {
            // Some built-in searches specific for application admins
            args.AddPersistentObjects();
            args.AddUsers();
        }

        using (var context = new MyCRMEntityModelContainer())
        {
            var search = args.Search; // The search query from the end user

            // The first parameter specifies the PO type name
            args.AddRange("Customer", context.Customers
                .Where(it => it.FirstName.Contains(search) || it.LastName.Contains(search))
                .Select(it => new
                {
                    ID = it.CustomerID,
                    it.FirstName,
                    it.LastName
                })
                .Take(4)
                .AsEnumerable()
                .Select(it => new InstantResult(it.ID.ToServiceString(), it.FirstName + " " + it.LastName)));
            // The instant result determines the ObjectId and Breadcrumb to display the result in the menu

            // For single property lookups we have an easy helper method
            args.AddRange("Product", context.Products, it => it.ProductID, it => it.Name, 4); // 4 max results instead of the default 5
            args.AddRange("ProductCategory", context.ProductCategories, it => it.ProductCategoryID, it => it.Name, 4);

            int number;
            if (int.TryParse(search, out number)) // We can skip certain tables if the search input doesn't match the expected input
            {
                args.AddRange("SalesOrderHeader", context.SalesOrderHeaders
                    .Where(it => it.SalesOrderNumber.Contains(search))
                    .Select(it => new
                    {
                        ID = it.SalesOrderID,
                        it.SalesOrderNumber
                    })
                    .Take(4)
                    .AsEnumerable()
                    .Select(it => new InstantResult(it.ID.ToServiceString(), it.SalesOrderNumber, it.SalesOrderNumber.IndexOf(search, StringComparison.OrdinalIgnoreCase) - 2)));
                // The SalesOrderNumber column is a computed column ("SO" + ID) so we decrement the score by 2 for better ranking results
            }
        }
    }
}

PreviousGroupingNextVerbose Logs

Last updated 2 months ago

Was this helpful?

Which will give the following experience to the end user, as seen on

demo.vidyano.com