AleksLitynski / teller

A game engine dedicated to making generative content easier to make.
1 stars 0 forks source link

Alex : Need a simple search example. #21

Closed kyung01 closed 10 years ago

kyung01 commented 10 years ago

Currently server sends local dummy search file if asked to get data from database.

def sendSearch(handler): printFunc("SEARCH") searchResult = open("dataSearch.txt").read() read = SearchInterpreter.read(searchResult); handler.wfile.write(json.dumps(read))

This is the code atm. I am not familiar with sending data. I want you to provide me with simple example.

handler.wfile.write( dataYouJustSearchedThroughHere )

If you could edit this section, then I can start to understand far easily. Also we can now start to see all the nodes that are actually in the database :D!

s.send("give me the booty") #Thing that I need to send you in this line here

AleksLitynski commented 10 years ago

Three python code samples that may help:

Connect to the database. Send/receive json:

def query(query_string):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('127.0.0.1', 5005))
    s.send(query_string)
    query_response = s.recv(10000) #our replies are VERY long. GOTTA fix that. At least, don't recurse into nodes that already exist
    s.close()
    return query_response

Get info a about a given noun by name:

def describe_noun(noun_name, depth=2):
    #broke up the return into 2 lines to make it more readable
    return '{"type": "get", "params": {"depth":'+str(depth)+'}, "search": {"edges": [{"direction": "inbound","type": "describes","weight-time": "1",' +
    '"terminal": {"type": "relationship","edges": [{"terminal": {"type": "type","value": "named"}},{"terminal": {"type": "value","value": "'+noun_name+'"}}]}}]}}'

Get info about a node by ID:

def get_node(node_id, depth=2):
    return '{"type": "get", ' \
           '"params": {"depth":'+str(depth)+'}, ' \
                                            '"search": {"id":"'+node_id+'"}}'

Get all nodes in DB (will overrun buffer!!! Increase from 10000!!):

def get_all(depth=2):
    return '{"type": "get", ' \
           '"params": {"depth":'+str(depth)+'}, ' \
                                            '"search": {}}'
AleksLitynski commented 10 years ago

https://gist.github.com/tavoe/9f810ac1c3fab7ede530