[sword-cvs] sword/include swsearchable.h,NONE,1.1 rawtext.h,1.27,1.28 swcacher.h,1.4,1.5 swmodule.h,1.67,1.68 ztext.h,1.28,1.29

sword@www.crosswire.org sword@www.crosswire.org
Thu, 28 Aug 2003 23:00:19 -0700


Update of /usr/local/cvsroot/sword/include
In directory www:/tmp/cvs-serv27914/include

Modified Files:
	rawtext.h swcacher.h swmodule.h ztext.h 
Added Files:
	swsearchable.h 
Log Message:
	Abstracted the search interface from SWModule
	Added experimental implementation of fast
		search framework to zText using
		clucene



--- NEW FILE: swsearchable.h ---
/******************************************************************************
 *  swsearchable.h	- definition of class SWSearchable used to provide an
 *	interface for objects that be searched.
 *
 * $Id: swsearchable.h,v 1.1 2003/08/29 06:00:16 scribe Exp $
 *
 * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
 *	P. O. Box 2528
 *	Tempe, AZ  85280-2528
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#ifndef SWSEARCHABLE_H
#define SWSEARCHABLE_H

#include <defs.h>
#include <listkey.h>

SWORD_NAMESPACE_START

/** used to provide an interface for objects that be searched.
 */
class SWDLLEXPORT SWSearchable {
public:
	SWSearchable();
	virtual ~SWSearchable();

	/**
	* This is the default callback function for searching.
	* This function is a placeholder and does nothing.
	* You can define your own function for search progress
	* evaluation, and pass it over to Search().
	*/
	static void nullPercent(char percent, void *userData);

	// search methods

	/** Searches a module for a string
	*
	* @param istr string for which to search
	* @param searchType type of search to perform
	*   >=0 ->regex;  -1 ->phrase; -2 ->multiword;
	* @param flags options flags for search
	* @param scope Key containing the scope. VerseKey or ListKey are useful here.
	* @param justCheckIfSupported if set, don't search,
	* only tell if this function supports requested search.
	* @param percent Callback function to get the current search status in %.
	* @param percentUserData User data that is given to the callback function as parameter.
	*
	* @return listkey set to verses that contain istr
	*/
	virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0,
			SWKey * scope = 0,
			bool * justCheckIfSupported = 0,
			void (*percent) (char, void *) = &nullPercent,
			void *percentUserData = 0) = 0;

	/** ask the object to build any framework it need to do it searching.
	*
	*/
	virtual signed char createSearchFramework();	// special search framework

	/** does this class have a search framework built?
	*
	*/
	virtual bool hasSearchFramework() { return false; }				// special search framework
	/** Check if the search is optimally supported (e.g. if index files are presnt and working)
	* This function checks whether the search framework may work in the best way.
	* @return True if the the search is optimally supported, false if it's not working in the best way.
	*/
	virtual bool isSearchOptimallySupported(const char *istr, int searchType, int flags, SWKey * scope) {
		bool retVal = false;
		search(istr, searchType, flags, scope, &retVal);
		return retVal;
	}
};

SWORD_NAMESPACE_END
#endif

Index: rawtext.h
===================================================================
RCS file: /usr/local/cvsroot/sword/include/rawtext.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- rawtext.h	20 Feb 2003 07:25:19 -0000	1.27
+++ rawtext.h	29 Aug 2003 06:00:16 -0000	1.28
@@ -47,7 +47,7 @@
 	virtual void decrement(int steps = 1) { increment(-steps); }
 	virtual signed char createSearchFramework();
 	virtual bool hasSearchFramework() { return true; }
-	virtual ListKey & Search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
+	virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
 
 	// write interface ----------------------------
 	virtual bool isWritable() { return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & O_RDWR) == O_RDWR)); }

Index: swcacher.h
===================================================================
RCS file: /usr/local/cvsroot/sword/include/swcacher.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- swcacher.h	4 Mar 2003 11:35:52 -0000	1.4
+++ swcacher.h	29 Aug 2003 06:00:16 -0000	1.5
@@ -27,8 +27,9 @@
 
 SWORD_NAMESPACE_START
 
