Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+25 votes
4.3k views
in Q2A Core by
edited by

so that when a user is typing a search query for answers/questions or when a user is typing in his question, suggestions should instantly appear in the search box.

You can see it in action on Quora

This question is going as a top 5 HOT! question for last 6 days. i was hoping Gidgreen would answer this for the benefit of all users

by
This was one of the features that was 'lacking' in Q2A compared to the other options. Still picked this one!
by
I am hoping admin would answer this ??
by
ajax search lets users immediately see similar questions to the one they want to ask, which is highly important for q&a site. so maybe not the most important, but definitely one of the most important features
by
How about using the tag suggestion for a token search and then modifying a jQuery Joomla pluggin to perform the real time search!

4 Answers

+2 votes
by
I fear instant search as on Quora is quite a hard thing to achieve :)

Maybe something useful/similar could be done by modifying e.g. something like this:

http://loopj.com/jquery-tokeninput/

...where instead of doing an autocomplete, it should retrieve and show the same questions that are currently shown when the user submits the single-line question in Q2A (when the corresponding setting is enabled) and the software asks if the question is different.
by
Why is it so hard to achieve ? Due to processing power needed or sth?
by
I remember I read an answer on Quora by Adam D'Angelo (not sure) about that feature from a technical point of view. I'm not able to find it now to read it again - if someone succeeds please do post the link here.
+3 votes
by
For when typing in a question, this is already implemented, but the suggestions only appear when you hit TAB or click out of the box, since it uses "onchange".  If you want as-you-type suggestions, you can just change line 189 of qa-page-ask.php to:

        $qa_content['form']['fields']['title']['tags'].=' onkeyup="if(this.old_value == this.value || this.value.length < 4) return; this.old_value = this.value; qa_title_change(this.value);"';

Which will begin to show suggestions after you've typed four characters.

As for instant search, well, you can suggest it for 1.6 :)
by
Hi NoahY.

i have tried what you mentioned above, no suggestions appear, i have clicked outside the search box and clicked tab, but no suggestions

Is t his featured removed now? or did I miss something?

thanks
by
you have to activate it in the admin panel. /admin/posting → Check for similar questions when asking: [ x ]
by
This is working, with modifications in version 1.8.2: in pages/ask.php on line 242 change to:
$qa_content['form']['fields']['title']['tags'] .= ' onkeyup="if(this.value.length < 4) return;qa_title_change(this.value);"';

Can I implement this without touching Q2A file? I mean, can I achieve the same result with some plugin? Like, to override this line of code even if Q2A script is updated?
0 votes
by

I also wanted to make add search autocomplete.
I found out that autocomplete option is already built in the code, and is used when someone is asking (not searching) a question on the ask page.

I added a search box to my theme's hearder (you may alrady have your search box somewhere)

<input type="text" placeholder="Find your answer..." name="q" onkeyup="qa_title_change_search(this.value);" autocomplete="off" required>

Then I added the a span which will display the suggested questions just below the search box:

<span id="similar_search"></span>

 

Now I went to qa-ask.js and based on this function "qa_title_change"(which is used for the autocomplete while asking a question) I careated the function: "qa_title_change_search"

function qa_title_change_search(value) {
    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_search');
                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_search'), true);
}
 
If you want to change the line displayed before the suggested questions, you can look for "ask_same_q" in qa-lan-question.php (be default it is: "Before proceeding, please check your question was not asked already:")
–1 vote
by
11 years later we still miss an autocomplete feature. Wow its 2022 LOL
...