Search code examples
pythonwhoosh

How to get a indexed document or document field value by document number (doc id)


How do I get an indexed document or document field value by document number (doc id) using Whoosh?

For example, if I get a set of matches by matcher=myquery.matcher(s); I can get matched doc num by matcher.id. How could we retrieve the document information by the doc num ?

I can't find any method in whoosh.reading.IndexReader allowing me to retrieve doc by docnum.


Solution

  • Find one solution via Whoosh documentation. Document information can be further retrieved by stored_fields method in whoosh.searching.Searcher. An example usage to get doc title by docnum can be achieved searcher.stored_fields(matcher.id())["title"]