Add explicit conversion to std::string#1019
Conversation
In Xapian 2.0.x most API methods which previously took std::string or const std::string& now take std::string_view, which can avoid the need to copy data which isn't already in a std::string. That causes a compilation failure here - the compiler knows how to convert zim::Formatter to std::string and how to convert std::string to std::string_view but it isn't allowed to chain implicit conversions.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1019 +/- ##
=======================================
Coverage 56.18% 56.18%
=======================================
Files 101 101
Lines 4989 4989
Branches 2170 2170
=======================================
Hits 2803 2803
Misses 739 739
Partials 1447 1447 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
To the best of my knowledge the word count is only used to decorate the search results with additional info about the documents with a match. Currently there is no support for sorting/filtering the search results based on word count. |
In Xapian 2.0.x most API methods which previously took std::string or const std::string& now take std::string_view, which can avoid the need to copy data which isn't already in a std::string.
That causes a compilation failure here - the compiler knows how to convert zim::Formatter to std::string and how to convert std::string to std::string_view but it isn't allowed to chain implicit conversions.
We could use https://en.cppreference.com/w/cpp/io/basic_ostringstream/view.html to add a conversion to
std::string_viewtozim::Formatter, but that was added in C++20 andmeson.buildcurrently requires C++17. I don't see a good way to add a conversion operator which works for older C++ standards.Incidentally, storing the word count in a value slot in this way doesn't seem the best idea. Sorting by value performs a string sort, so sorting by word count would currently give e.g.
999999>9>80>700>6000>50000>400000>3000000>20000000>1000000.Xapian::sortable_serialise()encodes numbers as strings which sorts the same way as the numbers do, but a switch to that would presumably need to consider how to handle existing databases.