You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2017/01/02 15:46:28 UTC
[11/14] lucy git commit: Add TestUtils_create_index
Add TestUtils_create_index
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/2b905009
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/2b905009
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/2b905009
Branch: refs/heads/master
Commit: 2b905009e69fccfc8abe62cfe7814565f15beab5
Parents: 3dfb22c
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Dec 24 16:13:26 2016 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Jan 2 16:33:57 2017 +0100
----------------------------------------------------------------------
test/Lucy/Test/Search/TestQueryParserLogic.c | 26 ++-----------
test/Lucy/Test/TestUtils.c | 45 +++++++++++++++++++++++
test/Lucy/Test/TestUtils.cfh | 11 ++++++
3 files changed, 60 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/2b905009/test/Lucy/Test/Search/TestQueryParserLogic.c
----------------------------------------------------------------------
diff --git a/test/Lucy/Test/Search/TestQueryParserLogic.c b/test/Lucy/Test/Search/TestQueryParserLogic.c
index 22104fd..91413be 100644
--- a/test/Lucy/Test/Search/TestQueryParserLogic.c
+++ b/test/Lucy/Test/Search/TestQueryParserLogic.c
@@ -25,11 +25,8 @@
#include "Lucy/Test.h"
#include "Lucy/Test/Search/TestQueryParserLogic.h"
#include "Lucy/Test/Search/TestQueryParser.h"
-#include "Lucy/Test/TestSchema.h"
#include "Lucy/Test/TestUtils.h"
#include "Lucy/Analysis/Analyzer.h"
-#include "Lucy/Document/Doc.h"
-#include "Lucy/Index/Indexer.h"
#include "Lucy/Search/Hits.h"
#include "Lucy/Search/IndexSearcher.h"
#include "Lucy/Search/QueryParser.h"
@@ -42,7 +39,7 @@
#include "Lucy/Search/NoMatchQuery.h"
#include "Lucy/Search/ORQuery.h"
#include "Lucy/Search/RequiredOptionalQuery.h"
-#include "Lucy/Store/RAMFolder.h"
+#include "Lucy/Store/Folder.h"
#define make_leaf_query (Query*)TestUtils_make_leaf_query
#define make_not_query (Query*)TestUtils_make_not_query
@@ -859,26 +856,11 @@ static LUCY_TestQPLogic_Prune_Test_t prune_test_funcs[] = {
static Folder*
S_create_index() {
- Schema *schema = (Schema*)TestSchema_new(false);
- RAMFolder *folder = RAMFolder_new(NULL);
- Vector *doc_set = TestUtils_doc_set();
- Indexer *indexer = Indexer_new(schema, (Obj*)folder, NULL, 0);
-
- String *field = SSTR_WRAP_C("content");
- for (size_t i = 0, max = Vec_Get_Size(doc_set); i < max; i++) {
- Doc *doc = Doc_new(NULL, 0);
- Doc_Store(doc, field, Vec_Fetch(doc_set, i));
- Indexer_Add_Doc(indexer, doc, 1.0f);
- DECREF(doc);
- }
-
- Indexer_Commit(indexer);
+ Vector *doc_set = TestUtils_doc_set();
+ Folder *folder = TestUtils_create_index(doc_set);
DECREF(doc_set);
- DECREF(indexer);
- DECREF(schema);
-
- return (Folder*)folder;
+ return folder;
}
void
http://git-wip-us.apache.org/repos/asf/lucy/blob/2b905009/test/Lucy/Test/TestUtils.c
----------------------------------------------------------------------
diff --git a/test/Lucy/Test/TestUtils.c b/test/Lucy/Test/TestUtils.c
index bddfa7b..0f579b0 100644
--- a/test/Lucy/Test/TestUtils.c
+++ b/test/Lucy/Test/TestUtils.c
@@ -21,11 +21,14 @@
#include "Lucy/Test/TestUtils.h"
#include "Lucy/Test.h"
+#include "Lucy/Test/TestSchema.h"
#include "Clownfish/TestHarness/TestBatchRunner.h"
#include "Clownfish/TestHarness/TestUtils.h"
#include "Lucy/Analysis/Analyzer.h"
#include "Lucy/Analysis/Inversion.h"
#include "Lucy/Analysis/Token.h"
+#include "Lucy/Document/Doc.h"
+#include "Lucy/Index/Indexer.h"
#include "Lucy/Search/TermQuery.h"
#include "Lucy/Search/PhraseQuery.h"
#include "Lucy/Search/LeafQuery.h"
@@ -37,6 +40,7 @@
#include "Lucy/Store/InStream.h"
#include "Lucy/Store/OutStream.h"
#include "Lucy/Store/RAMFile.h"
+#include "Lucy/Store/RAMFolder.h"
#include "Lucy/Util/Freezer.h"
Vector*
@@ -54,6 +58,47 @@ TestUtils_doc_set() {
return docs;
}
+Folder*
+TestUtils_create_index(Vector *doc_set) {
+ Schema *schema = (Schema*)TestSchema_new(false);
+ RAMFolder *folder = RAMFolder_new(NULL);
+ Indexer *indexer = Indexer_new(schema, (Obj*)folder, NULL, 0);
+
+ String *field = SSTR_WRAP_C("content");
+ for (size_t i = 0, max = Vec_Get_Size(doc_set); i < max; i++) {
+ Doc *doc = Doc_new(NULL, 0);
+ Doc_Store(doc, field, Vec_Fetch(doc_set, i));
+ Indexer_Add_Doc(indexer, doc, 1.0f);
+ DECREF(doc);
+ }
+
+ Indexer_Commit(indexer);
+
+ DECREF(indexer);
+ DECREF(schema);
+
+ return (Folder*)folder;
+}
+
+Folder*
+TestUtils_create_index_c(const char *first, ...) {
+ Vector *doc_set = Vec_new(1);
+ Vec_Push(doc_set, (Obj*)Str_new_from_utf8(first, strlen(first)));
+
+ va_list ap;
+ va_start(ap, first);
+ const char *next;
+ while ((next = va_arg(ap, const char*))) {
+ Vec_Push(doc_set, (Obj*)Str_new_from_utf8(next, strlen(next)));
+ }
+ va_end(ap);
+
+ Folder *folder = TestUtils_create_index(doc_set);
+
+ DECREF(doc_set);
+ return folder;
+}
+
PolyQuery*
TestUtils_make_poly_query(uint32_t boolop, ...) {
va_list args;
http://git-wip-us.apache.org/repos/asf/lucy/blob/2b905009/test/Lucy/Test/TestUtils.cfh
----------------------------------------------------------------------
diff --git a/test/Lucy/Test/TestUtils.cfh b/test/Lucy/Test/TestUtils.cfh
index 0d3e15c..00d50c4 100644
--- a/test/Lucy/Test/TestUtils.cfh
+++ b/test/Lucy/Test/TestUtils.cfh
@@ -24,6 +24,17 @@ inert class Lucy::Test::TestUtils {
inert incremented Vector*
doc_set();
+ /** Create an index using TestSchema with documents from `doc_set`.
+ */
+ inert incremented Folder*
+ create_index(Vector *doc_set);
+
+ /** Create an index using TestSchema with documents from a list
+ * of C strings terminated with NULL.
+ */
+ inert incremented Folder*
+ create_index_c(const char *first, ...);
+
/** Testing-only TermQuery factory.
*/
inert incremented TermQuery*