diff options
author | Yuri Gorshenin <y@maps.me> | 2016-09-02 14:40:01 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-09-05 12:30:57 +0300 |
commit | f3d2e6a5d4ea6e0df88669c73569a7ff3ccd0dc3 (patch) | |
tree | 296f038c9861fe181165fc3bcf3eeaa46e2048be /search/search_engine_pylib | |
parent | ad9015965a3e270e41857d521a69f6af768c18e4 (diff) |
Review fixes.
Diffstat (limited to 'search/search_engine_pylib')
-rw-r--r-- | search/search_engine_pylib/README.txt | 37 | ||||
-rw-r--r-- | search/search_engine_pylib/api.cpp | 5 | ||||
-rwxr-xr-x | search/search_engine_pylib/run_search_engine.py | 29 | ||||
-rw-r--r-- | search/search_engine_pylib/search_engine_pylib.pro | 25 |
4 files changed, 92 insertions, 4 deletions
diff --git a/search/search_engine_pylib/README.txt b/search/search_engine_pylib/README.txt new file mode 100644 index 0000000000..afd8f68a53 --- /dev/null +++ b/search/search_engine_pylib/README.txt @@ -0,0 +1,37 @@ +This document describes how to use this module. + +1. How to build? + + To build the module you need Python2.7 and Boost Python. Also, you + need Qt5.5 (or higher), but you need it in any case, if you're + planning to build the project. On MacOS, Python2.7 should be + installed by default, to get Boost via Brew just type in the shell: + + brew update + brew install boost --with-python + brew install boost-python + + On Debian, type in the shell: + + sudo apt-get install libboost-* + + Note that on MacOS Boost is built by default with libc++, on Debian + Boost is built by default with libstdc++. Therefore, you can use + only macx-clang and linux-clang specs correspondingly. It's wrong + to use linux-clang-libc++ because it's generally a bad idea to have + two implementations of the C++ standard library in the same + application. + + Then, invoke qmake from the shell, for example: + + qmake CONFIG+=search_engine_pylib path-to-omim.pro + make -k -j8 all + +2. How to use? + + As search_engine_pylib is a custom Python module, all that you need + is to customize PYTHONPATH environment variable before running your + scripts. For example: + + PYTHONPATH=path-to-the-directory-with-search_engine_pylib.so \ + ./search/search_engine_pylib/run_search_engine.py diff --git a/search/search_engine_pylib/api.cpp b/search/search_engine_pylib/api.cpp index 6eef117cdc..f899c3d831 100644 --- a/search/search_engine_pylib/api.cpp +++ b/search/search_engine_pylib/api.cpp @@ -78,7 +78,7 @@ struct LatLon string ToString() const { ostringstream os; - os << "lat:" << m_lat << ", lon:" << m_lon; + os << "lat: " << m_lat << ", lon: " << m_lon; return os.str(); } @@ -168,7 +168,7 @@ struct SearchEngineProxy { SearchEngineProxy() { - CHECK(g_storage.get() != nullptr, ("init() is not called.")); + CHECK(g_storage.get() != nullptr, ("init() was not called.")); auto & platform = GetPlatform(); auto infoGetter = storage::CountryInfoReader::CreateCountryInfoReader(platform); infoGetter->InitAffiliationsInfo(&g_storage->GetAffiliations()); @@ -208,6 +208,7 @@ struct SearchEngineProxy results.append(Result(result)); return results; } + shared_ptr<search::tests_support::TestSearchEngine> m_engine; }; } // namespace diff --git a/search/search_engine_pylib/run_search_engine.py b/search/search_engine_pylib/run_search_engine.py new file mode 100755 index 0000000000..73f18506bd --- /dev/null +++ b/search/search_engine_pylib/run_search_engine.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- + +from __future__ import print_function +import argparse +import os +import search_engine_pylib as search + + +DIR = os.path.dirname(__file__) +RESOURCE_PATH = os.path.realpath(os.path.join(DIR, '..', '..', 'data')) +MWM_PATH = os.path.realpath(os.path.join(DIR, '..', '..', 'data')) + +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument('-r', metavar='RESOURCE_PATH', default=RESOURCE_PATH, help='Path to resources directory.') +parser.add_argument('-m', metavar='MWM_PATH', default=MWM_PATH, help='Path to mwm files.') +args = parser.parse_args() + +search.init(args.r, args.m) +engine = search.SearchEngine() + +params = search.Params() +params.query = 'кафе юность' +params.locale = 'ru' +params.lat_lon = search.LatLon(55.751633, 37.618705) +params.viewport = search.Viewport(search.Mercator(37.1336, 67.1349), + search.Mercator(38.0314, 67.7348)) +for result in engine.query(params): + print(result.to_string()) diff --git a/search/search_engine_pylib/search_engine_pylib.pro b/search/search_engine_pylib/search_engine_pylib.pro index 469ca97d3e..4e64bf1de1 100644 --- a/search/search_engine_pylib/search_engine_pylib.pro +++ b/search/search_engine_pylib/search_engine_pylib.pro @@ -18,11 +18,32 @@ INCLUDEPATH -= $$ROOT_DIR/3party/boost # We do not support search_engine_pylib for other combinations of # OS and c++ standard library. macx-clang { - INCLUDEPATH += /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 - LIBS += -L/System/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7 + QMAKE_LFLAGS_PLUGIN += -bundle + + LIBRARY_PYTHON=/Library/Frameworks/Python.framework/Versions/2.7 + SYSTEM_LIBRARY_PYTHON=/System/Library/Frameworks/Python.framework/Versions/2.7 + + exists($$LIBRARY_PYTHON) { + INCLUDEPATH += $$LIBRARY_PYTHON/include/python2.7 + LIBS += -L$$LIBRARY_PYTHON/lib -lpython2.7 + } else:exists($$SYSTEM_LIBRARY_PYTHON) { + INCLUDEPATH += $$SYSTEM_LIBRARY_PYTHON/include/python2.7 + LIBS += -L$$SYSTEM_LIBRARY_PYTHON/lib -lpython2.7 + } else { + error("Can't find Python2.7") + } + + LIBS *= "-framework IOKit" + LIBS *= "-framework SystemConfiguration" + + LIBS *= -L/usr/local/opt/qt5/lib + LIBS *= "-framework QtCore" + LIBS *= "-framework QtNetwork" INCLUDEPATH += /usr/local/include LIBS += -L/usr/local/lib -lboost_python + + INCLUDEPATH += /usr/local/opt/qt5/include } else:linux-clang { INCLUDEPATH += /usr/include LIBS += -L/usr/lib/x86_64-linux-gnu/ -lboost_python |