Click or drag to resize

How To implement a custom file parser

This article explains how to implement a new parser to be used by the Full-Text indexer timer job.

Introduction
Note Note
Be sure to have read this article before reading this one. It explains how to install the Full-Text on your Packflow site and how it is working.

To enable file search in FileHolder fields, Packflow must index the files' content first.

Currently, it handles Text, Word and Excel documents.

Adding a custom parser to your application allows you to override or extend these capabilities.

Implementation

This implementation is easy: just add a new class to your application's project inheriting from the FileParser class.

Then override the following two methods:

C#
namespace Packflow.YourApplication
{
    public class CustomParser : Packflow.Core.FileParsing.FileParser
    {
        public override bool IsFileCompatible(System.IO.Stream file, string fileName)
        {
            return fileName.EndsWith(".txt");
        }

        public override string ParseFile(System.IO.Stream file, string separator)
        {
            using (StreamReader reader = new StreamReader(file))
            {
                String content = reader.ReadToEnd();

                return content;
            }
        }
    }
}

The first method identifies the scope of your parser. This also allows to take the control of the parsing of a file normally handled by our generic parsers.

Please note that this parser will only be called for files hosted in this specific application.

The second one effectively parses the file.

The separator parameter can be used to represent new paragraphs, sentences, page breaks, cell separator or equivalent.

See Also

Other Resources