Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
568 views
in Q2A Core by
does anybody has a suggestion how to build a query that selects and shows questions with multiple tags as input?

Something like:

http://.../question2answer/index.php?qa=tag&qa_1=error&qa2=gui&qa3=open

In addition it would be good to also exclude tags...

e.g. show all questions with TAG1  but not, if TAG2 is also present...

any idea or script example is welcome :)

2 Answers

0 votes
by

You'd have to do this in the database, using a JOIN on qa_posttags - there isn't currently a pre-written query in Q2A to do it.

0 votes
by

I hack the search, because I couldn't see how to add it as an override... the exiating search works as it was like;

https://jlogica.com/q2a/tag/shoutbox

But now you can do;

https://jlogica.com/q2a/tag/shoutbox|common

Each tage is separated with a pipe '|'

Open qa-include/qa-page-tag.php find (line 41);

//    Find the questions with this tag

Replace all of the code until the next comment isencountered

//    Prepare content for theme

The code...

    if (!strlen($tag))
        qa_redirect('tags');

    $tags = array();
    if( strpos( $tag, '|' ) !== false )
    {
        $tags = explode( '|', $tag );
        $tag = array_shift( $tags );
    }
        
    @list($questions, $tagword, $favorite)=qa_db_select_with_pending(
        qa_db_tag_recent_qs_selectspec($userid, $tag, $start, false, qa_opt_if_loaded('page_size_tag_qs')),
        qa_db_tag_word_selectspec($tag),
        isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_TAG, $tag) : null
    );
    
    if( count( $tags ) )
    {
        foreach( $tags as $t )
        {
            @list($q, $t, $f)=qa_db_select_with_pending(
                qa_db_tag_recent_qs_selectspec($userid, $t, $start, false, qa_opt_if_loaded('page_size_tag_qs')),
                qa_db_tag_word_selectspec($t),
                isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_TAG, $t) : null
            );
            //$questions = array_merge( $questions, $q );    
            foreach( $q AS $x )
            {
                foreach( $questions AS $y )
                {
                    if( $x['postid'] == $y['postid'] )
                    {
                        break 2;
                    }
                }
                $questions[] = $x;
            }
        }
    }
    
    $pagesize=qa_opt('page_size_tag_qs');
    $questions=array_slice($questions, 0, $pagesize);
    $usershtml=qa_userids_handles_html($questions);
 

 

...