def testIndexingHtml(self): path = testDataPath + "/test2.html" absPath = fs.absolutePath(path) if not fs.exists(absPath): fs.writeFile( path, "<html><head></head><body>Testing on html File</body></html>") index = Index(fs, testIndexPath) index.create() id = fs.splitExt(fs.split(path)[1])[0] contents = unicode(fs.readFile(path), 'iso-8859-1') #index.index Xml Content(contents, id) ## no indexing of xml searchResults = index.searchContents("Testing") self.assertEqual(searchResults.keys(), ["test2"]) searchResults.close() searchResults = index.searchContents("notInContent") self.assertEqual(searchResults.keys(), []) searchResults.close() searchResults = index.searchContents("body") self.assertEqual(searchResults.keys(), []) searchResults.close()
def testSearchId(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId") searchResults = index.searchId("testId") self.assertTrue(searchResults is not None) self.assertEqual(searchResults.value.get("id"), "testId") searchResults.close()
def testSearchMeta(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId", metaItems={"meta": "one"}) searchResults = index.searchMeta("meta", "one") #print searchResults self.assertTrue(searchResults is not None) self.assertTrue(searchResults["testId"].get("id"), "testId") searchResults.close()
def testKeywords(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId", other="one two") searchResults = index.searchContents("other:one") self.assertEqual(searchResults.keys(), ["testId"]) searchResults.close() searchResults = index.searchContents("other:two") self.assertEqual(searchResults.keys(), ["testId"]) searchResults.close()
def testDelete(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId") searchResults = index.searchId("testId") self.assertTrue(searchResults is not None) searchResults.close() index.deleteIndex("testId") searchResults = index.searchId("testId") self.assertEqual(searchResults.keys(), []) searchResults.close() searchResults = index.searchContents("content") self.assertEqual(searchResults.keys(), []) searchResults.close()
def testSearchContent(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test one content." index.indexContent(content, id="testId1", title="OneTitle") content = "This is just some test two content." index.indexContent(content, id="testId2", title="Two Title") searchResults = index.searchContents("content") self.assertEqual(len(searchResults), 2) self.assertEqual(searchResults["testId1"].get("id"), "testId1") self.assertEqual(searchResults["testId1"].get("title"), "OneTitle") searchResults.close() searchResults = index.searchContents("notInContent") self.assertEqual(len(searchResults), 0) searchResults.close()
def testIndexContent3(self): index = Index(fs, testIndexPath) index.create() content = "" meta = {"ids": ["1234"], "1234": ["tag1 tag2", "tag3"]} index.indexContent(content, id="one", metaItems=meta) searchResults = index.search("ids:1234") #print "found %s" % len(searchResults) for doc in searchResults.itervalues(): #print doc.get("1234") #print "x='%s'" % doc.get("x") #print dir(doc) for field in doc.getFields(): #print field.name(), field.stringValue() pass searchResults.close()
def testIndexContent2(self): index = Index(fs, testIndexPath) index.create() content = "" meta = { "one": "oNe", "tags": ["one", "tWo", "teST", "this"], "path": "/one/TWo/three" } index.indexContent(content, id="testId", metaItems=meta, comments="Comments One") meta = { "one": "ONE", "tags": ["one", "twO", "Test", "this"], "path": "/one/TWo/four" } index.indexContent(content, id="testId2", metaItems=meta, comments="Comments Two") # NOTE: there are NO wild cards in keywordQueries and are case-sensitive (not the storing analyzer # may have already lowerCased the content # also pathQueryStr is case-sensitive and may only contain a optional trailing '*' searchResults = index.search(queryStr="tags:tEst ", keywordQueryStr=None, pathQueryStr=None) for id, doc in searchResults.iteritems(): #print "'%s', '%s', '%s'" % (doc.get("comments"), doc.get("one"), doc.get("list")) pass self.assertEqual(len(searchResults), 2) searchResults.close() searchResults = index.search(queryStr=None, keywordQueryStr=None, pathQueryStr="/one/TWo/*") for id, doc in searchResults.iteritems(): #print "'%s', '%s', '%s'" % (doc.get("comments"), doc.get("one"), doc.get("list")) pass self.assertEqual(len(searchResults), 2) searchResults.close()
def testIndexContent(self): index = Index(fs, testIndexPath) index.create() content = "This is just some test content." index.indexContent(content, id="testId") searchResults = index.searchContents("content") self.assertEqual(len(searchResults), 1) searchResults.close() searchResults = index.searchContents("notInContent") self.assertEqual(len(searchResults), 0) searchResults.close() index = Index(fs, testIndexPath) index.indexContent(content, id="testId2") searchResults = index.searchContents("content") expected = ["testId", "testId2"] ids = searchResults.keys() ids.sort() expected.sort() self.assertEqual(ids, expected) searchResults.close()
def unpackJsCss(web_path): try: with ZipFile(io.BytesIO(DATA), 'r') as zipObj: zipObj.extractall(web_path) except Exception as e: error(e) if __name__ == "__main__": web_path = createDir(f'{DEFAULT_DIR_RUN}\\web') unpackJsCss(web_path) CHECKS_OPTIONS = '' SELECT_OPTIONS = '' i = 0 for file in glob.glob(WIN_LOG_PATH): SELECT_OPTIONS += f'<option value="{md5(filename(file))}" id="OPT{i}">{file}</option>' CHECKS_OPTIONS += f'<tr onclick="checkSelect(\'inp_{md5(file)}\')"><td width="5%"><input id="inp_{md5(file)}" onclick="checkSelect(\'inp_{md5(file)}\')" class="form-check-input select-all" type="checkbox" value="{file}"></td><td>{file}</td><td class="text-center" id="{md5(file)}"></td></tr>' i += 1 with open(f'{web_path}\\index.html', 'w', encoding='utf-8') as file: file.write( index.create([ WIN_LOG_PATH, IGNORE_COLUMN, REG_COUNT_LIMIT, REGEX_PATERN, SERVER_HOST, SERVER_PORT ], SELECT_OPTIONS, CHECKS_OPTIONS)) eel.init(web_path) eel.start('index.html', host=SERVER_HOST, port=SERVER_PORT)
def xtestTest(self): index = Index(fs, testIndexPath) index.create() index.test(self)