xappy.searchconnection.SearchResult

Package xappy :: Module searchconnection :: Class SearchResult |
[frames] | no frames]

# Class SearchResult

source code

                          object --+
                                   |
    datastructures.ProcessedDocument --+
                                       |
                                      SearchResult

A result from a search.

As well as being a ProcessedDocument representing the document in the database, the result has several members which may be used to get information about how well the document matches the search:

> - `rank`: The rank of the document in the search results, starting at 0 (ie, 0 is the "top" result, 1 is the second result, etc).
> - `weight`: A floating point number indicating the weight of the result document. The value is only meaningful relative to other results for a given search - a different search, or the same search with a different database, may give an entirely different scale to the weights. This should not usually be displayed to users, but may be useful if trying to perform advanced reweighting operations on search results.
> - `percent`: A percentage value for the weight of a document. This is just a rescaled form of the `weight` member. It doesn't represent any kind of probability value; the only real meaning of the numbers is that, within a single set of results, a document with a higher percentage corresponds to a better match. Because the percentage doesn't really represent a probability, or a confidence value, it is probably unhelpful to display it to most users, since they tend to place an over emphasis on its meaning. However, it is included because it may be useful occasionally.

Instance Methods
__init__(self, msetitem, results) Create a ProcessedDocument. | source code
summarise(self, field, maxlen=600, hl=`(``'``<b>``'``,` `'``</b>``'``)`, query=None) Return a summarised version of the field specified. | source code
highlight(self, field, hl=`(``'``<b>``'``,` `'``</b>``'``)`, strip_tags=False, query=None) Return a highlighted version of the field specified. | source code
__repr__(self) repr(x) | source code
Inherited from `datastructures.ProcessedDocument`: `add_term`, `add_value`, `get_value`, `prepare` Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Properties
Inherited from `datastructures.ProcessedDocument`: `data`, `id` Inherited from `object`: `__class__`

Method Details

### __init__(self, msetitem, results) (Constructor) | source code
Create a ProcessedDocument. fieldmappings is the configuration from a database connection used lookup the configuration to use to store each field. If supplied, `xapdoc` is a Xapian document to store in the processed document. Otherwise, a new Xapian document is created. Overrides: datastructures.ProcessedDocument.__init__ (inherited documentation)

### summarise(self, field, maxlen=600, hl=`(``'``<b>``'``,` `'``</b>``'``)`, query=None) | source code
Return a summarised version of the field specified. This will return a summary of the contents of the field stored in the search result, with words which match the query highlighted. The maximum length of the summary (in characters) may be set using the maxlen parameter. The return value will be a string holding the summary, with highlighting applied. If there are multiple instances of the field in the document, the instances will be joined with a newline character. To turn off highlighting, set hl to None. Each highlight will consist of the first entry in the `hl` list being placed before the word, and the second entry in the `hl` list being placed after the word. Any XML or HTML style markup tags in the field will be stripped before the summarisation algorithm is applied. If `query` is supplied, it should contain a Query object, as returned from SearchConnection.query_parse() or related methods, which will be used as the basis of the summarisation and highlighting rather than the query which was used for the search. Raises KeyError if the field is not known.

### highlight(self, field, hl=`(``'``<b>``'``,` `'``</b>``'``)`, strip_tags=False, query=None) | source code
Return a highlighted version of the field specified. This will return all the contents of the field stored in the search result, with words which match the query highlighted. The return value will be a list of strings (corresponding to the list of strings which is the raw field data). Each highlight will consist of the first entry in the `hl` list being placed before the word, and the second entry in the `hl` list being placed after the word. If `strip_tags` is True, any XML or HTML style markup tags in the field will be stripped before highlighting is applied. If `query` is supplied, it should contain a Query object, as returned from SearchConnection.query_parse() or related methods, which will be used as the basis of the summarisation and highlighting rather than the query which was used for the search. Raises KeyError if the field is not known.

### __repr__(self) (Representation operator) | source code
repr(x) Overrides: datastructures.ProcessedDocument.__repr__