Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js
Simple dialog using CSMLStatic
Environment: VC6 SP5, Win9x, WinNT, Win2000, WinXP
After deciding exactly what I wanted, I implemented the CSMLDoc and CSMLStatic classes. CSMLDoc is a simple standalone class used for parsing and storing documents that use an "HTML like" markup language called SML (Small Markup Language). CSMLStatic is a CRichEditCtrl derived class that handles the display of formatted text while preventing any user action with the document (except for scrolling through large documents such as an EULA).
Since the CSMLStatic control maintains it's own CSMLDoc object, the CSMLStatic class is the only item of interest (although you might want to look at CSMLDoc for your own purposes). The CSMLStatic class works on both a CSMLDoc as well as plain text and allows both types of text to be provided through both constructors and methods.
Example of an SML document
Since the source code archive contains a help document explaining how SML works, I will only touch upon a few of the features here.
SML works on the basis of text groups. A text group is everything between break (<br>) formatting tags. Every time a break formatting tag is encountered a new text group is created. When a new text group is started, it inherits all of the styling attributes the previous group had. This includes, but it not limited to typeface, bold or italic styles, point size, justification and color. One special thing to note when dealing with text groups; whenever one of the justification tags (<center>, <right>, <left>) are encountered, the last one used in the text group is the ONLY one applied to that text group.
The following example was used in the dialog pictured above:
<body face=DEFAULT_GUI_FONT bgcolor=COLOR_BTNFACE> <center> <h4 color="800000"><u>Server Information</u></h> </center> <br> <br> <b><u>User Information:</u></b> <br><over> This is where you will enter your real name, email address, and other user identifiable information. </over><br> <br> <b><u>News Server:</u></b> <br> This is where you enter the information about your Usenet news server.<br> <br> <b><u>Email Server:</u></b> <br> If you wish to reply to usenet posters via email, information about your outgoing SMTP e-mail server is required. This is where that information is entered. </body>
The <body> command tag is used to indicate the entire body of the text. Everything that calls inside of the <body> tag will be used in the document. All other text that falls outside of this tag is considered to be a comment.
The <font> command tag is used to indicate a change in the typeface for a block of text. When the <font> tag is applied, all text between <font> and </font> will be displayed in the specified font and style attributes.
<center> and </center> : Begin and end center justification.
<left> and </left> : Begin and end left justification.
<right> and </right> : Begin and end right justification.
<b> and </b> : Begin and end bold style formatting.
<u> and </u> : Begin and end underline style formatting.
<i> and </i> : Begin and end italic style formatting.
<br> : Begin a new text block.
<h1>,<h2>, <h3>, <h4>, <h5>, and </h> : Header/Font point size
Constructing a CSMLStatic object
CSMLStatic provides three methods for setting the text to display:
BOOL SetSMLText(UINT nID);
This method accepts an SML formatted document in the form of a resource ID. The resource MUST be created with the custom type "SMLDOC" or the CSMLDoc manager will not be able to locate it.
BOOL SetSMLText(LPCSTR stream);
This method accepts an SML formatted document in the form of a null terminated buffer.
BOOL SetPlainText(LPCSTR lpszText);
This method accepts a buffer containing plain text. No parsing is done on text of this type.
- Create a resource of type "SMLDOC" and insert the example code.
- Create a dialog containing a rich edit control.
- Using the class wizard, create a CDialog derived class that is associated with the dialog.
- Using the class wizard, associate a variable of type CRichEditCtrl with the rich edit control in the dialog and name is m_SMLText.
- In the dialog class, change the CRichEditCtrl to a CSMLStatic class and make sure the SMLStatic.h file is included.
- Using the class wizard, add a handler for the WM_INITDIALOG message.
- In the OnInitDialog() method, add the following line
m_SMLText.SetSMLText(resID);Make sure you change resID to the ID of the SMLDOC resource you created.