Howto create an apache module with a sphinxserver

I'm struggling to understand on how to set up Sphinx with Sparkle/XData as a Module.

I have implemented my backend as a XData Module on an apache server on linux. To do that I create a WebBrokerServer, then create a XDataServerModule, add Middleware to the XDataServerModule and finally add the XDataServerModule to the Dispatcher of the WebBrokerServer.
The actual endpoints implementation are added as Service Operations. This all works fine and I have no problem using this approach to build my backend functionality.

In the Documentation in the Reference Section I can only find TSphinxServer which is described as: The component that provides the HTTP Sphinx server, as a XData/Sparkle module. However I cannot use TSphinxServer like I would use a TXDataServerModule. I can find a TSphinxServerModule, but there is no information listed in the Reference about TSphinxServerModule. I'm scratching my head now, on how to make Sphinx Server work in a module compiled for apache on linux.

Any suggestion would be highly appreciated.

Hi @Putzich_Andreas, sorry for the delay in response. Let me try to help you.

In the Sparkle documentation, there is a topic about how to create an Apache module:
https://doc.tmssoftware.com/biz/sparkle/guide/server.html#apache-based-server

In step 4, it provides the code example where it adds the Sparkle module to the dispatcher:

  Server.Dispatcher.AddModule(TAnonymousServerModule.Create(
    'http://localhost/tms/hello',
    procedure(const C: THttpServerContext)
    begin
      C.Response.StatusCode := 200;
      C.Response.ContentType := 'text/html';
      C.Response.Close(TEncoding.UTF8.GetBytes('<h1>Hello, World!</h1>'));
    end
  ));

Of course, you will add the desired module to the dispatcher, in this example it's an anonymous module, but it can be a XData module (as you said, an instance of TXDataServerModule) or any other.

Those are objects of the "module layer" of Sparkle system. In more recent years, we added a "RAD layer", which are non-visual components that you can drop in the form and use them together to build a Sparkle server in an easier way than before.

Thus, there is not only TXDataServerModule now, but also a TXDataServer, which under the hood encapsulates the module.

And, as you said, there is a TSphinxServer and a TSphinxServerModule. Indeed, the "RAD layer" is easier to use and more straightforward, while the "Module layer" is non-visual, code-only and sometimes more complex to setup, but also more flexible. It's a fallback in case the "RAD layer" is not flexible enough.

Again, indeed, as you noted, the way to build a Sparkle server using an Apache module only uses the "Module layer". Then, in case you have a component of the "RAD layer" and want to use the "Module layer", you can simply use the method CreateModule from the component. This will create an instance of the "Module layer" with everything correctly setup based on the properties and events configured in the "RAD layer".

In summary, this is what you should do to add the module to dispatcher from an existing TSphinxServer instance you have previously configured:

  Server.Dispatcher.AddModule(SphinxServer1.CreateModule);

I hope this helps.