xapian-core  1.4.27
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, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  */
23 
24 #include <config.h>
25 
26 #include "xapian/geospatial.h"
27 #include "xapian/document.h"
28 #include "xapian/queryparser.h" // For sortable_serialise.
29 
30 using namespace Xapian;
31 using namespace std;
32 
33 string
35 {
36  string val(doc.get_value(slot));
37  if (val.empty()) {
38  return defkey;
39  }
40  LatLongCoords doccoords;
41  doccoords.unserialise(val);
42  double distance = (*metric)(centre, doccoords);
43  return sortable_serialise(distance);
44 }
45 
47 {
48  delete metric;
49 }
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
STL namespace.
std::string sortable_serialise(double value)
Convert a floating point number to a string, preserving sort order.
Definition: queryparser.h:1382
Geospatial search support routines.
std::string operator()(const Xapian::Document &doc) const
Build a key string for a Document.
A sequence of latitude-longitude coordinates.
Definition: geospatial.h:232
API for working with documents.
void unserialise(const std::string &serialised)
Unserialise a string and set this object to the coordinates in it.
Definition: latlongcoord.cc:94
std::string get_value(Xapian::valueno slot) const
Get value by number.
Definition: omdocument.cc:64
A handle representing a document in a Xapian database.
Definition: document.h:61
parsing a user query string to build a Xapian::Query object