There are a number of ways of extending query execution
Property functions provide the most convenient way of adding custom code to the graph matching process for specific predicates. The free text search capabilities, using Lucene, are done this way.
To replace all SPARQL basic graph pattern (BGP) matching in a query, an application can enhance the main query engine and intercept the BGP matching process.
BGP matching proceeds a number of "stages". Each stage matches a subset of the basic graph pattern.
The normal BGP matching is a single stage that finds all bindings for variables for a pattern.
@@stages
The query optimizer prefers execution plans that pass the results from previous patterns into later stages. This enables maximal indexing of pattern matching.
@@Somewhere: Bindings / Query Iterators
Query optimization, input and substitution