xapian-core  1.4.27
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Xapian::LatLongDistancePostingSource Class Reference

Posting source which returns a weight based on geospatial distance. More...

#include <geospatial.h>

+ Inheritance diagram for Xapian::LatLongDistancePostingSource:
+ Collaboration diagram for Xapian::LatLongDistancePostingSource:

Public Member Functions

 LatLongDistancePostingSource (Xapian::valueno slot_, const LatLongCoords &centre_, const LatLongMetric &metric_, double max_range_=0.0, double k1_=1000.0, double k2_=1.0)
 Construct a new posting source which returns only documents within range of one of the central coordinates. More...
 
 LatLongDistancePostingSource (Xapian::valueno slot_, const LatLongCoords &centre_, double max_range_=0.0, double k1_=1000.0, double k2_=1.0)
 Construct a new posting source which returns only documents within range of one of the central coordinates. More...
 
 ~LatLongDistancePostingSource ()
 
void next (double min_wt)
 Advance the current position to the next matching document. More...
 
void skip_to (Xapian::docid min_docid, double min_wt)
 Advance to the specified docid. More...
 
bool check (Xapian::docid min_docid, double min_wt)
 Check if the specified docid occurs. More...
 
double get_weight () const
 Return the weight contribution for the current document. More...
 
LatLongDistancePostingSourceclone () const
 Clone the posting source. More...
 
std::string name () const
 Name of the posting source class. More...
 
std::string serialise () const
 Serialise object parameters into a string. More...
 
LatLongDistancePostingSourceunserialise_with_registry (const std::string &serialised, const Registry &registry) const
 Create object given string serialisation returned by serialise(). More...
 
void init (const Database &db_)
 Set this PostingSource to the start of the list of postings. More...
 
std::string get_description () const
 Return a string describing this object. More...
 
- Public Member Functions inherited from Xapian::ValuePostingSource
 ValuePostingSource (Xapian::valueno slot_)
 Construct a ValuePostingSource. More...
 
Xapian::doccount get_termfreq_min () const
 A lower bound on the number of documents this object can return. More...
 
Xapian::doccount get_termfreq_est () const
 An estimate of the number of documents this object can return. More...
 
Xapian::doccount get_termfreq_max () const
 An upper bound on the number of documents this object can return. More...
 
void next (double min_wt)
 Advance the current position to the next matching document. More...
 
void skip_to (Xapian::docid min_docid, double min_wt)
 Advance to the specified docid. More...
 
bool check (Xapian::docid min_docid, double min_wt)
 Check if the specified docid occurs. More...
 
bool at_end () const
 Return true if the current position is past the last entry in this list. More...
 
Xapian::docid get_docid () const
 Return the current docid. More...
 
void init (const Database &db_)
 Set this PostingSource to the start of the list of postings. More...
 
Xapian::Database get_database () const
 The database we're reading values from. More...
 
Xapian::valueno get_slot () const
 The slot we're reading values from. More...
 
std::string get_value () const
 Read current value. More...
 
void done ()
 End the iteration. More...
 
bool get_started () const
 Flag indicating if we've started (true if we have). More...
 
void set_termfreq_min (Xapian::doccount termfreq_min_)
 Set a lower bound on the term frequency. More...
 
void set_termfreq_est (Xapian::doccount termfreq_est_)
 An estimate of the term frequency. More...
 
void set_termfreq_max (Xapian::doccount termfreq_max_)
 An upper bound on the term frequency. More...
 
- Public Member Functions inherited from Xapian::PostingSource
 PostingSource ()
 Allow subclasses to be instantiated. More...
 
virtual ~PostingSource ()
 
void set_maxweight (double max_weight)
 Specify an upper bound on what get_weight() will return from now on. More...
 
double get_maxweight () const
 Return the currently set upper bound on what get_weight() can return. More...
 
virtual PostingSourceunserialise (const std::string &serialised) const
 Create object given string serialisation returned by serialise(). More...
 
