[dovecot-cvs] dovecot/src/plugins/fts-lucene fts-backend-lucene.c, 1.8, 1.9 lucene-wrapper.cc, 1.9, 1.10 lucene-wrapper.h, 1.5, 1.6

tss at dovecot.org tss at dovecot.org
Fri Mar 16 00:20:58 EET 2007


Update of /var/lib/cvs/dovecot/src/plugins/fts-lucene
In directory talvi:/tmp/cvs-serv30017/fts-lucene

Modified Files:
	fts-backend-lucene.c lucene-wrapper.cc lucene-wrapper.h 
Log Message:
Separate headers and body in building and searching. Added support for
Lucene to index/search them separately.



Index: fts-backend-lucene.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts-lucene/fts-backend-lucene.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- fts-backend-lucene.c	20 Dec 2006 21:26:37 -0000	1.8
+++ fts-backend-lucene.c	15 Mar 2007 22:20:55 -0000	1.9
@@ -109,7 +109,7 @@
 static int
 fts_backend_lucene_build_more(struct fts_backend_build_context *ctx,
 			      uint32_t uid, const unsigned char *data,
-			      size_t size)
+			      size_t size, bool headers)
 {
 	struct lucene_fts_backend *backend =
 		(struct lucene_fts_backend *)ctx->backend;
@@ -122,7 +122,7 @@
 
 	i_assert(backend->lstorage->selected_box == backend->box);
 	return lucene_index_build_more(backend->lstorage->index,
-				       uid, data, size);
+				       uid, data, size, headers);
 }
 
 static int
@@ -167,14 +167,16 @@
 }
 
 static int
-fts_backend_lucene_lookup(struct fts_backend *_backend, const char *key,
-			 ARRAY_TYPE(seq_range) *result)
+fts_backend_lucene_lookup(struct fts_backend *_backend,
+			  enum fts_lookup_flags flags,
+			  const char *key, ARRAY_TYPE(seq_range) *result)
 {
 	struct lucene_fts_backend *backend =
 		(struct lucene_fts_backend *)_backend;
 
 	fts_backend_select(backend);
-	return lucene_index_lookup(backend->lstorage->index, key, result);
+	return lucene_index_lookup(backend->lstorage->index,
+				   flags, key, result);
 }
 
 struct fts_backend fts_backend_lucene = {

Index: lucene-wrapper.cc
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts-lucene/lucene-wrapper.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- lucene-wrapper.cc	15 Mar 2007 21:46:26 -0000	1.9
+++ lucene-wrapper.cc	15 Mar 2007 22:20:55 -0000	1.10
@@ -57,10 +57,12 @@
 public:
 	TokenStream *tokenStream(const TCHAR *fieldName,
 				 CL_NS(util)::Reader *reader) {
-		/* Everything except contents should go as-is without any
+		/* Everything except body/headers should go as-is without any
 		   modifications. Isn't there any easier way to do this than
 		   to implement a whole new RawTokenStream?.. */
-		if (fieldName != 0 && wcscmp(fieldName, L"contents") != 0)
+		if (fieldName != 0 &&
+		    wcscmp(fieldName, L"headers") != 0 &&
+		    wcscmp(fieldName, L"body") != 0)
 			return _CLNEW RawTokenStream(reader);
 
 		return standard::StandardAnalyzer::
@@ -282,7 +284,8 @@
 }
 
 int lucene_index_build_more(struct lucene_index *index, uint32_t uid,
-			    const unsigned char *data, size_t size)
+			    const unsigned char *data, size_t size,
+			    bool headers)
 {
 	unsigned int len;
 	char id[MAX_INT_STRLEN];
@@ -309,7 +312,10 @@
 		index->doc->add(*Field::Text(_T("box"), index->tmailbox_name));
 	}
 
-	index->doc->add(*Field::Text(_T("contents"), dest));
+	if (headers)
+		index->doc->add(*Field::Text(_T("headers"), dest));
+	else
+		index->doc->add(*Field::Text(_T("body"), dest));
 	return 0;
 }
 
@@ -411,12 +417,14 @@
 	}
 }
 
-int lucene_index_lookup(struct lucene_index *index, const char *key,
-			ARRAY_TYPE(seq_range) *result)
+int lucene_index_lookup(struct lucene_index *index, enum fts_lookup_flags flags,
+			const char *key, ARRAY_TYPE(seq_range) *result)
 {
 	const char *quoted_key;
 	int ret = 0;
 
+	i_assert((flags & (FTS_LOOKUP_FLAG_HEADERS|FTS_LOOKUP_FLAG_BODY)) != 0);
+
 	if (lucene_index_open_search(index) <= 0)
 		return -1;
 
@@ -429,15 +437,26 @@
 	lucene_utf8towcs(tkey, quoted_key, len + 1);
 	t_pop();
 
-	Query *content_query = NULL;
+	BooleanQuery lookup_query;
+	Query *content_query1 = NULL, *content_query2 = NULL;
 	try {
-		content_query = QueryParser::parse(tkey, _T("contents"),
-						   index->analyzer);
+		if ((flags & FTS_LOOKUP_FLAG_HEADERS) != 0) {
+			content_query1 = QueryParser::parse(tkey, _T("headers"),
+							    index->analyzer);
+			lookup_query.add(content_query1, false, false);
+		}
+		if ((flags & FTS_LOOKUP_FLAG_BODY) != 0) {
+			content_query2 = QueryParser::parse(tkey, _T("body"),
+							    index->analyzer);
+			lookup_query.add(content_query2, false, false);
+		}
 	} catch (CLuceneError &err) {
 		if (getenv("DEBUG") != NULL) {
 			i_info("lucene: QueryParser::parse(%s) failed: %s",
 			       str_sanitize(key, 40), err.what());
 		}
+		if (content_query1 != NULL)
+			_CLDELETE(content_query1);
 		lucene_index_close(index);
 		return -1;
 	}
@@ -445,7 +464,7 @@
 	BooleanQuery query;
 	Term mailbox_term(_T("box"), index->tmailbox_name);
 	TermQuery mailbox_query(&mailbox_term);
-	query.add(content_query, true, false);
+	query.add(&lookup_query, true, false);
 	query.add(&mailbox_query, true, false);
 
 	try {
@@ -469,6 +488,9 @@
 		ret = -1;
 	}
 
-	_CLDELETE(content_query);
+	if (content_query1 != NULL)
+		_CLDELETE(content_query1);
+	if (content_query2 != NULL)
+		_CLDELETE(content_query2);
 	return ret;
 }

Index: lucene-wrapper.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts-lucene/lucene-wrapper.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- lucene-wrapper.h	20 Dec 2006 14:46:28 -0000	1.5
+++ lucene-wrapper.h	15 Mar 2007 22:20:55 -0000	1.6
@@ -12,12 +12,13 @@
 
 int lucene_index_build_init(struct lucene_index *index, uint32_t *last_uid_r);
 int lucene_index_build_more(struct lucene_index *index, uint32_t uid,
-			    const unsigned char *data, size_t size);
+			    const unsigned char *data, size_t size,
+			    bool headers);
 int lucene_index_build_deinit(struct lucene_index *index);
 
 int lucene_index_expunge(struct lucene_index *index, uint32_t uid);
 
-int lucene_index_lookup(struct lucene_index *index, const char *key,
-			ARRAY_TYPE(seq_range) *result);
+int lucene_index_lookup(struct lucene_index *index, enum fts_lookup_flags flags,
+			const char *key, ARRAY_TYPE(seq_range) *result);
 
 #endif



More information about the dovecot-cvs mailing list