Description
Introduce a Parser interface to support different file types such as .txt, .html, .pdf, etc. This makes the engine extensible and ready for multi-format parsing.
Why
- Currently, the engine only supports parsing plain
.txt files.
- Introducing a common interface allows us to plug in support for other formats cleanly.
What to Add
- Define a
Parser interface with a method like Parse(path string) ([]string, error) that extracts indexable results.
- Refactor the existing
.txt parsing logic to implement this interface.
- Update the engine to use the interface instead of hardcoding
.txt logic.
- Introduce a parser factory that select parser based on file extension or file headers.
Example
type Parser interface {
Parse(path string) ([]string, error)
}
// Usage
parser := parserFactory.GetParser("file.html")
words, err := parser.Parse("file.html")
Description
Introduce a
Parserinterface to support different file types such as.txt,.html,.pdf, etc. This makes the engine extensible and ready for multi-format parsing.Why
.txtfiles.What to Add
Parserinterface with a method likeParse(path string) ([]string, error)that extracts indexable results..txtparsing logic to implement this interface..txtlogic.Example