PostingSourcerelease ()
 Start reference counting this object. More...
 
const PostingSourcerelease () const
 Start reference counting this object. More...
 
- Public Member Functions inherited from Xapian::Internal::opt_intrusive_base
 opt_intrusive_base (const opt_intrusive_base &)
 
opt_intrusive_baseoperator= (const opt_intrusive_base &)
 
 opt_intrusive_base ()
 Construct object which is initially not reference counted. More...
 
virtual ~opt_intrusive_base ()
 
void ref () const
 
void unref () const
 

Private Member Functions

void calc_distance ()
 Calculate the distance for the current document. More...
 
 LatLongDistancePostingSource (Xapian::valueno slot_, const LatLongCoords &centre_, const LatLongMetric *metric_, double max_range_, double k1_, double k2_)
 Internal constructor; used by clone() and serialise(). More...
 

Private Attributes

double dist
 Current distance from centre. More...
 
LatLongCoords centre
 Centre, to compute distance from. More...
 
const LatLongMetricmetric
 Metric to compute the distance with. More...
 
double max_range
 Maximum range to allow. If set to 0, there is no maximum range. More...
 
double k1
 Constant used in weighting function. More...
 
double k2
 Constant used in weighting function. More...
 

Additional Inherited Members

- Public Attributes inherited from Xapian::Internal::opt_intrusive_base
unsigned _refs
 Reference count. More...
 
- Protected Member Functions inherited from Xapian::Internal::opt_intrusive_base
void release () const
 Start reference counting. More...
 
- Protected Attributes inherited from Xapian::ValuePostingSource
Xapian::Databasedb
 The database we're reading values from. More...
 
Xapian::valuenoslot
 The slot we're reading values from. More...
 
Xapian::ValueIteratorvalue_it
 Value stream iterator. More...
 
bool & started
 Flag indicating if we've started (true if we have). More...
 
Xapian::doccounttermfreq_min
 A lower bound on the term frequency. More...
 
Xapian::doccounttermfreq_est
 An estimate of the term frequency. More...
 
Xapian::doccounttermfreq_max
 An upper bound on the term frequency. More...
 

Detailed Description

Posting source which returns a weight based on geospatial distance.

Experimental - see https://xapian.org/docs/deprecation#experimental-features

Results are weighted by the distance from a fixed point, or list of points, calculated according to the metric supplied. If multiple points are supplied (either in the constructor, or in the coordinates stored in a document), the closest pointwise distance is used.

Documents further away than a specified maximum range (or with no location stored in the specified slot) will not be returned.

The weight returned is computed from the distance using the formula:

k1 * pow(distance + k1, -k2)

(Where k1 and k2 are (strictly) positive, floating point constants, which default to 1000 and 1, respectively. Distance is measured in metres, so this means that something at the centre gets a weight of 1.0, something 1km away gets a weight of 0.5, and something 3km away gets a weight of 0.25, etc)

Definition at line 454 of file geospatial.h.

Constructor & Destructor Documentation

◆ LatLongDistancePostingSource() [1/3]

LatLongDistancePostingSource::LatLongDistancePostingSource ( Xapian::valueno  slot_,
const LatLongCoords centre_,
const LatLongMetric metric_,
double  max_range_,
double  k1_,
double  k2_ 
)
private

◆ LatLongDistancePostingSource() [2/3]

LatLongDistancePostingSource::LatLongDistancePostingSource ( Xapian::valueno  slot_,
const LatLongCoords centre_,
const LatLongMetric metric_,
double  max_range_ = 0.0,
double  k1_ = 1000.0,
double  k2_ = 1.0 
)

Construct a new posting source which returns only documents within range of one of the central coordinates.

Parameters
slot_The value slot to read values from.
centre_The centre point to use for distance calculations.
metric_The metric to use for distance calculations.
max_range_The maximum distance for documents which are returned.
k1_The k1 constant to use in the weighting function.
k2_The k2 constant to use in the weighting function.

