diff options
Diffstat (limited to 'examples/cmdline/search.cpp')
-rw-r--r-- | examples/cmdline/search.cpp | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/examples/cmdline/search.cpp b/examples/cmdline/search.cpp index f437430..1a3b098 100644 --- a/examples/cmdline/search.cpp +++ b/examples/cmdline/search.cpp @@ -6,7 +6,7 @@ * * search KJV "swift hear slow speak" * - * $Id: search.cpp 2980 2013-09-14 21:51:47Z scribe $ + * $Id: search.cpp 3515 2017-11-01 11:38:09Z scribe $ * * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -36,15 +36,23 @@ using namespace sword; #endif -/* - * >=0 - regex - * -1 - phrase - * -2 - multiword - * -3 - entryAttrib (eg. Word//Lemma/G1234/) - * -4 - Lucene - */ +// FROM swmodule.h + /* + * >=0 - regex; (for backward compat, if > 0 then used as additional REGEX FLAGS) + * -1 - phrase + * -2 - multiword + * -3 - entryAttrib (eg. Word//Lemma./G1234/) (Lemma with dot means check components (Lemma.[1-9]) also) + * -4 - Lucene + * -5 - multilemma window; set 'flags' param to window size (NOT DONE) + */ char SEARCH_TYPE=-2; +int flags = 0 +// for case insensitivity +| REG_ICASE +// for use with entryAttrib search type to match whole entry to value, e.g., G1234 and not G12345 +//| SEARCHFLAG_MATCHWHOLEENTRY +; char printed = 0; void percentUpdate(char percent, void *userData) { @@ -68,7 +76,7 @@ int main(int argc, char **argv) SWMgr manager; SWModule *target; ListKey listkey; - ListKey scope; + ListKey *scope = 0; ModMap::iterator it; if ((argc < 3) || (argc > 5)) { @@ -81,7 +89,7 @@ int main(int argc, char **argv) SWBuf searchTerm = argv[2]; manager.setGlobalOption("Greek Accents", "Off"); - manager.setGlobalOption("Strong's Numbers", "On"); + manager.setGlobalOption("Strong's Numbers", "Off"); manager.setGlobalOption("Hebrew Vowel Points", "Off"); manager.filterText("Greek Accents", searchTerm); @@ -96,32 +104,33 @@ int main(int argc, char **argv) target = (*it).second; + ListKey maybeScope; if (argc > 3) { // if min / max specified SWKey *k = target->getKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, k); VerseKey kjvParser; if (!parser) parser = &kjvParser; // use standard KJV parsing as fallback - scope = parser->parseVerseList(argv[3], *parser, true); - scope.setPersist(true); - target->setKey(scope); + maybeScope = parser->parseVerseList(argv[3], *parser, true); + scope = &maybeScope; } std::cerr << "[0=================================50===============================100]\n "; char lineLen = 70; - listkey = target->search(searchTerm.c_str(), SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen); + listkey = target->search(searchTerm.c_str(), SEARCH_TYPE, flags, scope, 0, &percentUpdate, &lineLen); std::cerr << std::endl; - if (argc > 4) { // if min / max specified - scope = listkey; - scope.setPersist(true); - target->setKey(scope); + if (argc > 4) { // example: if a second search term is supplied, search again for a second search term, limiting to previous results + scope = &listkey; printed = 0; std::cerr << " "; - listkey = target->search(argv[4], SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen); + listkey = target->search(argv[4], SEARCH_TYPE, flags, scope, 0, &percentUpdate, &lineLen); std::cerr << std::endl; } - listkey.sort(); +// we don't want to sort by verse if we've been given scores +// listkey.sort(); while (!listkey.popError()) { - std::cout << (const char *)listkey << std::endl; + std::cout << (const char *)listkey; + if (listkey.getElement()->userData) std::cout << " : " << (__u64)listkey.getElement()->userData << "%"; + std::cout << std::endl; listkey++; } |