Skip to content

Commit

Permalink
Remove levenshtein
Browse files Browse the repository at this point in the history
  • Loading branch information
maneeshpm committed Feb 23, 2021
1 parent 7a393df commit 38f5752
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 86 deletions.
31 changes: 0 additions & 31 deletions src/levenshtein.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions src/levenshtein.h

This file was deleted.

1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ endif
xapian_sources = [
'search.cpp',
'search_iterator.cpp',
'levenshtein.cpp',
'xapian/htmlparse.cc',
'xapian/myhtmlparse.cc',
'writer/xapianIndexer.cpp',
Expand Down
46 changes: 1 addition & 45 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <zim/item.h>
#include "fileimpl.h"
#include "search_internal.h"
#include "levenshtein.h"
#include "fs.h"

#include <sstream>
Expand Down Expand Up @@ -115,23 +114,6 @@ setup_queryParser(Xapian::QueryParser* queryparser,
}
}

class LevenshteinDistanceMaker : public Xapian::KeyMaker {
public:
LevenshteinDistanceMaker(const std::string& query, size_t value_index):
query(query),
value_index(value_index) {}
~LevenshteinDistanceMaker() = default;

virtual std::string operator() (const Xapian::Document &doc) const {
auto document_value = doc.get_value(value_index);
return Xapian::sortable_serialise(
levenshtein_distance(document_value, query));
}
private:
std::string query;
size_t value_index;
};

}

Search::Search(const std::vector<Archive>& archives) :
Expand Down Expand Up @@ -235,8 +217,6 @@ Search& Search::set_suggestion_mode(const bool suggestion_mode) {
return *this;
}

#define WITH_LEV 1

Search::iterator Search::begin() const {
if ( this->search_started ) {
return new search_iterator::InternalData(this, internal->results.begin());
Expand Down Expand Up @@ -364,9 +344,6 @@ Search::iterator Search::begin() const {
delete queryParser;

Xapian::Enquire enquire(internal->database);
#if WITH_LEV
std::unique_ptr<Xapian::KeyMaker> keyMaker(nullptr);
#endif

if (geo_query && valuesmap.find("geo.position") != valuesmap.end()) {
Xapian::GreatCircleMetric metric;
Expand All @@ -392,29 +369,8 @@ Search::iterator Search::begin() const {
enquire.set_weighting_scheme(Xapian::BM25Weight(0.001,0,1,1,0.5));
enquire.set_sort_by_relevance_then_value(valuesmap["title"], false);
}
enquire.set_query(query);

#if WITH_LEV
if (suggestion_mode && !hasNewSuggestionFormat) {
size_t value_index = 0;
bool has_custom_distance_maker = true;
if ( !valuesmap.empty() ) {
if ( valuesmap.find("title") != valuesmap.end() ) {
value_index = valuesmap["title"];
} else {
// This should not happen as valuesmap has a title entry, but let's
// be tolerent.
has_custom_distance_maker = false;
}
}
auto temp_results = enquire.get_mset(0,0);
if ( has_custom_distance_maker
&& temp_results.get_matches_estimated() <= MAX_MATCHES_TO_SORT ) {
keyMaker.reset(new LevenshteinDistanceMaker(this->query, value_index));
enquire.set_sort_by_key(keyMaker.get(), false);
}
}
#endif
enquire.set_query(query);

if (suggestion_mode && valuesmap.find("title") != valuesmap.end()) {
enquire.set_collapse_key(valuesmap["title"]);
Expand Down

0 comments on commit 38f5752

Please sign in to comment.