-/** A simple cache management class.
-*/
+/** used to provide an interface for objects that cache and want
+ *	a standard interface for cleaning up.
+ */
 class SWDLLEXPORT  SWCacher {
 public:
 	SWCacher();

Index: swmodule.h
===================================================================
RCS file: /usr/local/cvsroot/sword/include/swmodule.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- swmodule.h	5 Jul 2003 04:58:42 -0000	1.67
+++ swmodule.h	29 Aug 2003 06:00:16 -0000	1.68
@@ -29,9 +29,12 @@
 #include <listkey.h>
 #include <swfilter.h>
 #include <swconfig.h>
+#include <swbuf.h>
+
 #include <swcacher.h>
+#include <swsearchable.h>
+
 #include <list>
-#include <swbuf.h>
 
 #include <defs.h>
 #include <multimapwdef.h>
@@ -82,7 +85,7 @@
 // Just leave for now.  This lets us always able to call module->flush()
 // to manually flush a cache, and doesn't hurt if there is no work done.
 
-class SWDLLEXPORT SWModule : public SWCacher {
+class SWDLLEXPORT SWModule : public SWCacher, public SWSearchable {
 
 protected:
 
@@ -133,13 +136,6 @@
 
 	public:
 	/**
-	* This is the default callback function for searching.
-	* This function is a placeholder and does nothing.
-	* You can define your own function for search progress
-	* evaluation, and pass it over to Search().
-	*/
-	static void nullPercent(char percent, void *userData);
-	/**
 	* Set this bool to false to terminate the search which is executed by this module (Search()).
 	* This is useful for threaded applications to terminate the search in another thread.
 	*/
@@ -299,8 +295,8 @@
 	*/
 	virtual char *Lang(const char *imodlang = 0);
 
-	// search methods
 
+	// search interface
 	/** Searches a module for a string
 	*
 	* @param istr string for which to search
@@ -315,29 +311,22 @@
 	*
 	* @return listkey set to verses that contain istr
 	*/
-	virtual ListKey & Search(const char *istr, int searchType = 0, int flags = 0,
+	virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0,
 			SWKey * scope = 0,
 			bool * justCheckIfSupported = 0,
 			void (*percent) (char, void *) = &nullPercent,
 			void *percentUserData = 0);
-	/**
-	*
-	*/
-	virtual signed char createSearchFramework() { return 0; }				// special search framework
-	/** Not yet useful.
-	*
-	*/
-	virtual bool hasSearchFramework() { return false; }				// special search framework
-	/** Check if the search is optimally supported (e.g. if index files are presnt and working)
-	* This function checks whether the search framework may work in the best way.
-	* @return True if the the search is optimally supported, false if it's not working in the best way.
-	*/
-	virtual bool isSearchOptimallySupported(const char *istr, int searchType,
-			int flags, SWKey * scope) {
-		bool retVal = false;
-		Search(istr, searchType, flags, scope, &retVal);
-		return retVal;
+
+	// for backward compat-- deprecated
+	virtual ListKey &Search(const char *istr, int searchType = 0, int flags = 0,
+			SWKey * scope = 0,
+			bool * justCheckIfSupported = 0,
+			void (*percent) (char, void *) = &nullPercent,
+			void *percentUserData = 0) {
+		return search(istr, searchType, flags, scope, justCheckIfSupported, percent, percentUserData);
 	}
+
+
 	/** Allocates a key of specific type for module
 	* The different reimplementatiosn of SWModule (e.g. SWText) support SWKey implementations, which support special.
 	* This functions returns a SWKey object which works with the current implementation of SWModule. For example for the SWText class it returns a VerseKey object.

Index: ztext.h
===================================================================
RCS file: /usr/local/cvsroot/sword/include/ztext.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ztext.h	20 Feb 2003 07:25:20 -0000	1.28
+++ ztext.h	29 Aug 2003 06:00:16 -0000	1.29
@@ -24,11 +24,20 @@
 #define ZTEXT_H
 
 #include <zverse.h>
+#include <rawstr.h>
 #include <swtext.h>
 //#include <swcomprs.h>
 
 #include <defs.h>
 
+namespace lucene { namespace index {
+class IndexReader;
+}}
+
+namespace lucene { namespace search {
+class IndexSearcher;
+}}
+
 SWORD_NAMESPACE_START
 
 /*** SWModule implementation for compressed modules
@@ -37,9 +46,11 @@
 */
 class SWDLLEXPORT zText:public zVerse, public SWText {
 
-     VerseKey *lastWriteKey;
-     bool sameBlock(VerseKey * lastWriteKey, VerseKey * key);
+	VerseKey *lastWriteKey;
+	bool sameBlock(VerseKey * lastWriteKey, VerseKey * key);
 	int blockType;
+	lucene::index::IndexReader *ir;
+	lucene::search::IndexSearcher *is;
 	VerseKey &getVerseKey();
 
 
@@ -73,6 +84,11 @@
 	// swcacher interface ----------------------
 	virtual void flush() { flushCache(); }
 	// end swcacher interface ----------------------
+
+	virtual signed char createSearchFramework();
+	virtual bool hasSearchFramework() { return true; }
+	virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
+
 
 	SWMODULE_OPERATORS