def search(humanReadableId):
    query = request.args.get('q', '').strip()
    pagination = None
    if query:
        index_base_dir = config().get_path("ZIM", "wikipedia_index_dir")
        index_dir = os.path.join(index_base_dir, humanReadableId)
        page = int(request.args.get('page', 1))

        # Set a higher value for the title field so it is weighted more
        weighting=scoring.BM25F(title_B=1.0)

        # Sort pages with "Image:" in their title after
        # regular articles
        def image_pages_last(searcher, docnum):
            fields = searcher.stored_fields(docnum)
            if fields['title'].find("Image:") == 0:
                return 1;
            else:
                return 0;

        sortedby = sorting.MultiFacet([ sorting.FunctionFacet(image_pages_last),
                                        sorting.ScoreFacet(),
                                        sorting.FieldFacet("reverse_links", reverse=True),
                                       ])
        (pagination, suggestion) = paginated_search(index_dir, ["title", "content"], query, page, weighting=weighting, sort_column=sortedby)
    else:
        flash(_('Please input keyword(s)'), 'error')

    return render_template('zim/search.html', humanReadableId=humanReadableId, pagination=pagination, suggestion=suggestion, keywords=query, endpoint_desc=EndPointDescription('zim_views.search', {'humanReadableId':humanReadableId}))
Beispiel #2
0
def search(humanReadableId):
    query = request.args.get('q', '').strip()
    pagination = None
    if query:
        index_base_dir = config().get_path("ZIM", "wikipedia_index_dir")
        index_dir = os.path.join(index_base_dir, humanReadableId)
        page = int(request.args.get('page', 1))

        # Load index so we can query it for which fields exist
        ix = whoosh_open_dir_32_or_64(index_dir)

        # Set a higher value for the title field so it is weighted more
        weighting = scoring.BM25F(title_B=1.0)

        # Sort pages with "Image:" in their title after
        # regular articles
        def image_pages_last(searcher, docnum):
            fields = searcher.stored_fields(docnum)
            if fields['title'].find("Image:") == 0:
                return 1
            else:
                return 0

        # Support older whoosh indexes that do not have a reverse_links field
        if 'reverse_links' in ix.schema.names():
            sortedby = sorting.MultiFacet([
                sorting.FunctionFacet(image_pages_last),
                sorting.ScoreFacet(),
                sorting.FieldFacet("reverse_links", reverse=True),
            ])
        else:
            sortedby = sorting.MultiFacet([
                sorting.FunctionFacet(image_pages_last),
                sorting.ScoreFacet(),
            ])

        (pagination, suggestion) = paginated_search(ix, ["title", "content"],
                                                    query,
                                                    page,
                                                    weighting=weighting,
                                                    sort_column=sortedby)
    else:
        flash(_('Please input keyword(s)'), 'error')

    return render_template('zim/search.html',
                           humanReadableId=humanReadableId,
                           pagination=pagination,
                           suggestion=suggestion,
                           keywords=query,
                           endpoint_desc=EndPointDescription(
                               'zim_views.search',
                               {'humanReadableId': humanReadableId}))
def search():
    query = request.args.get('q', '').strip()
    pagination = None
    if query:
        index_dir = config().get_path('GUTENBERG', 'index_dir')
        page = int(request.args.get('page', 1))
        (pagination, suggestion) = paginated_search(index_dir, DEFAULT_SEARCH_COLUMNS, query, page, sort_column='creator')
    else:
        flash(_('Please input keyword(s)'), 'error')
    #print pagination.items
    return render_template('gutenberg/search.html', pagination=pagination,
                           keywords=query, suggestion=suggestion, fn_author_to_query=author_to_query,
                           endpoint_desc=EndPointDescription('gutenberg.search', None),
                           files_exist=files_exist)
Beispiel #4
0
def search():
    query = request.args.get('q', '').strip()
    pagination = None
    if query:
        index_dir = config().get_path('GUTENBERG', 'index_dir')
        page = int(request.args.get('page', 1))
        ix = whoosh_open_dir_32_or_64(index_dir)
        (pagination, suggestion) = paginated_search(ix,
                                                    DEFAULT_SEARCH_COLUMNS,
                                                    query,
                                                    page,
                                                    sort_column='creator')
    else:
        flash(_('Please input keyword(s)'), 'error')
    #print pagination.items
    return render_template('gutenberg/search.html',
                           pagination=pagination,
                           keywords=query,
                           suggestion=suggestion,
                           fn_author_to_query=author_to_query,
                           endpoint_desc=EndPointDescription(
                               'gutenberg.search', None),
                           files_exist=files_exist)