1

feinCMS ページの簡単な検索を構築しようとしています。このチュートリアルの助けを借りて、すべてのページ タイトルを検索する検索を作成しました。

def get_results(query_string, search_fields):
    ''' Returns a query, that is a combination of Q objects. That combination
        aims to search keywords within a model by testing the given search fields.

    '''
    if len(query_string)>1:
        results = []
        query = None # Query to search for every search term        
        terms = normalize_query(query_string)
        for term in terms:
            results += Page.objects.filter(title__contains = term)
        return results

しかし、さまざまなコンテンツ タイプを検索する方法がわかりません。

今私は追加しましmarkdowncontent_set = Page.content_type_for(MarkdownContent)たが、何を受け取り、コンテンツをループして、含まれているかどうかを確認するにはどうすればよいquery_sringですか?

編集:

現在、私のコードは次のようになっています。

def get_results(query_string, search_fields):
    ''' Returns a query, that is a combination of Q objects. That combination
        aims to search keywords within a model by testing the given search fields.

    '''
    if len(query_string)>0:
        results = []
        query = None # Query to search for every search term        
        terms = normalize_query(query_string)
        for term in terms:
            results += Page.objects.filter(title__contains = term)
            results += Page.objects.select_related("markdowncontent_set").filter(markdowncontent_set__content__contains = term)
        return list(set(results))

最善の解決策ではないかもしれませんが、うまくいきます。

4

0 に答える 0