Full-text search database and entity implementation, full-text search entity

Source: Internet
Author: User

Full-text search database and entity implementation, full-text search entity

In daily business scenarios, it is not clear that each type of data requires structured storage. In many cases, only the data of a form can be saved. As for subsequent queries, in addition to the form ID, full-text retrieval is more required.

At present, we have a lot of processes, mainly working in the following ways: at startup, we get the corresponding data from the primary data to the transaction data. After processing in all stages of the process, at the end of the process, the transaction data is written back to the primary data. In this process, except for the process, there are few opportunities to query transaction data (except for full-text retrieval ). Therefore, it is of little significance to design a database for a large amount of transaction data in the process.

In addition to the primary key RESOURCE_ID, the most critical field is the XML_CONTENT field, which stores the content of the business entity as an xml data type. The reason for using the xml type instead of the binary or pure string type is to retain the possibility of creating an index for the content in the xml field.

It is not enough to have only a table structure. For your convenience, we have designed the data entity and data access Adapter for this data structure ). In addition, we have defined a set of attributes to help you convert objects into xml format .. The xml serialization mechanism of NetFramework is easy to use because dynamic compilation is required.

Let's take a look at the definition of the base class of this data entity:

[Serializable] [XmlRootMapping ("GenericFormData")] [XElementSerializable] [ORTableMapping ("WF. GENERIC_FORM_DATA ")] [ObjectCompare (" ID ")] public class GenericFormData: WorkflowObjectBase {[Description (" no. ")] [XmlObjectMapping] [ORFieldMapping (" RESOURCE_ID ", primaryKey = true)] public override string ID {get; set;} [Description ("title")] [XmlObjectMapping] [ORFieldMapping ("SUBJECT")] [StringLengthValidator (1,255, messageTemplate = "Enter the title and the length must be less than 255 characters")] public override string Subject {get; set;} private IUser _ Creator = null; [SubClassORFieldMapping ("ID", "CREATOR_ID", IsNullable = false)] [SubClassORFieldMapping ("DisplayName", "CREATOR_NAME", IsNullable = false)] [SubClassType (typeof (OguUser)] public virtual IUser Creator {get {return this. _ Creator;} set {this. _ Creator = (IUser) OguBase. createWrapperObject (value);} [Description ("Creation Time")] [XmlObjectMapping] [ORFieldMapping ("CREATE_TIME")] [SqlBehavior (BindingFlags = ClauseBindingFlags. all, DefaultExpression = "getdate ()")] public virtual DateTime CreateTime {get; set;} [Description ("XML")] [ORFieldMapping ("XML_CONTENT")] public virtual string XmlContent {get; set;} [ORFieldMapping ("SEARCH_CONTENT")] [Description ("search content")] public virtual string SearchContent {get; set ;}}

As you can see, it is not much different from the general data entity class, except there are several attributes such as XmlRootMapping and XmlObjectMapping to help serialize objects into xml.

To serialize GenericFormData to xml, you only need to call XmlHelper. SerializeObjectToXml (data.

To use this function, you only need to write a data entity derived from GenericFormData and an Adapter class derived from GenericFormDataAdapterBase <T, TCollection>.

Because SampleFormData is stored in xml fields, we can consider it unstructured without creating indexes. In the above example, its sub-object set SubData is also unstructured. In actual application scenarios, sub-objects are not necessarily unstructured, such as form comments and attachments. We need to reload the BeforeInnerUpdate, AfterInnerUpdate, or AfterLoad of the Adapter to process Sub-objects.

Sometimes, it is not necessary to load the primary object and sub-objects at the same time. For example, the primary object is used only in the list, while the form usually uses both the primary object and sub-object.

In this scenario, sub-objects are often loaded with delay.

Note that not all objects can be serialized according to the Xml serialization mechanism above, especially when cross object references are made, such common data cannot be easily retrieved as structured data. To alleviate this problem, we have set a SearchContent attribute on both GenericFormData and GenericFormRelativeData. This attribute corresponds to the full-text search field of SEARCH_CONTENT in the database table.

The application can put the text data you want to query in the SearchContent attribute and then query it:

select *from WF.GENERIC_FORM_RELATIVE_DATAwhere CONTAINS(SEARCH_CONTENT, '123'); 




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.