def precomposedsqlsearch(so: SearchObject) -> List[dbWorkLine]: """ flow control for searching governed by so.searchtype speed notes: the speed of these searches is consonant with that of the old search code; usu. <1s difference sqlphrasesearch() was eliminated in order to keep the code base more streamlined """ assert so.searchtype in [ 'simple', 'simplelemma', 'proximity', 'phrase', 'phraseandproximity' ], 'unknown searchtype sent to rawsqlsearches()' so.poll.statusis('Executing a {t} search...'.format(t=so.searchtype)) so.searchsqldict = searchlistintosqldict(so, so.termone) if so.lemmaone: so.searchsqldict = rewritesqlsearchdictforlemmata(so) searchfnc = lambda x: list() if so.searchtype in ['simple', 'simplelemma']: searchfnc = basicprecomposedsqlsearcher elif so.searchtype == 'proximity': # search for the least common terms first: swap termone and termtwo if need be so = rebuildsearchobjectviasearchorder(so) if so.scope == 'lines': # this will hit rawdsqlsearchmanager() 2x searchfnc = precomposedsqlwithinxlinessearch else: searchfnc = precomposedsqlwithinxwords elif so.searchtype == 'phrase': so.phrase = so.termone # so.leastcommon = findleastcommonterm(so.termone, so.accented) searchfnc = precomposedsqlsubqueryphrasesearch elif so.searchtype == 'phraseandproximity': so.phrase = so.termone searchfnc = precomposedphraseandproximitysearch else: # should be hard to reach this because of "assert" above consolewarning( 'rawsqlsearches() does not support {t} searching'.format( t=so.searchtype), color='red') so.searchsqldict = searchlistintosqldict(so, so.termone) if so.lemmaone: so.searchsqldict = rewritesqlsearchdictforlemmata(so) hitlist = searchfnc(so) if so.onehit: # you might still have two hits from the same author; purge the doubles # use unique keys property of a dict() to do it uniqueauthors = {h.authorid: h for h in hitlist} hitlist = [uniqueauthors[a] for a in uniqueauthors] hitlist = hitlist[:so.cap] return hitlist
def precomposedphraseandproximitysearch(so: SearchObject) -> List[dbWorkLine]: """ do a precomposedsqlsubqueryphrasesearch() and then search inside the results for part two... corner case tester: two line-enders: non solum + temporum dignitatem [12] Caesar, De Bello Gallico: book 7, chapter 54, section 4, line 2 7.54.3.3 multatos agris, omnibus ereptis sociis, imposito stipendio, 7.54.4.1 obsidibus summa cum contumelia extortis, et quam in 7.54.4.2 fortunam quamque in amplitudinem deduxisset, ut non 7.54.4.3 solum in pristinum statum redissent, sed omnium tem- 7.54.4.4 porum dignitatem et gratiam antecessisse viderentur. corner case tester: two distant line-enders: temporum dignitatem + obsides Galliae ut non solum in pristinum statum redissent, sed omnium tem- 7.54.4.3 porum dignitatem et gratiam antecessisse viderentur. his datis mandatis eos ab se dimisit. Noviodunum erat oppidum Haeduorum ad ripas 7.55.1.1 Ligeris opportuno loco positum. huc Caesar omnes ob- 7.55.2.1 sides Galliae, frumentum, pecuniam publicam, suorum the old code will trick you by pretending it is doing a valid search even though it is not really set up to handle this situation and was not supposed to promise that it could do phrase+ [it's the phrase-spanning-two-lines bit that yields the problem since you do "lemma+" but have no handler for the multi-line issue] 0.0.0-1.8.1 Sought all 19 known forms of »χώρα« within 1 lines of »μεγάλην δύναμιν« Searched 3,182 works and found 1 passage (0.77s) Searched between 850 B.C.E. and 300 B.C.E. Sorted by name [1] Ctesias, Fragmenta: Volume-Jacoby#-F 3c,688,F, fragment 5, line 47 3c,688,F.5.45 τόπουϲ. (3) γενόμενον δ’ ἀποϲτάτην καὶ πείϲαντα τὸ ϲύμπαν ἔθνοϲ ἀντέχεϲθαι 3c,688,F.5.46 τῆϲ ἐλευθερίαϲ, αἱρεθῆναι ϲτρατηγὸν διὰ τὴν ἀνδρείαν. ἔπειτα πυνθανόμενον 3c,688,F.5.47 ἀθροιζομένην ἐπ’ αὐτὸν μεγάλην δύναμιν, καθοπλίϲαι τοὺϲ Καδουϲίουϲ παν- 3c,688,F.5.48 δημεί, καὶ καταϲτρατοπεδεῦϲαι πρὸϲ ταῖϲ εἰϲ τὴν χώραν εἰϲβολαῖϲ, ἔχοντα 3c,688,F.5.49 τοὺϲ ϲύμπανταϲ οὐκ ἐλάττουϲ εἴκοϲι μυριάδων. (4) τοῦ δὲ βαϲιλέωϲ Ἀρταίου 1.8.2+ Sought all 19 known forms of »χώρα« within 1 lines of »μεγάλην δύναμιν« Searched 2,346 works and found 2 passages (2.2s) Searched between 850 B.C.E. and 300 B.C.E. Sorted by name [1] Ctesias, Fragmenta: Volume-Jacoby#-F 3c,688,F, fragment 5, line 47 3c,688,F.5.45 τόπουϲ. (3) γενόμενον δ’ ἀποϲτάτην καὶ πείϲαντα τὸ ϲύμπαν ἔθνοϲ ἀντέχεϲθαι 3c,688,F.5.46 τῆϲ ἐλευθερίαϲ, αἱρεθῆναι ϲτρατηγὸν διὰ τὴν ἀνδρείαν. ἔπειτα πυνθανόμενον 3c,688,F.5.47 ἀθροιζομένην ἐπ’ αὐτὸν μεγάλην δύναμιν, καθοπλίϲαι τοὺϲ Καδουϲίουϲ παν- 3c,688,F.5.48 δημεί, καὶ καταϲτρατοπεδεῦϲαι πρὸϲ ταῖϲ εἰϲ τὴν χώραν εἰϲβολαῖϲ, ἔχοντα 3c,688,F.5.49 τοὺϲ ϲύμπανταϲ οὐκ ἐλάττουϲ εἴκοϲι μυριάδων. (4) τοῦ δὲ βαϲιλέωϲ Ἀρταίου [2] Ctesias, Fragmenta: Volume-Jacoby#-F 3c,688,F, fragment 14, line 54 3c,688,F.14.52 (40) καὶ ἐλυπήθη λύπην ϲφοδρὰν Μεγάβυζοϲ, καὶ ἐπένθηϲε, καὶ ἠιτήϲατο 3c,688,F.14.53 ἐπὶ Ϲυρίαν τὴν ἑαυτοῦ χώραν ἀπιέναι. ἐνταῦθα λάθραι καὶ τοὺϲ ἄλλουϲ τῶν 3c,688,F.14.54 Ἑλλήνων προέπεμπε. καὶ ἀπήιει, καὶ ἀπέϲτη βαϲιλέωϲ, καὶ ἀθροίζει μεγάλην 3c,688,F.14.55 δύναμιν ἄχρι πεντεκαίδεκα μυριάδων χωρὶϲ τῶν ἱππέων [καὶ τῶν πεζῶν]. 3c,688,F.14.56 καὶ πέμπεται Οὔϲιριϲ κατ’ αὐτοῦ ϲὺν ⟨κ⟩ μυριάϲι, καὶ ϲυνάπτεται πόλεμοϲ, καὶ """ # # initially do "within x lines" # phrasefinder = re.compile(r'[^\s]\s[^\s]') if re.search(phrasefinder, so.seeking) and re.search( phrasefinder, so.proximate): secondsearch = precomposedsqlsubqueryphrasesearch elif not re.search(phrasefinder, so.seeking) and re.search( phrasefinder, so.proximate): so.swapseekingandproxmate() so.swaplemmaoneandtwo() secondsearch = basicprecomposedsqlsearcher else: secondsearch = basicprecomposedsqlsearcher c = so.cap ps = so.proximate so.proximate = str() pl = so.lemmatwo so.lemmatwo = str() so.phrase = so.seeking firstterm = so.phrase so.cap = hipparchia.config['INTERMEDIATESEARCHCAP'] initialhitlines = precomposedsqlsubqueryphrasesearch(so) so.seeking = ps so.lemmaone = pl so.setsearchtype() so.cap = c if secondsearch == precomposedsqlsubqueryphrasesearch: so.phrase = ps else: so.phrase = str() so = perparesoforsecondsqldict(so, initialhitlines) so.searchsqldict = searchlistintosqldict(so, so.seeking) if so.lemmaone: so.searchsqldict = rewritesqlsearchdictforlemmata(so) so.poll.sethits(0) newhitlines = secondsearch(so) initialhitlinedict = {hl.uniqueid: hl for hl in initialhitlines} newhitlineids = set() for nhl in newhitlines: indices = list( range(nhl.index - so.distance, nhl.index + so.distance + 1)) ids = ['{a}_{b}'.format(a=nhl.wkuinversalid, b=i) for i in indices] newhitlineids.update(ids) maybefinalhitines = list() if so.near: # "is near" maybefinalhitines = [ initialhitlinedict[hl] for hl in initialhitlinedict if hl in newhitlineids ] elif not so.near: # "is not near" maybefinalhitines = [ initialhitlinedict[hl] for hl in initialhitlinedict if hl not in newhitlineids ] # # if neccessary, do "within x words" as x lines hits will always be a subset of the first set # if so.lemmaone: secondterm = wordlistintoregex(so.lemmaone.formlist) else: secondterm = so.seeking if so.scope == 'words': finalhitlines = paredowntowithinxwords(so, firstterm, secondterm, maybefinalhitines) else: finalhitlines = maybefinalhitines # to humor rewriteskgandprx() # but that formatting doesn't 100% work yet... so.termone = firstterm so.termtwo = secondterm so.lemmatwo = so.lemmaone return finalhitlines