46 return k1 / (dist + k1);
47 return k1 * pow(dist + k1, -k2);
53 dist = (*metric)(centre, get_value());
60 string msg(
"k1 parameter to LatLongDistancePostingSource must be " 61 "greater than 0; was ");
66 string msg(
"k2 parameter to LatLongDistancePostingSource must be " 67 "greater than 0; was ");
83 max_range(max_range_),
195 return "Xapian::LatLongDistancePostingSource";
207 result += serialised_centre;
209 result += metric_name;
211 result += serialised_metric;
222 const char * p = s.data();
223 const char * end = p + s.size();
229 string new_serialised_centre(p, len);
232 string new_metric_name(p, len);
235 string new_serialised_metric(p, len);
241 throw NetworkError(
"Bad serialised LatLongDistancePostingSource - junk at end");
249 if (metric_type == NULL) {
250 string msg(
"LatLongMetric ");
251 msg += new_metric_name;
252 msg +=
" not registered";
260 new_max_range, new_k1, new_k2);
279 string result(
"Xapian::LatLongDistancePostingSource(slot=");
The Xapian namespace contains public interfaces for the Xapian library.
virtual LatLongMetric * clone() const =0
Clone the metric.
void init(const Database &db_)
Set this PostingSource to the start of the list of postings.
length encoded as a string
This class is used to access a database, or a group of databases.
void set_maxweight(double max_weight)
Specify an upper bound on what get_weight() will return from now on.
LatLongCoords centre
Centre, to compute distance from.
std::string get_description() const
Return a string describing this object.
bool check(Xapian::docid min_docid, double min_wt)
Check if the specified docid occurs.
bool at_end() const
Return true if the current position is past the last entry in this list.
static void validate_postingsource_params(double k1, double k2)
Validate the parameters supplied to LatLongDistancePostingSource.
double dist
Current distance from centre.
void calc_distance()
Calculate the distance for the current document.
Convert types to std::string.
std::string encode_length(T len)
Encode a length as a variable-length string.
std::string serialise() const
Return a serialised form of the coordinate list.
Hierarchy of classes which Xapian can throw as exceptions.
functions to serialise and unserialise a double
Posting source which returns a weight based on geospatial distance.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
double max_range
Maximum range to allow. If set to 0, there is no maximum range.
static double weight_from_distance(double dist, double k1, double k2)
double unserialise_double(const char **p, const char *end)
Unserialise a double serialised by serialise_double.
Geospatial search support routines.
Registry for user subclasses.
virtual LatLongMetric * unserialise(const std::string &serialised) const =0
Create object given string serialisation returned by serialise().
void init(const Database &db_)
Set this PostingSource to the start of the list of postings.
Base class for calculating distances between two lat/long coordinates.
LatLongDistancePostingSource * unserialise_with_registry(const std::string &serialised, const Registry ®istry) const
Create object given string serialisation returned by serialise().
string str(int value)
Convert int to std::string.
virtual std::string serialise() const =0
Serialise object parameters into a string.
void skip_to(Xapian::docid min_docid, double min_wt)
Advance to the specified docid.
const LatLongMetric * metric
Metric to compute the distance with.
double k1
Constant used in weighting function.
A sequence of latitude-longitude coordinates.
std::string name() const
Name of the posting source class.
A posting source which generates weights from a value slot.
~LatLongDistancePostingSource()
bool check(Xapian::docid min_docid, double min_wt)
Check if the specified docid occurs.
double get_weight() const
Return the weight contribution for the current document.
std::string serialise_double(double v)
Serialise a double to a string.
void decode_length_and_check(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
LatLongDistancePostingSource * clone() const
Clone the posting source.
Indicates a problem communicating with a remote database.
virtual std::string name() const =0
Return the full name of the metric.
unsigned valueno
The number for a value slot in a document.
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 k2
Constant used in weighting function.
std::string serialise() const
Serialise object parameters into a string.
Calculate the great-circle distance between two coordinates on a sphere.
void skip_to(Xapian::docid min_docid, double min_wt)
Advance to the specified docid.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
void unserialise(const std::string &serialised)
Unserialise a string and set this object to the coordinates in it.
void decode_length(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
void next(double min_wt)
Advance the current position to the next matching document.
Class for looking up user subclasses during unserialisation.
Xapian::valueno get_slot() const
The slot we're reading values from.
void set_termfreq_min(Xapian::doccount termfreq_min_)
Set a lower bound on the term frequency.
const Xapian::LatLongMetric * get_lat_long_metric(const std::string &name) const
Get a lat-long metric given a name.
void next(double min_wt)
Advance the current position to the next matching document.