Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Oded Arbel
Baloo
Commits
87293131
Commit
87293131
authored
Mar 02, 2015
by
Pinak Ahuja
Browse files
FileSearchStoreTest wip
Throws an exception which needs to be fixed
parent
4fb05eb0
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lib/CMakeLists.txt
View file @
87293131
set
(
BALOO_LIB_SRCS
#
searchstore.cpp
#
term.cpp
#
query.cpp
searchstore.cpp
term.cpp
query.cpp
#queryrunnable.cpp
#
resultiterator.cpp
#
result.cpp
#
advancedqueryparser.cpp
resultiterator.cpp
result.cpp
advancedqueryparser.cpp
#file.cpp
filemapping.cpp
...
...
@@ -23,7 +23,8 @@ set(BALOO_LIB_SRCS
#xapiansearchstore.cpp
#wildcardpostingsource.cpp
#pathfilterpostingsource.cpp
#filesearchstore.cpp
filesearchstore.cpp
lucenesearchstore.cpp
)
add_library
(
KF5Baloo
${
BALOO_LIB_SRCS
}
)
...
...
@@ -35,12 +36,14 @@ target_link_libraries(KF5Baloo
Qt5::Core
KF5::CoreAddons
KF5::FileMetaData
${
LucenePlusPlus_LIBRARIES
}
PRIVATE
KF5::ConfigCore
Qt5::DBus
KF5::Solid
KF5::BalooLucene
KF5::BalooXapian
)
set_target_properties
(
KF5Baloo PROPERTIES
...
...
@@ -84,5 +87,5 @@ install(FILES
COMPONENT Devel
)
add_subdirectory
(
tests
)
#
add_subdirectory(tests)
add_subdirectory
(
autotests
)
src/lib/autotests/CMakeLists.txt
View file @
87293131
#
# Query Serialization
#
set
(
querySerialization_SRC queryserializationtest.cpp
)
#[[
set(querySerialization_SRC queryserializationtest.cpp)
ecm_add_test(${querySerialization_SRC}
TEST_NAME "queryserializationtest"
...
...
@@ -51,18 +51,15 @@ ecm_add_test(taglistjobtest.cpp
Qt5::Test
KF5::Baloo
)
]]
#
# Search Store
#
set
(
filesearchstore_SRCS filesearchstoretest.cpp
../filesearchstore.cpp
../pathfilterpostingsource.cpp
../wildcardpostingsource.cpp
../filemapping.cpp
../
xapian
searchstore.cpp
../
lucene
searchstore.cpp
../searchstore.cpp
../../file/database.cpp
)
ecm_add_test
(
${
filesearchstore_SRCS
}
...
...
@@ -74,12 +71,15 @@ ecm_add_test(${filesearchstore_SRCS}
KF5::FileMetaData
KF5::Baloo
KF5::BalooXapian
KF5::BalooLucene
${
LucenePlusPlus_LIBRARIES
}
)
ecm_add_test
(
filemappingbenchmark.cpp
#[[
ecm_add_test(filemappingbenchmark.cpp
TEST_NAME "filemappingbenchmark"
LINK_LIBRARIES
Qt5::Test
KF5::Baloo
baloofilecommon
)
]]
\ No newline at end of file
src/lib/autotests/filesearchstoretest.cpp
View file @
87293131
...
...
@@ -22,15 +22,14 @@
#include
"filesearchstoretest.h"
#include
"filesearchstore.h"
#include
"../../file/database.h"
#include
"filemapping.h"
#include
"query.h"
#include
"term.h"
#include
"lucenedocument.h"
#include
<QDebug>
#include
<QtTest>
#include
<xapian.h>
#include
<kfilemetadata/properties.h>
#include
<kfilemetadata/propertyinfo.h>
...
...
@@ -40,7 +39,7 @@ using namespace Baloo;
FileSearchStoreTest
::
FileSearchStoreTest
(
QObject
*
parent
)
:
QObject
(
parent
)
,
m_tempDir
(
0
)
,
m_
db
(
0
)
,
m_
index
(
0
)
,
m_store
(
0
)
{
}
...
...
@@ -49,13 +48,12 @@ void FileSearchStoreTest::init()
{
cleanupTestCase
();
m_db
=
new
Database
(
this
);
m_tempDir
=
new
QTemporaryDir
();
m_db
->
setPath
(
m_tempDir
->
path
())
;
m_
db
->
init
(
);
m_store
=
new
FileSearchStore
(
this
);
m_store
->
setDbPath
(
m_tempDir
->
path
());
if
(
m_tempDir
->
isValid
())
{
m_
index
=
new
LuceneIndex
(
m_tempDir
->
path
()
);
m_store
=
new
FileSearchStore
(
this
);
m_store
->
setIndexPath
(
m_tempDir
->
path
()
);
}
}
void
FileSearchStoreTest
::
initTestCase
()
...
...
@@ -67,8 +65,8 @@ void FileSearchStoreTest::cleanupTestCase()
delete
m_store
;
m_store
=
0
;
delete
m_
db
;
m_
db
=
0
;
delete
m_
index
;
m_
index
=
0
;
delete
m_tempDir
;
m_tempDir
=
0
;
...
...
@@ -76,90 +74,48 @@ void FileSearchStoreTest::cleanupTestCase()
uint
FileSearchStoreTest
::
insertUrl
(
const
QString
&
url
)
{
Xapian
::
Document
doc
;
doc
.
add_value
(
3
,
url
.
toUtf8
().
constData
());
std
::
string
dir
=
m_tempDir
->
path
().
toUtf8
().
constData
();
QScopedPointer
<
Xapian
::
WritableDatabase
>
wdb
(
new
Xapian
::
WritableDatabase
(
dir
,
Xapian
::
DB_CREATE_OR_OPEN
));
int
id
=
wdb
->
add_document
(
doc
);
wdb
->
commit
();
m_db
->
xapianDatabase
()
->
db
()
->
reopen
();
return
id
;
LuceneDocument
doc
;
doc
.
addIndexedField
(
"URL"
,
url
);
m_index
->
addDocument
(
doc
);
m_index
->
commit
();
FileMapping
map
(
url
);
map
.
fetch
(
m_index
->
IndexReader
());
return
map
.
id
();
}
void
FileSearchStoreTest
::
insertType
(
int
id
,
const
QString
&
type
)
{
Xapian
::
Document
doc
;
doc
.
add_term
((
"T"
+
type
.
toLower
()).
toUtf8
().
constData
());
std
::
string
dir
=
m_tempDir
->
path
().
toUtf8
().
constData
();
QScopedPointer
<
Xapian
::
WritableDatabase
>
wdb
(
new
Xapian
::
WritableDatabase
(
dir
,
Xapian
::
DB_CREATE_OR_OPEN
));
wdb
->
replace_document
(
id
,
doc
);
wdb
->
commit
();
m_db
->
xapianDatabase
()
->
db
()
->
reopen
();
LuceneDocument
doc
(
m_index
->
IndexReader
()
->
document
(
id
));
doc
.
addIndexedField
(
"T"
,
type
.
toLower
());
QString
url
=
doc
.
getFieldValues
(
"URL"
).
at
(
0
);
m_index
->
replaceDocument
(
url
,
doc
.
doc
());
m_index
->
commit
();
}
void
FileSearchStoreTest
::
insertExactText
(
int
id
,
const
QString
&
text
,
const
QString
&
prefix
)
{
Xapian
::
Document
doc
;
try
{
doc
=
m_db
->
xapianDatabase
()
->
db
()
->
get_document
(
id
);
}
catch
(...)
{
}
doc
.
add_term
((
prefix
+
text
).
toUtf8
().
constData
());
std
::
string
dir
=
m_tempDir
->
path
().
toUtf8
().
constData
();
QScopedPointer
<
Xapian
::
WritableDatabase
>
wdb
(
new
Xapian
::
WritableDatabase
(
dir
,
Xapian
::
DB_CREATE_OR_OPEN
));
wdb
->
replace_document
(
id
,
doc
);
wdb
->
commit
();
m_db
->
xapianDatabase
()
->
db
()
->
reopen
();
LuceneDocument
doc
(
m_index
->
IndexReader
()
->
document
(
id
));
doc
.
addIndexedField
(
prefix
,
text
);
m_index
->
replaceDocument
(
doc
.
getFieldValues
(
"URL"
).
at
(
0
),
doc
.
doc
());
m_index
->
commit
();
}
void
FileSearchStoreTest
::
insertText
(
int
id
,
const
QString
&
text
)
{
std
::
string
dir
=
m_tempDir
->
path
().
toUtf8
().
constData
();
QScopedPointer
<
Xapian
::
WritableDatabase
>
wdb
(
new
Xapian
::
WritableDatabase
(
dir
,
Xapian
::
DB_CREATE_OR_OPEN
));
Xapian
::
Document
doc
;
try
{
doc
=
wdb
->
get_document
(
id
);
}
catch
(...)
{
}
Xapian
::
TermGenerator
termGen
;
termGen
.
set_document
(
doc
);
termGen
.
index_text
(
text
.
toUtf8
().
constData
());
wdb
->
replace_document
(
id
,
doc
);
wdb
->
commit
();
m_db
->
xapianDatabase
()
->
db
()
->
reopen
();
LuceneDocument
doc
(
m_index
->
IndexReader
()
->
document
(
id
));
doc
.
indexText
(
text
);
m_index
->
replaceDocument
(
doc
.
getFieldValues
(
"URL"
).
at
(
0
),
doc
.
doc
());
m_index
->
commit
();
}
void
FileSearchStoreTest
::
insertRating
(
int
id
,
int
rating
)
{
Xapian
::
Document
doc
;
QString
str
=
QLatin1Char
(
'R'
)
+
QString
::
number
(
rating
);
doc
.
add_term
(
str
.
toUtf8
().
constData
());
std
::
string
dir
=
m_tempDir
->
path
().
toUtf8
().
constData
();
QScopedPointer
<
Xapian
::
WritableDatabase
>
wdb
(
new
Xapian
::
WritableDatabase
(
dir
,
Xapian
::
DB_CREATE_OR_OPEN
));
wdb
->
replace_document
(
id
,
doc
);
wdb
->
commit
();
m_db
->
xapianDatabase
()
->
db
()
->
reopen
();
LuceneDocument
doc
(
m_index
->
IndexReader
()
->
document
(
id
));
doc
.
addNumericField
(
"R"
,
rating
);
m_index
->
replaceDocument
(
doc
.
getFieldValues
(
"URL"
).
at
(
0
),
doc
.
doc
());
m_index
->
commit
();
}
...
...
@@ -197,7 +153,7 @@ void FileSearchStoreTest::testSimpleSearchString()
init
();
}
}
/*
void FileSearchStoreTest::testPropertyValueEqual()
{
QString url1(QLatin1String("/home/t/a"));
...
...
@@ -549,5 +505,5 @@ void FileSearchStoreTest::testDateTimeProperty()
QCOMPARE(m_store->id(qid), serialize("file", 1));
QVERIFY(!m_store->next(qid));
}
*/
QTEST_MAIN
(
Baloo
::
FileSearchStoreTest
)
src/lib/autotests/filesearchstoretest.h
View file @
87293131
...
...
@@ -25,6 +25,7 @@
#include
<QObject>
#include
<QTemporaryDir>
#include
"luceneindex.h"
class
Database
;
...
...
@@ -44,21 +45,21 @@ private Q_SLOTS:
void
cleanupTestCase
();
void
testSimpleSearchString
();
void
testPropertyValueEqual
();
void
testIncludeDir
();
void
testRatings
();
void
testEmptySearchString
();
void
testAllVideos
();
//
void testPropertyValueEqual();
//
void testIncludeDir();
//
void testRatings();
//
void testEmptySearchString();
//
void testAllVideos();
void
testFileNameSearch
();
void
testSortingNone
();
//
void testFileNameSearch();
//
void testSortingNone();
void
testInvalidProperties
();
void
testModifiedProperty
();
void
testDateTimeProperty
();
//
void testInvalidProperties();
//
void testModifiedProperty();
//
void testDateTimeProperty();
private:
QTemporaryDir
*
m_tempDir
;
Database
*
m_db
;
LuceneIndex
*
m_index
;
FileSearchStore
*
m_store
;
uint
insertUrl
(
const
QString
&
url
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment