Exemplo n.º 1
0
def create_scoring_functions():
    api = ApiClient(settings.INDEXTANK_API)
    index = api.get_index(settings.INDEXTANK_INDEX_NAME)

    index.add_function(1, 'relevance')
    index.add_function(2, '-d[0]')
    index.add_function(3, 'd[0]')
Exemplo n.º 2
0
def create_entry_examples():
    api = ApiClient(API_URL)
    index = api.get_index(INDEX_NAME)
    doc_vars = {0:0}

    entry = Entry()
    entry.name = 'leandro'
    entry.email = '*****@*****.**'
    entry.text = 'Hello world!'
    entry.save()

    index.add_document(entry.id, 
                    {'text': entry.name + ' ' + entry.email + ' ' + entry.text},
                    variables= doc_vars)

    entry = Entry()
    entry.name = 'juan'
    entry.email = '*****@*****.**'
    entry.text = 'Just passed to say hello'
    entry.save()

    index.add_document(entry.id, 
                    {'text': entry.name + ' ' + entry.email + ' ' + entry.text},
                    variables=doc_vars)
    
    entry = Entry()
    entry.name = 'leandro'
    entry.email = '*****@*****.**'
    entry.text = 'hey, it\'s me again. HeLLo!!!'
    entry.save()

    index.add_document(entry.id, 
                    {'text': entry.name + ' ' + entry.email + ' ' + entry.text},
                    variables=doc_vars)
Exemplo n.º 3
0
def restart_index():
    api = ApiClient(settings.INDEXTANK_API)
    index = api.get_index(settings.INDEXTANK_INDEX_NAME)
    index.delete_index()
    index.create_index()
    
    while not index.has_started():
        time.sleep(5)
    
    create_scoring_functions()
Exemplo n.º 4
0
def restart_index():
    '''
    if the public index is dirty, you can delete it a create it again
    '''
    api = ApiClient(API_URL)
    index = api.get_index(INDEX_NAME)
    index.delete_index()
    index.create_index()
    while not index.has_started:
        time.sleep(1)
    
    # add a fuction to sort results. 'd[0]' refers to the 0-variable of each document
    index.add_function(1, 'd[0]')
        
    print 'index restarted'
Exemplo n.º 5
0
def detail(request, object_id):
    entry_object = get_object_or_404(Entry, pk=object_id)
    entry_object.views += 1
    entry_object.save()

    # create api client and get index
    api = ApiClient(API_URL)
    index = api.get_index(INDEX_NAME)
    
    # variables are accessed by numbers. in this case 'd[0]' in a scoring function will reference 'entry_object.views'
    variables = {0:entry_object.views}
    
    # update the variables of this document
    index.update_variables(entry_object.id, variables)
    
    
    return render_to_response('guestbook/entry_detail.html', {'entry_object': entry_object})
Exemplo n.º 6
0
def search(request):
    query = request.GET['query']
    # create api client and get index
    api = ApiClient(API_URL)
    index = api.get_index(INDEX_NAME)
    # search by query and sort by views
    search_result = index.search(query, scoring_function=1)
    
    # retrieve results from database
    result_ids = [int(r['docid']) for r in search_result['results']]
    
    entry_list = []
    for result_id in result_ids:
        try:
            entry_object = Entry.objects.get(pk=result_id)
            entry_list.append(entry_object)
        except ObjectDoesNotExist, e:
            pass
Exemplo n.º 7
0
def submit(request):
    '''
    Create a new entry, save it and index it. Then render the home page
    '''
    new_entry = Entry()
    new_entry.name = request.POST['name']
    new_entry.email = request.POST['email']
    new_entry.text = request.POST['text']
    
    new_entry.save()
    
    api = ApiClient(API_URL)
    index = api.get_index(INDEX_NAME)
    variables = {0:0}
    index.add_document(new_entry.id, 
                    {'text': new_entry.name + ' ' + new_entry.email + ' ' + new_entry.text},
                    variables=variables)
    
    return redirect('guestbook.views.list')
Exemplo n.º 8
0
                    print "Link has no ID"

                cur.execute("select count(*) as count from stories where (url = %s or id_from_feed = %s) and location = %s",[link,str(id),feed.channel])
                count = cur.fetchone()['count']
                if count < 1:
                    #New Story, for this chan.
                    #But is it new for all of Lonava?
                    cur.execute("select commentgroup from stories where url = %s",[link])
                    existing = cur.fetchall();
                    if len(existing) > 0:
                        commentgroupid = existing[0]['commentgroup']
                    else:
                        commentgroupid = 0;
                    cur.execute("insert into stories (id_from_feed,usr,title,url,text,name,location,channame) values (%s,%s,%s,%s,%s,%s,%s,(select name from channels where chanid = %s )) returning storyid;",[str(id),feed.usr,entry.title,link,'Originally posted at: ' + entry.comments, feed.feedname, feed.channel,feed.channel])
                    storyid = cur.fetchone()['storyid']
                    if commentgroupid == 0:
                        cur.execute("insert into commentgroups(url) values (%s) returning commentgroupid;",[link]);
                        commentgroupid = cur.fetchone()['commentgroupid']

                    #now, commentgroupid is set, either way. 
                    cur.execute("update stories set commentgroup = %s where storyid = %s;",[commentgroupid,storyid]);

                    #EVERYONE posts into ALL-STORIES. EVERYTHING goes there! ;)
                    cur.execute("insert into stories (usr,title,url,text,name,location,commentgroup,channame) values (%s,%s,%s,%s,%s,0,%s,(select name from channels where chanid = 0 )) returning storyid;",[feed.usr,entry.title,link,'Via: ' + entry.link, feed.feedname, commentgroupid])
                    api = ApiClient('http://:[email protected]')
                    index = api.get_index('Pages')
                    index.add_document(storyid, { 'text': title , 'link': link})

            cur.execute("update feeds set lasttime = now() where feedid = %s",[feed.feedid])
            db.commit()
Exemplo n.º 9
0
                    ])
                storyid = cur.fetchone()['storyid']

                if commentgroupid == 0:
                    cur.execute(
                        "insert into commentgroups(url) values (%s) returning commentgroupid;",
                        [link])
                    commentgroupid = cur.fetchone()['commentgroupid']

                #now, commentgroupid is set, either way.
                cur.execute(
                    "update stories set commentgroup = %s where storyid = %s;",
                    [commentgroupid, storyid])
                #EVERYONE posts into ALL-STORIES. EVERYTHING goes there! ;)
                cur.execute(
                    "insert into stories (usr,title,url,text,name,location,commentgroup,channame) values (%s,%s,%s,%s,%s,0,%s,(select name from channels where chanid = 0 )) returning storyid;",
                    [
                        feed.usr, title, link, 'Via: ' + digglink,
                        feed.feedname, commentgroupid
                    ])
                api = ApiClient(
                    'http://:[email protected]')
                index = api.get_index('Pages')
                index.add_document(storyid, {'text': title, 'link': link})

            cur.execute("update feeds set lasttime = now() where feedid = %s",
                        [feed.feedid])
            a += 1

        db.commit()