[sword-svn] r3742 - in trunk: examples/cmdline include src/keys src/modules
scribe at crosswire.org
scribe at crosswire.org
Sun May 17 03:21:10 MST 2020
Author: scribe
Date: 2020-05-17 03:21:10 -0700 (Sun, 17 May 2020)
New Revision: 3742
Modified:
trunk/examples/cmdline/search.cpp
trunk/include/swkey.h
trunk/include/versekey.h
trunk/src/keys/versekey.cpp
trunk/src/modules/swmodule.cpp
Log:
Added bounds to search result element when spans keys
Fixed misnamed clearBounds which kept VerseKey from overriding base method
Modified: trunk/examples/cmdline/search.cpp
===================================================================
--- trunk/examples/cmdline/search.cpp 2020-05-13 23:37:36 UTC (rev 3741)
+++ trunk/examples/cmdline/search.cpp 2020-05-17 10:21:10 UTC (rev 3742)
@@ -51,7 +51,7 @@
// for case insensitivity
| REG_ICASE
// for enforcing strict verse boundaries
-| SEARCHFLAG_STRICTBOUNDARIES
+//| SEARCHFLAG_STRICTBOUNDARIES
// for use with entryAttrib search type to match whole entry to value, e.g., G1234 and not G12345
//| SEARCHFLAG_MATCHWHOLEENTRY
;
@@ -77,7 +77,7 @@
// SWMgr manager(0, 0, true, new MarkupFilterMgr(FMT_RTF, ENC_RTF));
SWMgr manager;
SWModule *target;
- ListKey listkey;
+ ListKey listKey;
ListKey *scope = 0;
ModMap::iterator it;
@@ -119,22 +119,23 @@
std::cerr << "[0=================================50===============================100]\n ";
char lineLen = 70;
- listkey = target->search(searchTerm.c_str(), SEARCH_TYPE, flags, scope, 0, &percentUpdate, &lineLen);
+ listKey = target->search(searchTerm.c_str(), SEARCH_TYPE, flags, scope, 0, &percentUpdate, &lineLen);
std::cerr << std::endl;
if (argc > 4) { // example: if a second search term is supplied, search again for a second search term, limiting to previous results
- scope = &listkey;
+ scope = &listKey;
printed = 0;
std::cerr << " ";
- listkey = target->search(argv[4], SEARCH_TYPE, flags, scope, 0, &percentUpdate, &lineLen);
+ listKey = target->search(argv[4], SEARCH_TYPE, flags, scope, 0, &percentUpdate, &lineLen);
std::cerr << std::endl;
}
// we don't want to sort by verse if we've been given scores
-// listkey.sort();
- while (!listkey.popError()) {
- std::cout << (const char *)listkey;
- if (listkey.getElement()->userData) std::cout << " : " << (__u64)listkey.getElement()->userData << "%";
+// listKey.sort();
+ for (listKey = TOP; !listKey.popError(); listKey.nextElement()) {
+ SWKey *k = listKey.getElement();
+ std::cout << k->getRangeText();
+// std::cout << (const char *)listKey;
+ if (k->userData) std::cout << " : " << (__u64)k->userData << "%";
std::cout << std::endl;
- listkey++;
}
return 0;
Modified: trunk/include/swkey.h
===================================================================
--- trunk/include/swkey.h 2020-05-13 23:37:36 UTC (rev 3741)
+++ trunk/include/swkey.h 2020-05-17 10:21:10 UTC (rev 3742)
@@ -180,7 +180,7 @@
virtual const char *getRangeText() const;
virtual const char *getOSISRefRangeText() const;
virtual bool isBoundSet() const { return boundSet; }
- virtual void clearBound() const { boundSet = false; }
+ virtual void clearBounds() const { boundSet = false; }
/** Compares this key object to another SWKey object
* @param ikey key to compare with this one
Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h 2020-05-13 23:37:36 UTC (rev 3741)
+++ trunk/include/versekey.h 2020-05-17 10:21:10 UTC (rev 3742)
@@ -194,7 +194,7 @@
/** clears the boundaries of this VerseKey
*/
- void clearBounds();
+ void clearBounds() const;
SWDEPRECATED void ClearBounds() { clearBounds(); }
/** Creates a new SWKey based on the current VerseKey
Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp 2020-05-13 23:37:36 UTC (rev 3741)
+++ trunk/src/keys/versekey.cpp 2020-05-17 10:21:10 UTC (rev 3742)
@@ -1199,16 +1199,14 @@
* VerseKey::clearBounds - clears bounds for this VerseKey
*/
-void VerseKey::clearBounds()
-{
+void VerseKey::clearBounds() const {
delete tmpClone;
tmpClone = 0;
boundSet = false;
}
-void VerseKey::initBounds() const
-{
+void VerseKey::initBounds() const {
if (!tmpClone) {
tmpClone = (VerseKey *)this->clone();
tmpClone->setAutoNormalize(false);
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2020-05-13 23:37:36 UTC (rev 3741)
+++ trunk/src/modules/swmodule.cpp 2020-05-17 10:21:10 UTC (rev 3742)
@@ -426,6 +426,7 @@
SWKey *searchKey = 0;
SWKey *resultKey = createKey();
SWKey *lastKey = createKey();
+ VerseKey *vkCheck = SWDYNAMIC_CAST(VerseKey, resultKey);
SWBuf lastBuf = "";
#ifdef USECXX11REGEX
@@ -680,7 +681,7 @@
if (!regexec(&preg, textBuf, 0, 0, 0)) {
#endif
*resultKey = *getKey();
- resultKey->clearBound();
+ resultKey->clearBounds();
listKey << *resultKey;
lastBuf = "";
}
@@ -695,8 +696,18 @@
#else
else if (!regexec(&preg, lastBuf + ' ' + textBuf, 0, 0, 0)) {
#endif
- lastKey->clearBound();
- listKey << *lastKey;
+ lastKey->clearBounds();
+ if (vkCheck) {
+ resultKey->clearBounds();
+ *resultKey = *getKey();
+ vkCheck->setUpperBound(resultKey);
+ vkCheck->setLowerBound(lastKey);
+ }
+ else {
+ *resultKey = *lastKey;
+ resultKey->clearBounds();
+ }
+ listKey << *resultKey;
lastBuf = (windowSize > 1) ? textBuf : "";
}
else {
@@ -718,7 +729,7 @@
sres = strstr(textBuf.c_str(), term.c_str());
if (sres) { //it's also in the stripText(), so we have a valid search result item now
*resultKey = *getKey();
- resultKey->clearBound();
+ resultKey->clearBounds();
listKey << *resultKey;
}
break;
@@ -771,8 +782,16 @@
} while ((windowSize > 1) && (multiVerse < 2) && (stripped != 2 || foundWords != words.size()));
if ((stripped == 2) && (foundWords == words.size())) { //we found the right words in both raw and stripped text, which means it's a valid result item
- *resultKey = (multiVerse == 1) ? *getKey() : *lastKey;
- resultKey->clearBound();
+ lastKey->clearBounds();
+ resultKey->clearBounds();
+ *resultKey = (multiVerse > 1 && !vkCheck) ? *lastKey : *getKey();
+ if (multiVerse > 1 && vkCheck) {
+ vkCheck->setUpperBound(resultKey);
+ vkCheck->setLowerBound(lastKey);
+ }
+ else {
+ resultKey->clearBounds();
+ }
listKey << *resultKey;
lastBuf = "";
// if we're searching windowSize > 1 and we had a hit which required the current verse
@@ -850,7 +869,7 @@
}
if (sres) {
*resultKey = *getKey();
- resultKey->clearBound();
+ resultKey->clearBounds();
listKey << *resultKey;
break;
}
More information about the sword-cvs
mailing list