xapian-core  2.0.0
latlong_distance_keymaker.cc
Go to the documentation of this file.
1 
4 /* Copyright 2008 Lemur Consulting Ltd
5  * Copyright 2011 Richard Boulton
6  * Copyright 2012 Olly Betts
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see
20  * <https://www.gnu.org/licenses/>.
21  */
22 
23 #include <config.h>
24 
25 #include "xapian/geospatial.h"
26 #include "xapian/document.h"
27 #include "xapian/queryparser.h" // For sortable_serialise.
28 
29 using namespace Xapian;
30 using namespace std;
31 
32 string
34 {
35  string val(doc.get_value(slot));
36  if (val.empty()) {
37  return defkey;
38  }
39  LatLongCoords doccoords;
40  doccoords.unserialise(val);
41  double distance = (*metric)(centre, doccoords);
42  return sortable_serialise(distance);
43 }
44 
46 {
47  delete metric;
48 }
Class representing a document.
Definition: document.h:64
std::string get_value(Xapian::valueno slot) const
Read a value slot in this document.
Definition: document.cc:185
A sequence of latitude-longitude coordinates.
Definition: geospatial.h:231
void unserialise(std::string_view serialised)
Unserialise a string and set this object to the coordinates in it.
Definition: latlongcoord.cc:95
std::string operator()(const Xapian::Document &doc) const
Build a key string for a Document.
Class representing a document.
Geospatial search support routines.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
std::string sortable_serialise(double value)
Convert a floating point number to a string, preserving sort order.
Definition: queryparser.h:1229
parsing a user query string to build a Xapian::Query object