swiftype / swiftype-wordpress

Elastic Site Search (Swiftype) Wordpress Plugin for full-text search
https://swiftype.com/solutions/wordpress-search
Apache License 2.0
26 stars 17 forks source link

Searching not getting data from api in WP_Query integration, like it does for autocomplete ajax results #15

Closed sc0ttkclark closed 11 years ago

sc0ttkclark commented 11 years ago

I'm testing some stuff out and it looks like Swiftype may only reorder search results from WP itself, instead of overriding it entirely.

look commented 11 years ago

Actually, result reordering does affect the autocomplete dropdown, but because these are prefix searches, the result modifications do not show up until the full query term has been entered. We have more details about this on our site.

sc0ttkclark commented 11 years ago

I was referring to the WP_Query integration. I'm still digging in, but it looks like performance is degrading severely since we have so much content on our site. The WP_Query still runs, which still performs the search on the WP side. I thought Swiftype would serve up it's own data entirely.

qhoxie commented 11 years ago

When you say "still performs the search on the WP side", I assume you are talking about the SQL LIKE query? That should not be happening with Swiftype enabled, and I just did some testing on this locally to verify. Basically, the way the plugin works is this:

1) Capture the search query 2) Ask the Swiftype API for the Post ID of matching results 3) Query the WP database for the posts with those IDs (this is a simple IN query) 4) Let the theme handle rendering the results as it normally would

The only real query that is happening as a result of Swiftype is the IN query from step 3), which should not be slow on any reasonable server. Have you done any profiling to see what queries are causing the slowness?

sc0ttkclark commented 11 years ago

Looks like the slow-down came from a pre_get_posts call by the theme which would set post_type explicitly to certain post types. For some reason, when it was 'any' or set to a few different ones, it would just slow everything down. Not sure why, since your code was setting post__in. Oh well, solved!