Ticket #340: patch
File patch, 6.2 KB (added by , 16 years ago) |
---|
-
matcher/externalpostlist.cc
25 25 26 26 #include <xapian/postingsource.h> 27 27 28 #include "multimatch.h" 28 29 #include "omassert.h" 29 30 #include "omdebug.h" 30 31 … … 32 33 33 34 ExternalPostList::ExternalPostList(const Xapian::Database & db, 34 35 Xapian::PostingSource *source_, 35 double factor_) 36 : source(source_), source_is_owned(false), current(0), factor(factor_) 36 double factor_, 37 MultiMatch * matcher_) 38 : source(source_), source_is_owned(false), current(0), factor(factor_), 39 matcher(matcher_) 37 40 { 38 41 Assert(source); 39 42 Xapian::PostingSource * newsource = source->clone(); … … 51 54 } 52 55 } 53 56 57 void 58 ExternalPostList::notify_new_maxweight() 59 { 60 matcher->recalc_maxweight(); 61 } 62 54 63 Xapian::doccount 55 64 ExternalPostList::get_termfreq_min() const 56 65 { -
matcher/queryoptimiser.cc
68 68 Assert(query->external_source); 69 69 Xapian::Database wrappeddb(new ConstDatabaseWrapper(&db)); 70 70 RETURN(new ExternalPostList(wrappeddb, 71 query->external_source, factor)); 71 query->external_source, factor, 72 matcher)); 72 73 } 73 74 74 75 case Xapian::Query::OP_AND: -
matcher/externalpostlist.h
28 28 class PostingSource; 29 29 } 30 30 31 class MultiMatch; 32 31 33 class ExternalPostList : public PostList { 32 34 Xapian::PostingSource * source; 33 35 bool source_is_owned; … … 36 38 37 39 double factor; 38 40 41 /// The matcher to notify when maximum weights change. 42 MultiMatch * matcher; 43 39 44 /// Disallow copying. 40 45 ExternalPostList(const ExternalPostList &); 41 46 … … 47 52 public: 48 53 ExternalPostList(const Xapian::Database & db, 49 54 Xapian::PostingSource *source_, 50 double factor_); 55 double factor_, 56 MultiMatch * matcher_); 51 57 ~ExternalPostList(); 52 58 59 void notify_new_maxweight(); 60 53 61 Xapian::doccount get_termfreq_min() const; 54 62 55 63 Xapian::doccount get_termfreq_est() const; -
docs/postingsource.rst
1 1 2 2 .. Copyright (C) 2008,2009 Olly Betts 3 .. Copyright (C) 2009 Lemur Consulting Ltd 3 4 4 5 ===================== 5 6 Xapian::PostingSource … … 72 73 These methods have default implementations which always return 0, for 73 74 convenience when deriving "weight-less" subclasses. 74 75 76 If the maximum weight that can be returned by the PostingSource has decreased 77 significantly, it may be worthwhile to notify the Xapian matcher about this, so 78 that it can use this information for optmisations, allowing the match process 79 to finish faster. You can notify the matcher about this by calling the 80 ``PostingSource::notify_new_maxweight()`` method. However, you should take 81 care not to call this method too frequently, as the resulting computation can 82 be moderately expensive. 83 84 It is therefore advisable only to call this after a significant decrease in 85 maxweight. Profiling your postingsource will often be the best way to 86 determine how often to call it. If it's cheap to calculate the maxweight in 87 your posting source, a reasonable strategy is to decide a maximum number of 88 times to call this method (eg, 10) and then to call it whenever 89 ``floor(new_maxweight * 10 / original_maxweight)`` changes; this ensures that 90 only reasonably significant drops result in a recalculation of the weights. 91 Alternatively, you could simply impose a lower limit on the number of documents 92 processed before re-calling this. 93 75 94 The ``at_end()`` method checks if the current iteration position is past the 76 95 last entry:: 77 96 -
include/xapian/postingsource.h
29 29 #include <string> 30 30 #include <map> 31 31 32 // Declaration of an opaque internal type. 33 class ExternalPostList; 34 32 35 namespace Xapian { 33 36 34 37 /** Base class which provides an "external" source of postings. … … 43 46 /// Don't allow copying. 44 47 PostingSource(const PostingSource &); 45 48 49 /// The ExternalPostList which notifications should be sent to. 50 ExternalPostList * externalpl; 51 52 /// Set a pointer to the external postlist. 53 void register_externalpl(ExternalPostList * externalpl_) { 54 externalpl = externalpl_; 55 } 56 57 // ExternalPostList needs to be able to call register_externalpl. 58 friend class ::ExternalPostList; 59 46 60 protected: 47 61 /// Allow subclasses to be instantiated. 48 62 PostingSource() { } 49 63 64 /** Notify the matcher that the maximum weight has decreased. 65 * 66 * This will potentially cause the maxweights throughout the query tree 67 * to be re-evaluated, and can therefore be quite expensive. On the 68 * other hand, it will allow the new reduced maxweight to be used to 69 * trigger query optimisations, which can greatly reduce the query 70 * processing time. 71 * 72 * It is therefore advisable only to call this after a significant 73 * decrease in maxweight. 74 */ 75 void notify_new_maxweight(); 76 50 77 public: 51 78 // Destructor. 52 79 virtual ~PostingSource(); -
api/postingsource.cc
27 27 28 28 #include "database.h" 29 29 #include "document.h" 30 #include "matcher/externalpostlist.h" 31 30 32 #include "xapian/document.h" 31 33 #include "xapian/error.h" 32 34 #include "xapian/queryparser.h" // For sortable_unserialise(). … … 40 42 41 43 namespace Xapian { 42 44 45 void 46 PostingSource::notify_new_maxweight() 47 { 48 externalpl->notify_new_maxweight(); 49 } 50 43 51 PostingSource::~PostingSource() { } 44 52 45 53 Xapian::weight