Ticket #473: postingiterator-from-query-wip.patch
| File postingiterator-from-query-wip.patch, 5.5 KB (added by , 9 days ago) |
|---|
-
xapian-core/api/database.cc
commit bfcef51795c034d31fe3cd6595484f176c4d4b4a Author: Olly Betts <olly@survex.com> Date: Mon Feb 23 13:21:22 2026 +1300 WIP diff --git a/xapian-core/api/database.cc b/xapian-core/api/database.cc index 5e36a50dfc6d..1cc7d0de1671 100644a b Database::postlist_begin(string_view term) const 196 196 return PostingIterator(new PostingIterator::Internal(pl, *this)); 197 197 } 198 198 199 PostingIterator 200 Database::postlist_begin(const Xapian::Query& query, bool prestart) const 201 { 202 PostList* pl = internal->open_post_list(query, prestart); 203 if (!pl) return PostingIterator(); 204 return PostingIterator(new PostingIterator::Internal(pl, *this)); 205 } 206 199 207 TermIterator 200 208 Database::termlist_begin(Xapian::docid did) const 201 209 { -
xapian-core/api/postingiteratorinternal.h
diff --git a/xapian-core/api/postingiteratorinternal.h b/xapian-core/api/postingiteratorinternal.h index e85020d623e4..a8a44501be16 100644
a b class PostingIterator::Internal { 69 69 } 70 70 71 71 bool next() { 72 (void)pl->next(); 72 auto prune = pl->next(); 73 if (rare(prune)) { 74 delete pl; 75 pl = prune; 76 } 73 77 return !pl->at_end(); 74 78 } 75 79 76 80 bool skip_to(Xapian::docid did) { 77 (void)pl->skip_to(did); 81 auto prune = pl->skip_to(did); 82 if (rare(prune)) { 83 delete pl; 84 pl = prune; 85 } 78 86 return !pl->at_end(); 79 87 } 80 88 -
xapian-core/backends/databaseinternal.cc
diff --git a/xapian-core/backends/databaseinternal.cc b/xapian-core/backends/databaseinternal.cc index 43bc9970f219..e5b608c0e0ff 100644
a b 25 25 26 26 #include "api/termlist.h" 27 27 #include "heap.h" 28 #include "matcher/localsubmatch.h" 29 #include "matcher/postlisttree.h" 28 30 #include "omassert.h" 29 31 #include "postlist.h" 30 32 #include "slowvaluelist.h" … … Database::Internal::get_unique_terms_upper_bound() const 77 79 return get_doclength_upper_bound(); 78 80 } 79 81 82 PostList* 83 Database::Internal::open_post_list(const Query& query, bool prestart) const 84 { 85 // FIXME: query_length wtscheme 86 Xapian::termcount query_length = query.get_length(); 87 // FIXME: Move to Enquire? 88 // FIXME: Also need special implementations for multi and remote (or UnimplementedError) 89 BoolWeight wtscheme; 90 LocalSubMatch localsubmatch(this, query, query_length, wtscheme, 0); 91 Xapian::Database db(const_cast<Database::Internal*>(this)); 92 93 // FIXME: Need to arrange for these to be deleted. 94 ValueStreamDocument* vsdoc = new ValueStreamDocument{db}; 95 PostListTree* pltree = new PostListTree(*vsdoc, db, wtscheme); 96 97 Xapian::termcount total_subqs_i = 0; 98 auto plest = localsubmatch.get_postlist(pltree, &total_subqs_i); 99 PostList* pl = plest.pl; 100 if (!prestart) { 101 auto prune = pl->next(); 102 if (rare(prune)) { 103 delete pl; 104 pl = prune; 105 } 106 } 107 return pl; 108 } 109 80 110 // Discard any exceptions - we're called from the destructors of derived 81 111 // classes so we can't safely throw. 82 112 void -
xapian-core/backends/databaseinternal.h
diff --git a/xapian-core/backends/databaseinternal.h b/xapian-core/backends/databaseinternal.h index 67d95f502cd7..e36da3c4b9ca 100644
a b class Database::Internal : public Xapian::Internal::intrusive_base { 218 218 /** Return a PostList suitable for use in a PostingIterator. */ 219 219 virtual PostList* open_post_list(std::string_view term) const = 0; 220 220 221 /*virtual*/ PostList* open_post_list(const Query& query, bool prestart) const; 222 221 223 /** Create a LeafPostList for use during a match. 222 224 * 223 225 * @param term The term to open a postlist for, or the empty -
xapian-core/include/xapian/database.h
diff --git a/xapian-core/include/xapian/database.h b/xapian-core/include/xapian/database.h index 2a15fe6b9283..3e2c4f626e3a 100644
a b namespace Xapian { 47 47 48 48 class Compactor; 49 49 class Document; 50 class Query; 50 51 class WritableDatabase; 51 52 52 53 /** An indexed database of documents. … … class XAPIAN_VISIBILITY_DEFAULT Database { 260 261 return PostingIterator(); 261 262 } 262 263 264 PostingIterator postlist_begin(const std::string& term) const { 265 return postlist_begin(std::string_view{term}); 266 } 267 268 /** End iterator corresponding to postlist_begin(). */ 269 PostingIterator postlist_end(const std::string&) const noexcept { 270 return PostingIterator(); 271 } 272 273 /** Start iterating the postings of a Query object. 274 * 275 * This returns the document ids matching a query. The key difference 276 * compared to Enquire::get_mset() are that it can only return in 277 * ascending document id order. However get_mset() needs O(n) memory 278 * so this can be useful if you want to process a lot of results. 279 * 280 * @param query The query to iterate the postings from. 281 * @param prestart If true the returned iterator needs incrementing to 282 * be at the first result. This is mainly useful as 283 * you can call get_description() and see the results 284 * of Xapian's query optimisation. (Default: false) 285 * 286 * @since Added in 1.5.0. 287 */ 288 PostingIterator postlist_begin(const Xapian::Query& query, 289 bool prestart = false) const; 290 291 /** End iterator corresponding to postlist_begin(). */ 292 PostingIterator postlist_end(const Xapian::Query&, 293 bool = false) const noexcept { 294 return PostingIterator(); 295 } 296 263 297 /** Start iterating the terms in a document. 264 298 * 265 299 * @param did The document id to iterate terms from
