def getMainContentType(node): occurences = [(k, v) for k, v in node.getAllOccurences(acl.getRootAccess()).items()] occurences.sort(lambda x, y: cmp(y[1], x[1])) maintype = None for nodetype, num in occurences: if hasattr(nodetype, "isContainer") and not nodetype.isContainer(): return nodetype return None
def getMainContentType(node): occurences = [ (k, v) for k, v in node.getAllOccurences(acl.getRootAccess()).items() ] occurences.sort(lambda x, y: cmp(y[1], x[1])) maintype = None for nodetype, num in occurences: if hasattr(nodetype, "isContainer") and not nodetype.isContainer(): return nodetype return None
""" import sys sys.path += ["../", "."] from core.init import full_init full_init() import core.tree as tree import core.acl as acl import re import string import core.xmlnode as xmlnode import schema.schema as metadatatypes rootaccess = acl.getRootAccess() path = [] node = tree.getRoot() lastnodes = [] def findNode(node, id): try: return tree.getNode(id) except KeyError: pass except tree.NoSuchNodeError: pass except ValueError: pass
def _makeCollectionIndices(): tmpdir = config.settings["paths.searchstore"] _makeTreeIndices() print "Retrieving node list..." nodelist = _getNodeList(tree.getRoot()) print len(nodelist), "nodes" fi = open(tmpdir + "s2n.txt", "wb") fi.write("--START--\n") for node in nodelist: fi.write("{}\n".format(node.id)) fi.close() def mkIndex(name, field, type, data=None): print "Making Index", name file = tmpdir + name + ".searchfile.txt" fi = open(file, "wb") for node in nodelist: if field == "alltext": s = "" if node.type != "directory": for key, val in node.items(): if val: s += val + "\n" s += node.getName() # for nfile in node.getFiles(): # if nfile.type == "fulltext": # try: # fi2 = open(nfile.retrieveFile(), "rb") # s += " " # s += fi2.read() # s += " " # fi2.close() # except IOError: # log.error("Couldn't access file "+nfile.getName()) elif field == "fulltext": s = "" if node.type != "directory": for nfile in node.getFiles(): if nfile.type == "fulltext": try: fi2 = open(nfile.retrieveFile(), "rb") s += " " s += fi2.read() s += " " fi2.close() except IOError: log.error("Couldn't access file " + nfile.getName()) #c1 = "abcdefghijklmnop"[(int(node.id)>>28)&15] #c2 = "abcdefghijklmnop"[(int(node.id)>>24)&15] #c3 = "abcdefghijklmnop"[(int(node.id)>>20)&15] #c4 = "abcdefghijklmnop"[(int(node.id)>>16)&15] #c5 = "abcdefghijklmnop"[(int(node.id)>>12)&15] #c6 = "abcdefghijklmnop"[(int(node.id)>>8)&15] #c7 = "abcdefghijklmnop"[(int(node.id)>>4)&15] #c8 = "abcdefghijklmnop"[(int(node.id)>>0)&15] #s += " mx" + c8+c7+c6+c5+c4+c3+c2+c1 + " " elif field == "everything": s = "" if node.type != "directory": for key, val in node.items(): if val: s += UTF8ToLatin(val) + "\n" s += UTF8ToLatin(node.getName()) for nfile in node.getFiles(): if nfile.type == "fulltext": try: fi2 = open(nfile.retrieveFile(), "rb") s += " " s += fi2.read() s += " " fi2.close() except IOError: log.error("Couldn't access file " + nfile.getName()) elif field == "objtype": s = node.type if "/" in s: s = s[:s.index("/")] elif field == "schema": s = node.type if "/" in s: s = s[s.index("/") + 1:] else: s = "" elif type == "union": s = "" for item in data: field = node.get(item) if field: s += field + " " else: s = node.get(field) if type == "date": if len(s): try: s = str(date.parse_date(s).daynum()) except: print "Couldn't parse date", s s = "0" s = UTF8ToLatin(s) s = modify_tex(s, 'strip') fi.write(s.replace("\2", " ") + "\n") fi.write("\2") if type != "num" and type != "date": fi.write( "ecjfadf;jwkljer;jfklajd;gyugi;wyuogsdfjg;wuriosygh;nmwert;bwweriwoue;jfkajsdf;nmweurwu;hkethre;ghbyxuidfg;ewrioafi;ewirjglsag;vhxyseoru;vnmwerwe;fajsdfwetrh" ) fi.close() basename = name itype = "makeindex" if type == "date" or type == "num": itype = "makeNumIndex" elif type == "list" or type == "mlist" or type == "ilist": itype = "makeClassIndex" command = "%s %s %s %s %s %s" % ( sys.executable, os.path.join(config.basedir, "core/search/runindexer.py"), itype, file, tmpdir, basename) exit_status = os.system(command) if exit_status: print "Exit status " + str( exit_status) + " of subprocess " + command sys.exit(1) #raise "Exit status "+str(exit_status)+" of subprocess "+command #mgindexer.makeindex(file, tmpdir, name) occurs = tree.getRoot().getAllOccurences(acl.getRootAccess()) searchfields = [] for mtype, num in occurs.items(): if num > 0: fields = mtype.getMetaFields() for field in fields: if field.Searchfield(): searchfields += [field] mkIndex("full", "alltext", "text") mkIndex("everything", "everything", "text") mkIndex("objtype", "objtype", "list") mkIndex("schema", "schema", "list") mkIndex("mindex", "mindex", "num") mkIndex("updatetime", "updatetime", "date") for f in searchfields: mkIndex(f.getName(), f.getName(), f.getFieldtype(), f.getValueList())
def _makeCollectionIndices(): tmpdir = config.settings["paths.searchstore"] _makeTreeIndices() print "Retrieving node list..." nodelist = _getNodeList(tree.getRoot()) print len(nodelist), "nodes" fi = open(tmpdir + "s2n.txt", "wb") fi.write("--START--\n") for node in nodelist: fi.write("{}\n".format(node.id)) fi.close() def mkIndex(name, field, type, data=None): print "Making Index", name file = tmpdir + name + ".searchfile.txt" fi = open(file, "wb") for node in nodelist: if field == "alltext": s = "" if node.type != "directory": for key, val in node.items(): if val: s += val + "\n" s += node.getName() # for nfile in node.getFiles(): # if nfile.type == "fulltext": # try: # fi2 = open(nfile.retrieveFile(), "rb") # s += " " # s += fi2.read() # s += " " # fi2.close() # except IOError: # log.error("Couldn't access file "+nfile.getName()) elif field == "fulltext": s = "" if node.type != "directory": for nfile in node.getFiles(): if nfile.type == "fulltext": try: fi2 = open(nfile.retrieveFile(), "rb") s += " " s += fi2.read() s += " " fi2.close() except IOError: log.error("Couldn't access file " + nfile.getName()) #c1 = "abcdefghijklmnop"[(int(node.id)>>28)&15] #c2 = "abcdefghijklmnop"[(int(node.id)>>24)&15] #c3 = "abcdefghijklmnop"[(int(node.id)>>20)&15] #c4 = "abcdefghijklmnop"[(int(node.id)>>16)&15] #c5 = "abcdefghijklmnop"[(int(node.id)>>12)&15] #c6 = "abcdefghijklmnop"[(int(node.id)>>8)&15] #c7 = "abcdefghijklmnop"[(int(node.id)>>4)&15] #c8 = "abcdefghijklmnop"[(int(node.id)>>0)&15] #s += " mx" + c8+c7+c6+c5+c4+c3+c2+c1 + " " elif field == "everything": s = "" if node.type != "directory": for key, val in node.items(): if val: s += UTF8ToLatin(val) + "\n" s += UTF8ToLatin(node.getName()) for nfile in node.getFiles(): if nfile.type == "fulltext": try: fi2 = open(nfile.retrieveFile(), "rb") s += " " s += fi2.read() s += " " fi2.close() except IOError: log.error("Couldn't access file " + nfile.getName()) elif field == "objtype": s = node.type if "/" in s: s = s[:s.index("/")] elif field == "schema": s = node.type if "/" in s: s = s[s.index("/") + 1:] else: s = "" elif type == "union": s = "" for item in data: field = node.get(item) if field: s += field + " " else: s = node.get(field) if type == "date": if len(s): try: s = str(date.parse_date(s).daynum()) except: print "Couldn't parse date", s s = "0" s = UTF8ToLatin(s) s = modify_tex(s, 'strip') fi.write(s.replace("\2", " ") + "\n") fi.write("\2") if type != "num" and type != "date": fi.write( "ecjfadf;jwkljer;jfklajd;gyugi;wyuogsdfjg;wuriosygh;nmwert;bwweriwoue;jfkajsdf;nmweurwu;hkethre;ghbyxuidfg;ewrioafi;ewirjglsag;vhxyseoru;vnmwerwe;fajsdfwetrh") fi.close() basename = name itype = "makeindex" if type == "date" or type == "num": itype = "makeNumIndex" elif type == "list" or type == "mlist" or type == "ilist": itype = "makeClassIndex" command = "%s %s %s %s %s %s" % (sys.executable, os.path.join( config.basedir, "core/search/runindexer.py"), itype, file, tmpdir, basename) exit_status = os.system(command) if exit_status: print "Exit status " + str(exit_status) + " of subprocess " + command sys.exit(1) #raise "Exit status "+str(exit_status)+" of subprocess "+command #mgindexer.makeindex(file, tmpdir, name) occurs = tree.getRoot().getAllOccurences(acl.getRootAccess()) searchfields = [] for mtype, num in occurs.items(): if num > 0: fields = mtype.getMetaFields() for field in fields: if field.Searchfield(): searchfields += [field] mkIndex("full", "alltext", "text") mkIndex("everything", "everything", "text") mkIndex("objtype", "objtype", "list") mkIndex("schema", "schema", "list") mkIndex("mindex", "mindex", "num") mkIndex("updatetime", "updatetime", "date") for f in searchfields: mkIndex(f.getName(), f.getName(), f.getFieldtype(), f.getValueList())