Definition at line 91 of file latlong_posting_source.cc.

References k1, k2, Xapian::PostingSource::set_maxweight(), validate_postingsource_params(), and weight_from_distance().

◆ LatLongDistancePostingSource() [3/3]

LatLongDistancePostingSource::LatLongDistancePostingSource ( Xapian::valueno  slot_,
const LatLongCoords centre_,
double  max_range_ = 0.0,
double  k1_ = 1000.0,
double  k2_ = 1.0 
)

Construct a new posting source which returns only documents within range of one of the central coordinates.

Parameters
slot_The value slot to read values from.
centre_The centre point to use for distance calculations.
max_range_The maximum distance for documents which are returned.
k1_The k1 constant to use in the weighting function.
k2_The k2 constant to use in the weighting function.

Xapian::GreatCircleMetric is used as the metric.

Definition at line 109 of file latlong_posting_source.cc.

References k1, k2, Xapian::PostingSource::set_maxweight(), validate_postingsource_params(), and weight_from_distance().

◆ ~LatLongDistancePostingSource()

LatLongDistancePostingSource::~LatLongDistancePostingSource ( )

Definition at line 126 of file latlong_posting_source.cc.

References metric.

Member Function Documentation

◆ calc_distance()

void LatLongDistancePostingSource::calc_distance ( )
private

Calculate the distance for the current document.

Definition at line 51 of file latlong_posting_source.cc.

Referenced by check(), next(), and skip_to().

◆ check()

bool LatLongDistancePostingSource::check ( Xapian::docid  did,
double  min_wt 
)
virtual

Check if the specified docid occurs.

The caller is required to ensure that the specified document id did actually exists in the database. If it does, it must move to that document id, and return true. If it does not, it may either:

  • return true, having moved to a definite position (including "at_end"), which must be the same position as skip_to() would have moved to.

or

  • return false, having moved to an "indeterminate" position, such that a subsequent call to next() or skip_to() will move to the next matching position after did.

Generally, this method should act like skip_to() and return true if that can be done at little extra cost.

Otherwise it should simply check if a particular docid is present, returning true if it is, and false if it isn't.

The default implementation calls skip_to() and always returns true.

Xapian will always call init() on a PostingSource before calling this for the first time.

Note: in the case of a multi-database search, the docid specified is the docid in the single subdatabase relevant to this posting source. See the init() method for details.

Parameters
didThe document id to check.
min_wtThe minimum weight contribution that is needed (this is just a hint which subclasses may ignore).

Reimplemented from Xapian::PostingSource.

Definition at line 159 of file latlong_posting_source.cc.

References Xapian::ValuePostingSource::at_end(), calc_distance(), Xapian::ValuePostingSource::check(), dist, and max_range.

◆ clone()

LatLongDistancePostingSource * LatLongDistancePostingSource::clone ( ) const
virtual

Clone the posting source.

The clone should inherit the configuration of the parent, but need not inherit the state. ie, the clone does not need to be in the same iteration position as the original: the matcher will always call init() on the clone before attempting to move the iterator, or read the information about the current position of the iterator.

This may return NULL to indicate that cloning is not supported. In this case, the PostingSource may only be used with a single-database search.

The default implementation returns NULL.

Note that the returned object will be deallocated by Xapian after use with "delete". If you want to handle the deletion in a special way (for example when wrapping the Xapian API for use from another language) then you can define a static operator delete method in your subclass as shown here: https://trac.xapian.org/ticket/554#comment:1

Reimplemented from Xapian::PostingSource.

Definition at line 185 of file latlong_posting_source.cc.

References centre, Xapian::LatLongMetric::clone(), Xapian::ValuePostingSource::get_slot(), k1, k2, LatLongDistancePostingSource(), max_range, and metric.

◆ get_description()

string LatLongDistancePostingSource::get_description ( ) const
virtual

Return a string describing this object.

