New and need a little guidance

May 18, 2011 at 3:53 PM

Hi 

I am building, actually have already built a search tool that uses FTS in MS SQL server 2008. So far so good, but im using an old version of the irony library.

I Downloaded this kit and fired up the samples. I'm using the google style text search to FTS query condition implementation.

In my existing project using the old irony lobrary I declare like so 

Dim _compiler As LanguageCompiler

This is however not valid for the latest version.

In my existing project, to perform a full text conversion its done in steps

1. instantiate the compiler
2. verify the text is valid 
3. perform the conversion

so in order this is how i used to use the irony library

 Dim root As AstNode = _compiler.Parse(FriendlySrchString.ToLower())
 If Not CheckParseErrors() Then
     Return Nothing
 End If
'build the full text search condition 
 ftString = SearchGrammar.ConvertQuery(root, SearchGrammar.TermType.Inflectional)

Where CheckParserErrors looked like this

 Private Function CheckParseErrors() As Boolean
        If _compiler.Context.Errors.Count = 0 Then
            Return True
        End If
        Dim errs As String = "Errors: " & vbCr & vbLf
        For Each err As SyntaxError In _compiler.Context.Errors
            errs += err.ToString() & vbCr & vbLf
        Next
        priErrors.AppendLine(errs)
        Return False
    End Function

I cannot seem to work out how to do this using the new irony library, nor can I find any documentation on the subject to help.

Look forward to someone pointing me in the right direction

regards
A
Coordinator
May 18, 2011 at 5:46 PM

SearchGrammar is in Samples project that comes with Irony - it is an updated and improved version.

Look at RunSample method in it, or Grammar.RunSample

May 18, 2011 at 6:12 PM

I think I have 99% completed the move from the old version to the new. I am missing one thing that maybe someone else can provide.

Here is how I am using the "FullTextSearchQueryConverter" found in the samples of the latest kit.

When i am using this in my application i have a few class wide variables

    Private _grammar As SearchGrammar
    Private _parser As Irony.Parsing.Parser
    Private _compilerContext As ParsingContext
    Private _parseTree As ParseTree
    Private priErrors As New StringBuilder

When I instatiate my class I load the SearchGrammer implementation into ivory (the 1% I havn't completed is at this point)

    Public Sub New()
        _grammar = New SearchGrammar
        _parser = New Parser(_grammar)
        _compilerContext = New ParsingContext(_parser)
        _parseTree = Nothing
        _parser.Context.SetOption(ParseOptions.TraceParser, True)

        'Dim errors As StringSet = _compiler.Parser.GetErrors
        'If (errors.Count > 0) Then
        '    Throw New Exception("SearchGrammar contains errors. Investigate using GrammarExplorer.\r\n" + errors.ToString())
        'End If
    End Sub

So the class is instantiated, the Grammer implementation loaded into ivory but the check to see if there were any errors in the Grammer is no longer in since I cant figure out how to check !

ok so finally we want to use it in any method in our class we can do this

        If Not String.IsNullOrEmpty(FriendlySrchString) Then
            _parser.Parse(FriendlySrchString)
            _parseTree = _parser.Context.CurrentParseTree

            If Not CheckParseErrors() Then
                Return Nothing
            End If
            'build the full text search condition 
            ftString = SearchGrammar.ConvertQuery(_parseTree.Root)
        End If

This is the error check function

    Private Function CheckParseErrors() As Boolean
        If _parseTree Is Nothing OrElse _parseTree.ParserMessages.Count = 0 Then
            Return True
        End If
        Dim errs As String = "Errors: " & vbCr & vbLf
        For Each err As Irony.Parsing.ParserMessage In _parseTree.ParserMessages
            errs = err.Location.ToString() & "Error: " & err.ToString() & "Parser State: " & err.ParserState.ToString()
        Next

        priErrors.AppendLine(errs)
        Return False
    End Function

Hope this helps anyone trying to do the same thing

cheers

A