zoukankan      html  css  js  c++  java
  • How to: Make the FullTextSearch Action Search Within Required Properties 如何:使用全文搜索按钮在需要的属性中进行全文搜索

    This topic demonstrates how to customize the FullTextSearch Action's behavior. This Action filters the current List View by setting criteria for its collection data source. According to the criteria, the object's properties must contain individual words from the word combination typed by an end-user. Reference several techniques on how to modify the Action's behavior, in the FilterController.FullTextFilterAction member description. Here, you will see how to use one of these techniques. We will specify a custom list of the properties that will be used to generate the filter criterion for the current List View.

    本主题演示如何自定义全文搜索操作的行为。此操作通过为其集合数据源设置条件来筛选当前列表视图。根据条件,对象的属性必须包含最终用户键入的单词组合中的单个单词。在筛选器控制器.FullTextFilterAction 成员描述中,引用有关如何修改操作行为的几种技术。在这里,您将看到如何使用这些技术之一。我们将指定将用于生成当前列表视图的筛选条件的属性的自定义列表。

    Tip 提示
    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E231
    完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E231

    .

    To specify a custom list of the properties that will be used in the search, the Filter Controller, which contains the FullTextSearch Action, exposes the FilterController.CustomGetFullTextSearchProperties event. To handle this event, we will add a new View Controller, and subscribe to its Controller.Activated event.

    要指定将在搜索中使用的属性的自定义列表,包含"完全文本搜索"操作的筛选器控制器将公开筛选器控制器。为了处理此事件,我们将添加新的视图控制器,并订阅其控制器.激活事件。

    In the CustomGetFullTextSearchProperties event handler, assign a list of any required properties to the CustomGetFullTextSearchPropertiesEventArgs.Properties parameter. In addition, set the CustomGetFullTextSearchPropertiesEventArgs.Handled parameter to true, to indicate that other properties must not be added to the list. In this example, we will add only the "LastName" property of the Person class. So, we will activate our Controller for Person List Views only. The MyFilterController is shown below:

    在"自定义获取全文搜索属性"事件处理程序中,将任何必需属性的列表分配给"自定义获取全文搜索属性事件"参数。此外,将"自定义获取全文搜索属性事件"参数设置为 true,以指示不得将其他属性添加到列表中。在此示例中,我们将仅添加 Person 类的"姓氏"属性。因此,我们将仅激活人员列表视图的控制器。"我的过滤器控制器"如下所示:

    using System;
    using System.Collections.Generic;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.SystemModule;
    //...
    public partial class MyFilterController : ViewController {
        public MyFilterController() {
            InitializeComponent();
            RegisterActions(components);
            this.TargetObjectType = typeof(DevExpress.Persistent.BaseImpl.Person);
        }
        private void MyFilterController_Activated(object sender, EventArgs e) {
            FilterController standardFilterController = Frame.GetController<FilterController>();
            if(standardFilterController != null) {
                standardFilterController.CustomGetFullTextSearchProperties += new 
    EventHandler<CustomGetFullTextSearchPropertiesEventArgs>(standardFilterController_CustomGetFullTextSearchProperties);
            }
        }
        void standardFilterController_CustomGetFullTextSearchProperties(object sender, 
    CustomGetFullTextSearchPropertiesEventArgs e) {
            foreach(string property in GetFullTextSearchProperties()) {
                e.Properties.Add(property);
            }
            e.Handled = true;
        }
        private List<string> GetFullTextSearchProperties() {
            List<string> searchProperties = new List<string>();
            searchProperties.Add("LastName");
            return searchProperties;
        }
    }

    The following image demonstrate that the MyFilterController works:

    下图演示了"我的过滤器控制器"的工作原理:

    FilterByTextAction_CustomGetFullTextSearchProperties

    Filtration may be impossible in case one or more property is of a particular type. For example, in Server mode, filtering by properties of the DateTimetype, which are stored in a database as columns of the datetime date type, may cause exceptions. To avoid them, ensure that the inputed text can be converted to the corresponding type and this converted value is within the acceptable range, and exclude a property from the default filter list if necessary. The following code demonstrates the Controller implementing this logic.

    如果一个或多个属性是特定类型的,则过滤可能是不可能的。例如,在服务器模式下,按 DateTimetype 的属性进行筛选(这些属性作为日期日期类型的列存储在数据库中)可能会导致异常。为了避免它们,请确保输入的文本可以转换为相应的类型,并且此转换值在可接受的范围内,并在必要时从默认筛选器列表中排除属性。以下代码演示了实现此逻辑的控制器。

    using System;
    using System.Collections.Generic;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.SystemModule;
    using DevExpress.ExpressApp.DC;
    using DevExpress.Data.Summary;
    using System.Data.SqlTypes;
    //...
    public class MyFilterController : ViewController<ListView> {
        private static readonly DateTime minDate;
        private static readonly DateTime maxDate;
        static MyFilterController() {
            minDate = (DateTime)SqlDateTime.MinValue;
            maxDate = (DateTime)SqlDateTime.MaxValue;
        }
        private Boolean CanFilter(string propertyName, string filterText) {
            IMemberInfo memberInfo = View.ObjectTypeInfo.FindMember(propertyName);
            if (SummaryItemTypeHelper.IsDateTime(memberInfo.MemberType)) {
                DateTime? convertedFilter = null;
                try {
                    convertedFilter = Convert.ChangeType(filterText, typeof(DateTime)) as DateTime?;
                }
                catch {
                    return false;
                }
                if (convertedFilter.HasValue) {
                    if ((convertedFilter.Value < minDate) || (convertedFilter.Value > maxDate)) {
                        return false;
                    }
                }
            }
            return true;
        }
        private ICollection<string> GetProcessedRequiredProperties(ICollection<string> searchProperties, 
    string filterText) {
            List<string> result = new List<string>();
            foreach (string propertyName in searchProperties) {
               if (CanFilter(propertyName, filterText)) {
                   result.Add(propertyName);
                }
            }
            return result;
        }
        private void FilterController_CustomGetFullTextSearchProperties(object sender, 
    CustomGetFullTextSearchPropertiesEventArgs e) {
            string filterText = ((FilterController)sender).FullTextFilterAction.Value as string;
            if (!string.IsNullOrEmpty(filterText)) {
                ICollection<string> searchProperties = 
    GetProcessedRequiredProperties(((FilterController)sender).GetFullTextSearchProperties(), filterText);
                e.Properties.AddRange(searchProperties);
                e.Handled = true;
            }
        }
        protected override void OnActivated() {
            base.OnActivated();
            FilterController filterController = Frame.GetController<FilterController>();
            if (filterController != null) {
                filterController.CustomGetFullTextSearchProperties += 
    FilterController_CustomGetFullTextSearchProperties;
            }
        }
        protected override void OnDeactivated() {
            FilterController filterController = Frame.GetController<FilterController>();
            if (filterController != null) {
                filterController.CustomGetFullTextSearchProperties -= 
    FilterController_CustomGetFullTextSearchProperties;
            }
            base.OnDeactivated();
        }
    }
  • 相关阅读:
    获取汉字信息(结合正则就可以得到想要的详细啦)
    压缩图片(递归结合pillow)通过改变图片尺寸实现;tinify 需要付费
    实现两个视频同时播放,利用到opencv模块 (线程进程开启)
    切换pip下载源头
    516. 最长回文子序列
    87.扰乱字符串
    Maximum Likelihood ML
    数组右边第一个比当前元素大的数
    4. 寻找两个正序数组的中位数
    min-hash
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Make-the-FullTextSearch-Action-Search-Within-Required-Properties.html
Copyright © 2011-2022 走看看