This default implementation returns a generic answer. This default it provided to avoid forcing those deriving their own PostingSource subclass from having to implement this (they may not care what get_description() gives for their subclass).

Reimplemented from Xapian::PostingSource.

Definition at line 277 of file latlong_posting_source.cc.

References Xapian::ValuePostingSource::get_slot(), and Xapian::Internal::str().

◆ get_weight()

double LatLongDistancePostingSource::get_weight ( ) const
virtual

Return the weight contribution for the current document.

This default implementation always returns 0, for convenience when implementing "weight-less" PostingSource subclasses.

This method may assume that it will only be called when there is a "current document". In detail: Xapian will always call init() on a PostingSource before calling this for the first time. It will also only call this if the PostingSource reports that it is pointing to a valid document (ie, it will not call it before calling at least one of next(), skip_to() or check(), and will ensure that the PostingSource is not at the end by calling at_end()).

Reimplemented from Xapian::PostingSource.

Definition at line 179 of file latlong_posting_source.cc.

References dist, k1, k2, and weight_from_distance().

Referenced by DEFINE_TESTCASE().

◆ init()

void LatLongDistancePostingSource::init ( const Database db)
virtual

Set this PostingSource to the start of the list of postings.

This is called automatically by the matcher prior to each query being processed.

If a PostingSource is used for multiple searches, init() will therefore be called multiple times, and must handle this by using the database passed in the most recent call.

Parameters
dbThe database which the PostingSource should iterate through.

Note: in the case of a multi-database search, a separate PostingSource will be used for each database (the separate PostingSources will be obtained using clone()), and each PostingSource will be passed one of the sub-databases as the db parameter here. The db parameter will therefore always refer to a single database. All docids passed to, or returned from, the PostingSource refer to docids in that single database, rather than in the multi-database.

Implements Xapian::PostingSource.

Definition at line 264 of file latlong_posting_source.cc.

References Xapian::ValuePostingSource::init(), max_range, and Xapian::ValuePostingSource::set_termfreq_min().

Referenced by DEFINE_TESTCASE().

◆ name()

string LatLongDistancePostingSource::name ( ) const
virtual

Name of the posting source class.

This is used when serialising and unserialising posting sources; for example, for performing remote searches.

If the subclass is in a C++ namespace, the namespace should be included in the name, using "::" as a separator. For example, for a PostingSource subclass called "FooPostingSource" in the "Xapian" namespace the result of this call should be "Xapian::FooPostingSource".

This should only be implemented if serialise() and unserialise() are also implemented. The default implementation returns an empty string.

If this returns an empty string, Xapian will assume that serialise() and unserialise() are not implemented.

Reimplemented from Xapian::PostingSource.

Definition at line 193 of file latlong_posting_source.cc.

◆ next()

void LatLongDistancePostingSource::next ( double  min_wt)
virtual

Advance the current position to the next matching document.

The PostingSource starts before the first entry in the list, so next(), skip_to() or check() must be called before any methods which need the context of the current position.

Xapian will always call init() on a PostingSource before calling this for the first time.

Parameters
min_wtThe minimum weight contribution that is needed (this is just a hint which subclasses may ignore).

Implements Xapian::PostingSource.

Definition at line 132 of file latlong_posting_source.cc.

References Xapian::ValuePostingSource::at_end(), calc_distance(), dist, max_range, and Xapian::ValuePostingSource::next().

Referenced by DEFINE_TESTCASE().

◆ serialise()

string LatLongDistancePostingSource::serialise ( ) const
virtual

Serialise object parameters into a string.

The serialised parameters should represent the configuration of the posting source, but need not (indeed, should not) represent the current iteration state.

If you don't want to support the remote backend, you can use the default implementation which simply throws Xapian::UnimplementedError.

Reimplemented from Xapian::PostingSource.

Definition at line 199 of file latlong_posting_source.cc.

References centre, encode_length(), Xapian::ValuePostingSource::get_slot(), k1, k2, max_range, metric, Xapian::LatLongMetric::name(), Xapian::LatLongCoords::serialise(), Xapian::LatLongMetric::serialise(), and serialise_double().

