Has Anyone Used AnsPress in Conjunction with the Swiftype WordPress Search Plugin?

5.88K viewsWordPress
1

Hello –

We use Swiftype for our site search. (http://swiftype.com)

They have a WordPress plugin that synchronizes each new post to their cloud-based search engine, and then seamlessly uses the Swiftype search engine in place of the standard WordPress search box.

However, I’ve found that this is currently not compatible with the base version of AnsPress.

(Swiftype is compatible with DWQA, but I’d prefer to keep AnsPress as my Q&A platform.)

 

I found a question and answer about incorporating AnsPress questions into the default WordPress search box:

Has Anyone Used AnsPress in Conjunction with the Swiftype WordPress Search Plugin?

 

Has anyone tried to incorporate the AnsPress results into the Swiftype plugin search results?  Any suggestions on how to make that work?

Thanks
James Grove

If there are any coders out there, I’ve also got Swiftype support looking into the problem and they suggested that it might be possible to add that code if somebody else wants to build it.

Here are the relevant quotes from Swiftype:

“I just did some testing with AnsPress and it looks like the question and answer data is stored in a database table separate from the standard wp_posts table. I’m afraid our plug-in is currently limited to indexing content within that specific table. The WP plug-in is open source and we’re always open to pull requests from outside sources that provide greater functionality.

“The mention of being able to utilize AnsPress with relevanssi is encouraging. It also does sound like a pre_get_posts function could be utilized to prime that data for indexing.

“Here’s our repo: https://github.com/swiftype/swiftype-wordpress

They are not correct. AnsPress does not store question and answer elsewhere.. both are CPT and saved in wp_posts table.

Here was a response from Swiftype:
As long as these conditions are met, we should be able to index the question content: https://swiftype.com/questions/does-the-swiftype-wordpress-plugin-index-custom-post-types

The key thing they mention is that “The exclude_from_search parameter is false for that type.”

So I looked in anspress-question-answer/includes/post_types.php and I found references to:

‘exclude_from_search’ => true,

for both questions and answers.

If I change those to
‘exclude_from_search’ => false,

will that solve the problem, do you think?

Update: I changed both lines to false
Then I deactivated and reactivated the plugin.
Now it seems to be indexing the AnsPress questions and answers correctly!

Will I have to re-do this fix whenever the plugin is updated?

add_filter(‘ap_question_cpt_args’, ‘d_ap_cpt_args’);
add_filter(‘ap_answer_cpt_args’, ‘d_ap_cpt_args’);
function d_ap_cpt_args($args) {
$args[‘exclude_from_search’] = false;

return $args;
}

Thanks for that suggestion, Dima. Where would I add those lines of code?

Also, do I need to do something similar so that search will also read the “Comments” on questions and answers?

1

Using it with Relevanssi. With few custom snippets, it works marvellous! Can’t wish for more!

(example)

1

Swiftype looks interesting (I have been looking for the site like this). Will check ad let you know.

yea it looks very nice

please keep us updated on this. 🙂