For a long time, ask the user who recently added Sphinx to our application using the Zend Framework.
Note on Propel and MVC
What I noticed during the last few months of development is that I would like for me to take advantage of the more immediate advantage of the Propel abstraction. As you probably know, Propel creates base classes for ORM, as well as empty classes, simply extending the base ones.
Currently, many business logics rely on separate models, when exactly the same logic can simply be implemented as methods in extended Propel classes.
You should use the same approach to implement Sphinx search. Try abstracting it using the extended ORM classes.
Sphinx Notes
Create views to simplify indexing : Sphinx does not work well with advanced subqueries and is easily confused by MySQL functions. Try abstracting the data you want to index so that the common SQL is simple as SELECT id, field1, field2, field3 FROM MyView. This is especially useful when you can associate each Sphinx document with a user account or other foreign foreign key relationship that is nontrivial.
Sphinx can only index UINT . This is probably not a problem in most cases, but you cannot use UUIDs or negative numbers to work with various odd database structures.
Avoid duplicate document id . In each Sphinx index, each document identifier must be unique. Say you want to make type A objects searchable, but you want to find object A by searching for tags, comments, and geographic locations. The right way to do this with Sphinx is to make index A with all the metadata about the object and separate indexes for comments, tags, and geographical locations and make sure you put the sql_attr_uint attribute to display back in object A , and then find out what get in your code.
Use the latest version of Sphinx : Sphinx is in rapid development, and distributions such as Debian have a rather outdated version in the repositories. If possible, and you have time to ensure stability, compile it from the source (Sphinx has several dependencies, so in most cases this will not be a problem). In addition, the PHP library code has fault tolerance, which prevents client code from talking to the too recent version of the Sphinx search daemon.
Sphinx degree . After you perform the search, you still need to get the relevant information from the database, since Sphinx will only provide you with identifiers for matching records. In some situations, it would be wise to use something like:
$ a = AQuery :: create () -> findByPk (ID_FROM_SPHINX)
in the foreach loop. But in some cases, it may be too inefficient to rely on ORM to get a list, especially if you just want to list multiple columns, for example. searching results. Then, instead, you can use custom optimized SQL selections to get information (can be done in Propel classes).
source share