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>
8 : #include <ept/textsearch/textsearch.h>
9 : #include <ept/textsearch/maint/path.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 :
20 4 : struct XapianTestEnvironment : AptTestEnvironment {
21 : textsearch::Path::OverrideIndexDir oid;
22 : textsearch::TextSearch textsearch;
23 : apt::Apt apt;
24 4 : XapianTestEnvironment()
25 4 : : oid( TEST_ENV_DIR "xapian" )
26 : {
27 4 : ept::textsearch::max_index = 1000;
28 4 : textsearch.rebuildIfNeeded(apt);
29 4 : }
30 : };
31 :
32 4 : struct TestXapian : XapianTestEnvironment {
33 : xapian::Source xap;
34 : xapian::Query query;
35 :
36 4 : TestXapian() : query( xap.db() )
37 : {
38 4 : query = xap.query( "sgml tool" );
39 4 : }
40 :
41 1 : Test enquire() {
42 1 : query.updateEnquire();
43 1 : Xapian::MSet matches = query.m_enq.get_mset(0, 100);
44 1 : assert( matches.size() > 0 );
45 2 : assert_eq( matches.begin().get_document().get_data(), "psgml" );
46 1 : }
47 :
48 1 : Test listCount() {
49 1 : xapian::List l( query.results() );
50 1 : Xapian::MSet matches = query.m_enq.get_mset(0, 6000);
51 1 : assert_eq( list::count( l ), matches.size() );
52 1 : }
53 :
54 : template< typename List >
55 1 : void checkXapianList( List l, Xapian::MSet m ) {
56 1 : Xapian::MSet::const_iterator i = m.begin();
57 16 : while (! l.empty() ) {
58 14 : assert_eq( l.token().package(), i.get_document().get_data() );
59 14 : l = l.tail();
60 15 : ++ i;
61 : }
62 1 : }
63 :
64 1 : Test list() {
65 1 : xapian::List l( query.results() );
66 1 : Xapian::MSet matches = query.m_enq.get_mset(0, 6000);
67 1 : checkXapianList( l, matches );
68 1 : }
69 :
70 1 : Test checkQuery() {
71 1 : assert_eq( xap.query( "sgml tool" ).results().token().package(), "psgml" );
72 1 : }
73 :
74 : };
|