示例#1
0
def test_search():
    entities.Listing(title="title for test",
                     posting_time=1.0e5, key_name="search_test").put()

    assert tuple(helpers.fetch_shard("title")) == ("search_test",)
    assert (tuple(x.permalink for x in helpers.run_query("title for test")) ==
            ("search_test",))

    ent = entities.Listing(title="new title",
                           posting_time=1.0e5, key_name="search_test")
    ent.put()
    helpers.invalidate_listing(ent)

    assert not helpers.run_query("title for test")
示例#2
0
def test_search():
    entities.Listing(title="title for test",
                     posting_time=1.0e5,
                     key_name="search_test").put()

    assert tuple(helpers.fetch_shard("title")) == ("search_test", )
    assert (tuple(
        x.permalink
        for x in helpers.run_query("title for test")) == ("search_test", ))

    ent = entities.Listing(title="new title",
                           posting_time=1.0e5,
                           key_name="search_test")
    ent.put()
    helpers.invalidate_listing(ent)

    assert not helpers.run_query("title for test")
示例#3
0
def search_listings():
    """Display a list of listings that match the given query."""

    # Fix session handler if not initialized
    view = request.args.get("v", "th")

    # Parse filtering options from query.
    query = request.args.get("q", "")
    offset = int(request.args.get("offset", "0"))
    if offset < 0:
        offset = 0

    # Compute the results matching that query.
    listings = helpers.run_query(query, offset, 24)

    # Render a chrome-less template for AJAH continuation.
    template = "" if "continuation" not in request.args else "_continuation"

    return render_template("index{}.html".format(template), listings=listings, view=view, query=query)
示例#4
0
文件: api.py 项目: tranv94/caravel
def api_all_listings():
    """Display a list of listings that match the given query."""

    # Parse filtering options from query.
    query = request.args.get("q", "")
    offset = int(request.args.get("offset", "0"))
    if offset < 0:
        offset = 0

    limit = int(request.args.get("limit", "100"))
    if limit < 0:
        limit = 0
    if limit > 100:
        limit = 100

    # Provide a burst limit on search queries.
    if dos.rate_limit("api_search:{}".format(request.remote_addr), 40, 60):
        abort(403)

    # Compute the results matching that query.
    listings = helpers.run_query(query, offset, limit)

    # Display only whitelisted properties as JSON.
    externalized = [_externalize(listing) for listing in listings]

    pages = {}
    if len(listings) == limit:
        pages["nextURL"] = url_for("api_all_listings",
            offset=offset + limit, _external=True)
    if offset != 0:
        pages["previousURL"] = url_for("api_all_listings",
            offset=max(0, offset - limit), _external=True)

    # Return JSON if requested.
    return jsonify(
        offset=offset,
        listings=externalized,
        limit=limit,
        **pages
    )
示例#5
0
def search_listings():
    """Display a list of listings that match the given query."""

    # Fix session handler if not initialized
    view = request.args.get("v", "th")

    # Parse filtering options from query.
    query = request.args.get("q", "")
    offset = int(request.args.get("offset", "0"))
    if offset < 0:
        offset = 0

    # Compute the results matching that query.
    listings = helpers.run_query(query, offset, 24)

    # Render a chrome-less template for AJAH continuation.
    template = ("" if "continuation" not in request.args else "_continuation")

    return render_template("index{}.html".format(template),
                           listings=listings,
                           view=view,
                           query=query)
示例#6
0
文件: api.py 项目: tranv94/caravel
def api_all_listings():
    """Display a list of listings that match the given query."""

    # Parse filtering options from query.
    query = request.args.get("q", "")
    offset = int(request.args.get("offset", "0"))
    if offset < 0:
        offset = 0

    limit = int(request.args.get("limit", "100"))
    if limit < 0:
        limit = 0
    if limit > 100:
        limit = 100

    # Provide a burst limit on search queries.
    if dos.rate_limit("api_search:{}".format(request.remote_addr), 40, 60):
        abort(403)

    # Compute the results matching that query.
    listings = helpers.run_query(query, offset, limit)

    # Display only whitelisted properties as JSON.
    externalized = [_externalize(listing) for listing in listings]

    pages = {}
    if len(listings) == limit:
        pages["nextURL"] = url_for("api_all_listings",
                                   offset=offset + limit,
                                   _external=True)
    if offset != 0:
        pages["previousURL"] = url_for("api_all_listings",
                                       offset=max(0, offset - limit),
                                       _external=True)

    # Return JSON if requested.
    return jsonify(offset=offset, listings=externalized, limit=limit, **pages)