◆ skip_to()

void LatLongDistancePostingSource::skip_to ( Xapian::docid  did,
double  min_wt 
)
virtual

Advance to the specified docid.

If the specified docid isn't in the list, position ourselves on the first document after it (or at_end() if no greater docids are present).

If the current position is already the specified docid, this method will leave the position unmodified.

If the specified docid is earlier than the current position, the behaviour is unspecified. A sensible behaviour would be to leave the current position unmodified, but it is also reasonable to move to the specified docid.

The default implementation calls next() repeatedly, which works but skip_to() can often be implemented much more efficiently.

Xapian will always call init() on a PostingSource before calling this for the first time.

Note: in the case of a multi-database search, the docid specified is the docid in the single subdatabase relevant to this posting source. See the init() method for details.

Parameters
didThe document id to advance to.
min_wtThe minimum weight contribution that is needed (this is just a hint which subclasses may ignore).

Reimplemented from Xapian::PostingSource.

Definition at line 145 of file latlong_posting_source.cc.

References Xapian::ValuePostingSource::at_end(), calc_distance(), dist, max_range, Xapian::ValuePostingSource::next(), and Xapian::ValuePostingSource::skip_to().

◆ unserialise_with_registry()

LatLongDistancePostingSource * LatLongDistancePostingSource::unserialise_with_registry ( const std::string &  serialised,
const Registry registry 
) const
virtual

Create object given string serialisation returned by serialise().

Note that the returned object will be deallocated by Xapian after use with "delete". If you want to handle the deletion in a special way (for example when wrapping the Xapian API for use from another language) then you can define a static operator delete method in your subclass as shown here: https://trac.xapian.org/ticket/554#comment:1

This method is supplied with a Registry object, which can be used when unserialising objects contained within the posting source. The default implementation simply calls unserialise() which doesn't take the Registry object, so you do not need to implement this method unless you want to take advantage of the Registry object when unserialising.

Parameters
serialisedA serialised instance of this PostingSource subclass.
registryThe Xapian::Registry object to use.

Reimplemented from Xapian::PostingSource.

Definition at line 219 of file latlong_posting_source.cc.

References decode_length(), decode_length_and_check(), Xapian::Registry::get_lat_long_metric(), LatLongDistancePostingSource(), Xapian::LatLongCoords::unserialise(), Xapian::LatLongMetric::unserialise(), and unserialise_double().

Member Data Documentation

◆ centre

LatLongCoords Xapian::LatLongDistancePostingSource::centre
private

Centre, to compute distance from.

Definition at line 460 of file geospatial.h.

Referenced by clone(), and serialise().

◆ dist

double Xapian::LatLongDistancePostingSource::dist
private

Current distance from centre.

Definition at line 457 of file geospatial.h.

Referenced by check(), get_weight(), next(), and skip_to().

◆ k1

double Xapian::LatLongDistancePostingSource::k1
private

Constant used in weighting function.

Definition at line 469 of file geospatial.h.

Referenced by clone(), get_weight(), LatLongDistancePostingSource(), and serialise().

◆ k2

double Xapian::LatLongDistancePostingSource::k2
private

Constant used in weighting function.

Definition at line 472 of file geospatial.h.

Referenced by clone(), get_weight(), LatLongDistancePostingSource(), and serialise().

◆ max_range

double Xapian::LatLongDistancePostingSource::max_range
private

Maximum range to allow. If set to 0, there is no maximum range.

Definition at line 466 of file geospatial.h.

Referenced by check(), clone(), init(), next(), serialise(), and skip_to().

◆ metric

const LatLongMetric* Xapian::LatLongDistancePostingSource::metric
private

Metric to compute the distance with.

Definition at line 463 of file geospatial.h.

Referenced by clone(), serialise(), and ~LatLongDistancePostingSource().


The documentation for this class was generated from the following files: