-
Notifications
You must be signed in to change notification settings - Fork 381
Return highlighted excerpt of result #211
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
Conversation
If configuration is set to
```
:using => {
:tsearch => {:highlight => true}
}
```
then queryies will return records with an additional `pg_highlight`
attribute.
Currently uses the defaults set by the Postgres function ts_headline, as
specified here:
http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-HEADLINE
Improves the "SELECT" clause of the statement by factoring out added fields into their own methods to be added as needed.
Should search within all provided documents
Will generate SQL to run the ts_headline() function with the provided query.
Using the ts_search options
```ruby
{ highlight: { start_sel: "begin", stop_sel: "end" } }
```
will override the default "<b>" and "</b" query delimiters in the highlighted results.
|
So the build is failing because Rubocop wants class definitions to have <= 100 lines of code, and /lib/pg_search/features/tsearch.rb is 107. :/ I could resolve by either:
Do you have a preference @nertzy? |
|
It would be better to refactor some of the methods into service objects. For instance, tsquery_for_term is way too complicated. But for now it would be OK with me to add a Rubocop comment that turns off the file size check for just tsearch.rb until we can get a good refactor in. Just add a line to the top of the file that turns off that rule: # rubocop:disable Metrics/ClassLength |
|
This is awesome! 👍 |
|
Thanks, @nertzy. I'd rather do it right the first time, so I'll refactor them out as suggested. |
Just to make rubocop pass since the class is a tad too long...
The ts_highlight() command is only available on PostgreSQL versions 9.0 and above.
Don't modify the behavior, because it already exists.
|
Ok, so here's the deal. I cleaned up this PR, added documentation, and added a workaround to appease Rubocop. Then, in a separate branch, I did some serious refactoring. I didn't want to bundle all of it into this one PR, so we can do it in two phases:
What do you think, @nertzy? Will that work for you? |
Adds support for MaxFragments
|
I'm sorry that I've taken so long to address this pull request. Unfortunately, the new subquery structure in pg_search 1.0 breaks this pull request. I spent a few minutes trying to refactor what you've built to act similarly to how So I'm going to close this for now. I'd gladly accept a pull request based off of this that adapts things to the new subquery, and that makes the highlight optional through something like a |
Basically I adapted Casecommons#211
Basically I adapted Casecommons#211
Basically I adapted Casecommons#211
Basically I adapted Casecommons#211
Basically I adapted Casecommons#211
Basically I adapted Casecommons#211
|
Hey @nertzy no worries, I got pulled in other directions too. Sadly this is not a high priority for me anymore, so don't think I'll be able to work on the feature anytime soon. Thanks for the helpful suggestions and feedback earlier though! Hope that #280 is able to make it through by building on this one. 😄 |
Basically I adapted Casecommons#211
Basically I adapted Casecommons#211
|
@nertzy Was documentation for this feature merged into the master branch README by mistake? I keep trying to use |
|
By the way I'm referring to https://github.com/Casecommons/pg_search/blob/ff1af346322ca54808b3f53081149b8cac55bb76/README.md#highlight-postgresql-90-and-newer-only The recommended configuration causes the following error: |
|
It's not an error. It's merged to master but not yet in a released gem version, I believe. I'll try to get a new version cut very soon, sorry for the confusion! |
|
Oh, fantastic. Thank you.
|
|
There are still error in documentation (the sample content is: but not ) |
Basically I adapted Casecommons/pg_search#211
Basically I adapted Casecommons/pg_search#211
Basically I adapted Casecommons/pg_search#211
Basically I adapted Casecommons/pg_search#211
Addresses issue #100.
If configuration is set to
then queries will return records with an additional
pg_highlightattribute.Currently uses the defaults set by the Postgres function ts_headline, as specified here: http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-HEADLINE
Also supports custom delimiters
will override the default
<b>and</b>query delimiters in the highlighted results.NOTE: the pg function used (
ts_headline()) is not supported on pg versions < 9.0. I know that the gem is intended to support 8.0 and above, but this seemed like a useful enough feature get started. Any way to work around?