Skip to content

Handle output with no highlighted matches - #8

Open
imarko wants to merge 1 commit into
jeremy-compostella:masterfrom
imarko:nomatch
Open

Handle output with no highlighted matches#8
imarko wants to merge 1 commit into
jeremy-compostella:masterfrom
imarko:nomatch

Conversation

@imarko

@imarko imarko commented Oct 7, 2022

Copy link
Copy Markdown

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

imarko commented Oct 7, 2022

Copy link
Copy Markdown
Author

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

imarko commented Oct 7, 2022

Copy link
Copy Markdown
Author

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.

1 participant