[sword-cvs] sword/src/modules swmodule.cpp,1.54,1.55

sword at www.crosswire.org sword at www.crosswire.org
Wed Jun 2 15:28:21 MST 2004


Committed by: joachim

Update of /cvs/core/sword/src/modules
In directory www:/tmp/cvs-serv9786/src/modules

Modified Files:
	swmodule.cpp 
Log Message:
search up to 5.5 times faster now :) (joachim)

Index: swmodule.cpp
===================================================================
RCS file: /cvs/core/sword/src/modules/swmodule.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- swmodule.cpp	28 Feb 2004 20:14:29 -0000	1.54
+++ swmodule.cpp	2 Jun 2004 22:28:18 -0000	1.55
@@ -472,8 +472,6 @@
 	(*percent)(perc, percentUserData);
 
 	while (!Error() && !terminateSearch) {
-
-	
 		long mindex = 0;
 		if (vkcheck)
 			mindex = vkcheck->NewIndex();
@@ -504,21 +502,36 @@
 			}
 		}
 		else if (searchType == -1) {
-			sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(StripText(), istr) : strstr(StripText(), istr);
-			if (sres) {
+			sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(getRawEntry(), istr) : strstr(getRawEntry(), istr);
+			
+			if (sres) { //the raw text has the search text, check the stripped text for the text to be sure the text wasn't a tag value or similair
+				sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(StripText(), istr) : strstr(StripText(), istr);
+			}
+			
+			if (sres) { //it's also in the StripText(), so we have a valid search result item now
 					textkey = KeyText();
 					listkey << textkey;
 			}
 		}
 		else if (searchType == -2) {
-			int i;
-			const char *stripBuf = StripText();
-			for (i = 0; i < wordCount; i++) {
-				sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(stripBuf, words[i]) : strstr(stripBuf, words[i]);
-				if (!sres)
-					break;
-			}
-			if (i == wordCount) {
+			int loopCount = 0;
+			int foundWords = 0;
+			do {
+				const char* textBuf = (loopCount == 0) ? getRawEntry() : StripText();
+				foundWords = 0;
+				
+				for (int i = 0; i < wordCount; ++i) {
+					sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(textBuf, words[i]) : strstr(textBuf, words[i]);
+					if (!sres) {
+						break; //for loop
+					}
+					++foundWords;
+				}
+				
+				++loopCount;
+			} while ( (loopCount < 2) && (foundWords == wordCount));
+			
+			if ((loopCount == 2) && (foundWords == wordCount)) { //we found the right words in both raw and stripped text, which means it's a valid result item
 				textkey = KeyText();
 				listkey << textkey;
 			}
@@ -580,6 +593,7 @@
 		}
 		(*this)++;
 	}
+	
 	if (searchType >= 0)
 		regfree(&preg);
 



More information about the sword-cvs mailing list