jaimz22 / DoctrineFullTextPostrgres

A simple to use set of database types, and annotations to use postgresql's full text search engine with doctrine
17 stars 21 forks source link

Useless when there are multiple tsvector fields for the same text field #8

Open teohhanhui opened 8 years ago

teohhanhui commented 8 years ago

The first tsvector field that contains the field is used: https://github.com/jaimz22/DoctrineFullTextPostrgres/blob/86bca023c972d0f08988c3c912bb6d4c77c400bf/src/ORM/Query/AST/Functions/TSFunction.php#L59-L62

To fix this, we have to allow the user to directly specify the tsvector field to use, instead of using the underlying field in the query.

Example:

tsquery(a.titleAndBodyFts, :searchQuery)
jaimz22 commented 8 years ago

sorry, can you elaborate?

teohhanhui commented 8 years ago

Using the example in the README:

class Article
{
    /**
     * @var string
     * @Column(name="title", type="string", nullable=false)
     */
    private $title;

    /**
     * @TsVector(name="title_fts", fields={"title"})
     */
    private $titleFTS;

    /**
     * @var string
     * @Column(name="body", type="text", nullable=true)
     */
    private $body;

    /**
     * @TsVector(name="body_fts", fields={"body"})
     */
    private $bodyFTS;

    /**
     * @TsVector(name="title_and_body_fts", fields={"title", "body"})
     */
    private $titleAndBodyFTS;
}

We can never do the query against title_and_body_fts with the current design.

tsquery(a.title, :searchQuery) would use title_fts, and tsquery(a.body, :searchQuery) would use body_fts.

teohhanhui commented 8 years ago

I propose removing the text field -> tsvector field rewriting magic in the query.