Example #1
0
def search_view(request):
    q = request.GET.get("q")
    result0 = search.search(q)
    result1 = search.search(q, default_field="title")
    result0.upgrade_and_extend(result1)
    owner = request.user.username
    nbids = [res["nbid"] for res in result0 if res["owner"] == owner]
    nbs = Notebook.objects.filter(guid__in=nbids, owner=request.user).order_by("created_time")
    results = [[e.guid, e.title, e.backend.all()[0].engine_type.name, e.last_modified_time().strftime("%Y-%m-%d %H:%M:%S"), e.location] for e in nbs]
    jsobj = json.dumps({"query":q, "results":results})
    return HttpResponse(jsobj, mimetype='application/json')
Example #2
0
def test_search():
    #XXX Turn off Nose doctests?
    #"""
    #Add 2 Cells into 2 different Notebooks,
    #one with correct search terms,
    #and the other without, test that
    #only the Notebook with the correct search
    #terms appears in the results.
    #"""
    nb1 = models.Notebook(owner=f['user1'])
    nb1.save()
    nb2 = models.Notebook(owner=f['user1'])
    nb2.save()

    cell1 = models.Cell(guid=str(uuid.uuid4()).replace("-", ""),
                        notebook=nb1,
                        owner=nb1.owner,
                        content="foo=1\nbar=foo+foo")
    cell1.save()

    cell2 = models.Cell(guid=str(uuid.uuid4()).replace("-", ""),
                        notebook=nb2,
                        owner=nb2.owner,
                        content="baz=1\nbar=baz+baz")
    cell2.save()

    guids = [result["nbid"] for result in search.search("foo")]
    assert nb1.guid in guids
    assert nb2.guid not in guids
Example #3
0
def test_search():
    #XXX Turn off Nose doctests?
    #"""
    #Add 2 Cells into 2 different Notebooks, 
    #one with correct search terms, 
    #and the other without, test that
    #only the Notebook with the correct search
    #terms appears in the results.
    #"""
    nb1 = models.Notebook(owner=f['user1'])
    nb1.save()
    nb2 = models.Notebook(owner=f['user1'])
    nb2.save()
 
    cell1 = models.Cell(
        guid=str(uuid.uuid4()).replace("-", ""), 
        notebook=nb1,
        owner=nb1.owner,
        content="foo=1\nbar=foo+foo"
        )
    cell1.save()
 
    cell2 = models.Cell(
        guid=str(uuid.uuid4()).replace("-", ""), 
        notebook=nb2,
        owner=nb2.owner,
        content="baz=1\nbar=baz+baz"
        )
    cell2.save()

    guids = [result["nbid"] for result in search.search("foo")]
    assert nb1.guid in guids
    assert nb2.guid not in guids
Example #4
0
    def test_search(self):
        #XXX Turn off Nose doctests?
        #"""
        #Add 2 Cells into 2 different Notebooks,
        #one with correct search terms,
        #and the other without, test that
        #only the Notebook with the correct search
        #terms appears in the results.
        #"""
        nb1 = models.Notebook(owner=self.user1)
        nb1.save()
        nb1_record = backend_models.NotebookBackendRecord(
            notebook=nb1, engine_type=self.engine_type)
        nb1_record.save()

        nb2 = models.Notebook(owner=self.user1)
        nb2.save()
        nb2_record = backend_models.NotebookBackendRecord(
            notebook=nb2, engine_type=self.engine_type)
        nb2_record.save()

        cell1 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb1,
                            owner=nb1.owner,
                            content="foo=1\nbar=foo+foo")
        cell1.save()

        cell2 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb2,
                            owner=nb2.owner,
                            content="baz=1\nbar=baz+baz")
        cell2.save()

        guids = [result["nbid"] for result in search.search(u"foo")]
        assert nb1.guid in guids
        assert nb2.guid not in guids