This module contains classes and functions related to searching the index.
Wraps an IndexReader object and provides methods for searching the index.
Parameters: |
|
---|
Convenience method returns the stored fields of a document matching the given keyword arguments, where the keyword keys are field names and the values are terms that must appear in the field.
This method is equivalent to:
searcher.stored_fields(searcher.document_number(<keyword args>))
Where Searcher.documents() returns a generator, this function returns either a dictionary or None. Use it when you assume the given keyword arguments either match zero or one documents (i.e. at least one of the fields is a unique key).
>>> stored_fields = searcher.document(path=u"/a/b")
>>> if stored_fields:
... print stored_fields['title']
... else:
... print "There is no document with the path /a/b"
Returns the document number of the document matching the given keyword arguments, where the keyword keys are field names and the values are terms that must appear in the field.
>>> docnum = searcher.document_number(path=u"/a/b")
Where Searcher.document_numbers() returns a generator, this function returns either an int or None. Use it when you assume the given keyword arguments either match zero or one documents (i.e. at least one of the fields is a unique key).
Return type: | int |
---|
Returns a generator of the document numbers for documents matching the given keyword arguments, where the keyword keys are field names and the values are terms that must appear in the field.
>>> docnums = list(searcher.document_numbers(emailto=u"matt@whoosh.ca"))
Convenience method returns the stored fields of a document matching the given keyword arguments, where the keyword keys are field names and the values are terms that must appear in the field.
Returns a generator of dictionaries containing the stored fields of any documents matching the keyword arguments.
>>> for stored_fields in searcher.documents(emailto=u"matt@whoosh.ca"):
... print "Email subject:", stored_fields['subject']
Returns the ‘numterms’ most important terms from the documents listed (by number) in ‘docnums’. You can get document numbers for the documents your interested in with the document_number() and document_numbers() methods.
>>> docnum = searcher.document_number(path=u"/a/b")
>>> keywords = list(searcher.key_terms([docnum], "content"))
“Most important” is generally defined as terms that occur frequently in the top hits but relatively infrequently in the collection as a whole.
Parameters: |
|
---|
Runs the query represented by the query object and returns a Results object.
Parameters: |
|
---|---|
Return type: |
This object is returned by a Searcher. This object represents the results of a search query. You can mostly use it as if it was a list of dictionaries, where each dictionary is the stored fields of the document at that position in the results.
Parameters: |
|
---|
Appends hits from ‘results’ (that are not already in this results object) to the end of these results.
Parameter: | results – another results object. |
---|
Returns the ‘numterms’ most important terms from the top ‘numdocs’ documents in these results. “Most important” is generally defined as terms that occur frequently in the top hits but relatively infrequently in the collection as a whole.
Parameters: |
|
---|---|
Returns: | list of unicode strings. |
Re-sorts the results so any hits that are also in ‘results’ appear before hits not in ‘results’, otherwise keeping their current relative positions. This does not add the documents in the other results object to this one.
Parameters: |
|
---|
Combines the effects of extend() and increase(): hits that are also in ‘results’ are raised. Then any hits from ‘results’ that are not in this results object are appended to the end of these results.
Parameter: | results – another results object. |
---|
Represents a single page out of a longer list of results, as returned by whoosh.searching.Searcher.search_page(). Supports a subset of the interface of the Results object, namely getting stored fields with __getitem__ (square brackets), iterating, and the score() and docnum() methods.
The offset attribute contains the results number this page starts at (numbered from 0). For example, if the page length is 10, the offset attribute on the second page will be 10.
The pagecount attribute contains the number of pages available.
The pagenum attribute contains the page number. This may be less than the page you requested if the results had too few pages. For example, if you do:
ResultsPage(results, 5)
but the results object only contains 3 pages worth of hits, pagenum will be 3.
The pagelen attribute contains the number of results on this page (which may be less than the page length you requested if this is the last page of the results).
The total attribute contains the total number of hits in the results.
>>> mysearcher = myindex.searcher()
>>> pagenum = 2
>>> page = mysearcher.find_page(pagenum, myquery)
>>> print("Page %s of %s, results %s to %s of %s" %
... (pagenum, page.pagecount, page.offset+1, page.offset+page.pagelen, page.total))
>>> for i, fields in enumerate(page):
... print("%s. %r" % (page.offset + i + 1, fields))
>>> mysearcher.close()
Parameters: |
|
---|