Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about searching against multiple attributes with highlight #336

Open
zosiu opened this issue Nov 5, 2016 · 7 comments
Open

Question about searching against multiple attributes with highlight #336

zosiu opened this issue Nov 5, 2016 · 7 comments

Comments

@zosiu
Copy link

zosiu commented Nov 5, 2016

I have the following pg_search_scope on my model:

pg_search_scope :search_full_text,
                against: { title: 'A',
                           description: 'B' },
                using: { tsearch: { dictionary: 'english',
                                    prefix: true,
                                    any_word: true,
                                    tsvector_column: 'tsv',
                                    highlight: { start_sel: '<strong>',
                                                 stop_sel: '</strong>' } } }

I would like to return the full title and description, with both of them including the highlights, is this possible?

@dhruvasagar
Copy link

I would also like to see there to be pg_search_#{field}_highlight equivalent for each field as opposed to highlighting them all after concatenation.

Is there a way to do this right now ?

@kwent
Copy link

kwent commented Apr 11, 2018

This is still an issue :(

@jcostello
Copy link

Still and issue

@jbakerdev
Copy link

This would be very helpful. Is there a recommended workaround for searching multiple columns and then displaying results as individual highlighted fields?

@andrepcg
Copy link

Any updates on this?

@rhymes
Copy link

rhymes commented Apr 27, 2021

I think this is due to the fact that it's using a tsvector column, so the highlight is constructed on such column, as pg_search is not actually marking highlights on the other two columns, they're not present in the query at all.

If you examine the SQL query, you'll see something akin to:

SELECT ((ts_headline('simple', (coalesce("articles"."tsv"::text, '')), (to_tsquery('simple', ''' ' || unaccent('test') || ' ''' || ':*')), 'StartSel = "<mark>", StopSel = "</mark>", MaxFragments = 2'))) AS pg_search_highlight,
       articles.*
FROM "articles"
INNER JOIN
    (SELECT "articles"."id" AS pg_search_id,
            (ts_rank(("articles"."tsv"), (to_tsquery('simple', ''' ' || unaccent('test') || ' ''' || ':*')), 0)) AS rank
     FROM "articles"
     WHERE (("articles"."tsv") @@ (to_tsquery('simple', ''' ' || unaccent('test') || ' ''' || ':*')))) AS pg_search_906c7ff47cd7c682246c27 ON "articles"."id" = pg_search_906c7ff47cd7c682246c27.pg_search_id
ORDER BY pg_search_906c7ff47cd7c682246c27.rank DESC,
         "articles"."id" ASC
LIMIT 10

paulRbr added a commit to paulRbr/pg_search that referenced this issue May 16, 2022
When performing tsearch with Highlighting, the resulting query result
concatenates the searched columns with a space.

It can be hard to extract the different column data result if both
data are text (containing spaces).

In order to avoid this issue, we can allow users to customize the
columns separator (which needs to be one of the word boundaries used
by the query dictionnary).

Partial solution for Casecommons#336.
paulRbr added a commit to paulRbr/pg_search that referenced this issue Sep 20, 2023
When performing tsearch with Highlighting, the resulting query result
concatenates the searched columns with a space.

It can be hard to extract the different column data result if both
data are text (containing spaces).

In order to avoid this issue, we can allow users to customize the
columns separator (which needs to be one of the word boundaries used
by the query dictionnary).

Partial solution for Casecommons#336.
@msuliq
Copy link

msuliq commented Nov 29, 2023

Seeing that this is still an issue in 2023, I have made a pg_search_multiple_highlight gem that is supposed to solve the issue of multiple highlighting. Please give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants