libept
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 };