Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
2k views
in Q2A Core by
How can I implement Live search suggestions using already posted questions in my Q2A site ?
Q2A version: 1.6.3
by
Good question. Hopefully someone can help us with this feature. It would be great if there is a plugin or added to the next version.

1 Answer

+1 vote
by
selected by
 
Best answer

I once implemented that. Just put the askbox on the startpage:

                // teaser to ask, askbar, only show for visitors that are not logged in
                if( !qa_is_logged_in() ) {
                    
                    $askQuestionString = 'What do you like to know?';
                    
                    ?>
<div class="ask-teaser-input">
    <div class="ask-teaser-inner">
        <p>Ask anonymously: </p>
        <form method="post" action="<?php echo qa_path_html('ask', null); ?>">
            <input onkeyup="qa_title_change2(this.value);" autocomplete="off" id="askboxin" name="title" type="text" placeholder="<?php echo $askQuestionString; ?>">
            <span id="similar"></span>
            
            <style type="text/css">
                #similar {
                    display:none;
                    margin:20px 0 20px 233px !important;
                    text-align:left;
                }
            </style>
<script type="text/javascript">
    var similarQuShow2 = false; // eetv variable
    var minWords2 = 2; // eetv min words before showing similar questions
    function qa_title_change2(value) {
        // eetv added if: only show similar question if more than 2 words and chars>15
        var totalWords = value.split(/[\s\.\?]+/).length;
        if(totalWords>=minWords2 && value.length>=15) {
            // increase
            minWords2 = totalWords;
            // show #similar
            document.getElementById('similar').style.display = "block";
            qa_ajax_post('asktitle', {title:value}, function(lines) {
                if (lines[0]=='1') {
                    if (lines[1].length) {
                        //qa_tags_examples=lines[1];
                        //qa_tag_hints(true);
                    }
                    
                    if (lines.length>2) {
                        var simelem=document.getElementById('similar');
                        if (simelem)
                            simelem.innerHTML=lines.slice(2).join('\n');
                    }
                    
                } else if (lines[0]=='0')
                    alert(lines[1]);
                else
                    qa_ajax_error();
            });
            
            qa_show_waiting_after(document.getElementById('similar'), true);
            $('#similar').show();
            $('#similar').css('display', 'block');
            $('#similar').css('margin', '20px');
        }
        else if(similarQuShow2) {
            // eetv: we were showing similar questions already, user deleted some chars/words
            // reinit
            minWords2=2;
        }
        else if(value.length==0) {
            // eetv: hide similar questions if title got removed again by user
            minWords2 = 2;
            document.getElementById('similar').style.display = "none";
            similarQuShow2=false;
        }
    }
    </script>

        <input class="ask-boxT-button" type="submit" value="Ask without registration">
        <input type="hidden" name="doask1" VALUE="1">
    </form>
    </div>
</div>
<?php

 

If you like I could make a plugin of that. But for the work I'd charge 9 USD per plugin download.

Kai

...