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

Handle output with no highlighted matches #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imarko
Copy link

@imarko imarko commented Oct 7, 2022

Make pdfgrep-current-page-and-match return nil for the match when there is no highlighted match in the output line. pdfgrep-goto-locus already handles this.

Make pdfgrep-current-page-and-match return nil for the match when
there is no highlighted match in the output line. pdfgrep-goto-locus
already handles this.
@imarko
Copy link
Author

imarko commented Oct 7, 2022

Normal pdfgrep invocations always include a highlighted match but if the user specifies --color=never or if another tool is used to produce similar output without highlights then pdfgrep.el would throw an error on the line without highlights without this fix.

I am working on creating a script that produces pdfgrep-like output from recoll queries and there are some cases when not all lines will have highlights

@imarko
Copy link
Author

imarko commented Oct 7, 2022

Below is my pdfgrep-recoll script that can sometimes produce output lines with no highlighted matches, seems to happen for phrase searches in particular:

#! /usr/bin/python
from urllib.parse import urlparse
import sys

from recoll import recoll


class HL():
    def startMatch(self, i):
        return "\33[01;31m\33[K"

    def endMatch(self):
        return "\33[m\33[K"


hl = HL()
query = " ".join(sys.argv[1:])
q = recoll.connect().query()
count = q.execute(query)
for doc in q:
    for snip in q.getsnippets(doc, maxoccs=99999, ctxwords=8, sortbypage=True, methods=hl):
        print("%s:%d:%s" % (urlparse(doc.url).path, snip[0], snip[2]))

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

Successfully merging this pull request may close these issues.

None yet

1 participant