45 return k1 / (dist + k1);
46 return k1 * pow(dist + k1, -k2);
52 dist = (*metric)(centre, get_value());
59 string msg(
"k1 parameter to LatLongDistancePostingSource must be "
60 "greater than 0; was ");
65 string msg(
"k2 parameter to LatLongDistancePostingSource must be "
66 "greater than 0; was ");
82 max_range(max_range_),
99 metric(metric_.clone()),
100 max_range(max_range_),
117 max_range(max_range_),
194 return "Xapian::LatLongDistancePostingSource";
215 const char *
p = s.data();
216 const char * end =
p + s.size();
223 string new_serialised_centre;
224 string new_metric_name;
231 string new_serialised_metric(
p, end -
p);
238 if (metric_type == NULL) {
239 string msg(
"LatLongMetric ");
240 msg += new_metric_name;
241 msg +=
" not registered";
249 new_max_range, new_k1, new_k2);
269 string result(
"Xapian::LatLongDistancePostingSource(slot=");
An indexed database of documents.
Calculate the great-circle distance between two coordinates on a sphere.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
A sequence of latitude-longitude coordinates.
std::string serialise() const
Return a serialised form of the coordinate list.
void unserialise(std::string_view serialised)
Unserialise a string and set this object to the coordinates in it.
Posting source which returns a weight based on geospatial distance.
void next(double min_wt)
Advance the current position to the next matching document.
std::string get_description() const
Return a string describing this object.
LatLongDistancePostingSource(Xapian::valueno slot_, const LatLongCoords ¢re_, const LatLongMetric *metric_, double max_range_, double k1_, double k2_)
Internal constructor; used by clone() and serialise().
double k1
Constant used in weighting function.
double get_weight() const
Return the weight contribution for the current document.
double k2
Constant used in weighting function.
~LatLongDistancePostingSource()
void skip_to(Xapian::docid min_docid, double min_wt)
Advance to the specified docid.
double dist
Current distance from centre.
double max_range
Maximum range to allow. If set to 0, there is no maximum range.
LatLongCoords centre
Centre, to compute distance from.
std::string serialise() const
Serialise object parameters into a string.
LatLongDistancePostingSource * clone() const
Clone the posting source.
const LatLongMetric * metric
Metric to compute the distance with.
bool check(Xapian::docid min_docid, double min_wt)
Check if the specified docid occurs.
void reset(const Database &db_, Xapian::doccount shard_index)
Set this PostingSource to the start of the list of postings.
std::string name() const
Name of the posting source class.
LatLongDistancePostingSource * unserialise_with_registry(const std::string &serialised, const Registry ®istry) const
Create object given string serialisation returned by serialise().
void calc_distance()
Calculate the distance for the current document.
Base class for calculating distances between two lat/long coordinates.
virtual LatLongMetric * unserialise(const std::string &serialised) const =0
Create object given string serialisation returned by serialise().
virtual std::string serialise() const =0
Serialise object parameters into a string.
virtual LatLongMetric * clone() const =0
Clone the metric.
virtual std::string name() const =0
Return the full name of the metric.
void set_maxweight(double max_weight)
Specify an upper bound on what get_weight() will return from now on.
Registry for user subclasses.
const Xapian::LatLongMetric * get_lat_long_metric(std::string_view name) const
Get a lat-long metric given a name.
Indicates an error in the std::string serialisation of an object.
A posting source which generates weights from a value slot.
void skip_to(Xapian::docid min_docid, double min_wt)
Advance to the specified docid.
void set_termfreq_min(Xapian::doccount termfreq_min_)
Set a lower bound on the term frequency.
bool at_end() const
Return true if the current position is past the last entry in this list.
void next(double min_wt)
Advance the current position to the next matching document.
void reset(const Database &db_, Xapian::doccount shard_index)
Set this PostingSource to the start of the list of postings.
bool check(Xapian::docid min_docid, double min_wt)
Check if the specified docid occurs.
Xapian::valueno get_slot() const
The slot we're reading values from.
Hierarchy of classes which Xapian can throw as exceptions.
Geospatial search support routines.
static double weight_from_distance(double dist, double k1, double k2)
static void validate_postingsource_params(double k1, double k2)
Validate the parameters supplied to LatLongDistancePostingSource.
string str(int value)
Convert int to std::string.
The Xapian namespace contains public interfaces for the Xapian library.
unsigned valueno
The number for a value slot in a document.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Pack types into strings and unpack them again.
bool unpack_string(const char **p, const char *end, std::string &result)
Decode a std::string from a string.
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
void pack_string(std::string &s, std::string_view value)
Append an encoded std::string to a string.
Class for looking up user subclasses during unserialisation.
string serialise_double(double v)
Serialise a double to a string.
double unserialise_double(const char **p, const char *end)
Unserialise a double serialised by serialise_double.
functions to serialise and unserialise a double
Convert types to std::string.