libept  0.5.25
xapian.test.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 #include <ept/test.h>
3 #include <ept/core/list.h>
4 #include <ept/core/xapian.h>
5 
6 // TODO temporary, for building test database
7 #include <ept/apt/apt.h>
10 
11 using namespace ept;
12 using namespace core;
13 
14 namespace ept {
15 namespace textsearch {
16 extern size_t max_index;
17 }
18 }
19 
25  : oid( TEST_ENV_DIR "xapian" )
26  {
28  textsearch.rebuildIfNeeded(apt);
29  }
30 };
31 
35 
36  TestXapian() : query( xap.db() )
37  {
38  query = xap.query( "sgml tool" );
39  }
40 
41  Test enquire() {
42  query.updateEnquire();
43  Xapian::MSet matches = query.m_enq.get_mset(0, 100);
44  assert( matches.size() > 0 );
45  assert_eq( matches.begin().get_document().get_data(), "psgml" );
46  }
47 
48  Test listCount() {
49  xapian::List l( query.results() );
50  Xapian::MSet matches = query.m_enq.get_mset(0, 6000);
51  assert_eq( list::count( l ), matches.size() );
52  }
53 
54  template< typename List >
55  void checkXapianList( List l, Xapian::MSet m ) {
56  Xapian::MSet::const_iterator i = m.begin();
57  while (! l.empty() ) {
58  assert_eq( l.token().package(), i.get_document().get_data() );
59  l = l.tail();
60  ++ i;
61  }
62  }
63 
64  Test list() {
65  xapian::List l( query.results() );
66  Xapian::MSet matches = query.m_enq.get_mset(0, 6000);
67  checkXapianList( l, matches );
68  }
69 
70  Test checkQuery() {
71  assert_eq( xap.query( "sgml tool" ).results().token().package(), "psgml" );
72  }
73 
74 };
List results()
Definition: xapian.h:187
Test listCount()
Definition: xapian.test.h:48
void updateEnquire()
Definition: xapian.h:154
Definition: test.h:10
void checkXapianList(List l, Xapian::MSet m)
Definition: xapian.test.h:55
popcon paths
Query query(const std::string &s, bool expand=true, int qualityCutoff=50)
Definition: xapian.h:337
Definition: textsearch/maint/path.h:51
-*- C++ -*- (c) 2006, 2007 Petr Rockai me@mornfall.net
Definition: apt.cc:43
xapian::Source xap
Definition: xapian.test.h:33
xapian::Query query
Definition: xapian.test.h:34
textsearch::Path::OverrideIndexDir oid
Definition: xapian.test.h:21
bool rebuildIfNeeded(apt::Apt &apt, const std::vector< const ExtraIndexer * > &extraIndexers=std::vector< const ExtraIndexer * >())
Rebuild the index if needed.
Definition: textsearch.cc:81
Definition: xapian.h:247
std::string package() const
Definition: token.h:22
High-level access to the Apt cache, as a data provider for the ept framework.
Definition: apt/apt.h:60
Definition: xapian.h:35
High-level front-end to libapt-pkg, as a data provider for the ept framework.
Token token() const
Definition: xapian.h:49
Maintains and accesses a Xapian index of package descriptions.
Definition: textsearch.h:102
textsearch::TextSearch textsearch
Definition: xapian.test.h:22
Xapian::Enquire m_enq
Definition: xapian.h:99
Definition: xapian.h:97
apt::Apt apt
Definition: xapian.test.h:23
XapianTestEnvironment()
Definition: xapian.test.h:24
Test checkQuery()
Definition: xapian.test.h:70
size_t max_index
Definition: textsearch.cc:48
TestXapian()
Definition: xapian.test.h:36
Definition: xapian.test.h:32
Definition: xapian.test.h:20
Test enquire()
Definition: xapian.test.h:41
Test list()
Definition: xapian.test.h:64