parisholley / wordpress-fantastic-elasticsearch

Improve wordpress search performance/accuracy and enable faceted search by leveraging an ElasticSearch server.
MIT License
162 stars 64 forks source link

ES don't output every enabled fields #125

Closed 0x572f00 closed 9 years ago

0x572f00 commented 9 years ago

Hello,

I get some trouble develloping stuff on WFE plugin, I'd like to add wordpress attachment on search result.

First I've changed default.php and Indexer.php to index the post excerpt and the attachment (it works!) like this :

default.php static function fields(){ return array('post_content', 'post_title', 'post_type', 'post_excerpt'); }

indexer.php / * Retrieve the posts for the page provided * @param integer $page The page of results to retrieve for indexing * @return WP_Post[] posts / static function get_posts($page = 1){ $args = Config::apply_filters('indexer_get_posts', array( 'posts_per_page' => self::per_page(), 'post_type' => array('post','attachment'), 'paged' => $page, 'post_status' => 'any' ));

    return get_posts($args);
}

/**
* Retrieve count of the number of posts available for indexing
*
* @return integer number of posts
**/
static function get_count(){
    $query = new \WP_Query(array(
        'post_type' => array('post','attachment'),
        'post_status' => 'any'
    ));

    return $query->found_posts; //performance risk?
}

I'm sure that ES works nicely if i enable it. The problem is that the result doesn't output stuff based on attachment and excerpt even if i find them indexed. Also, it looks like my custom fields are same not considered.

Maybe i need to modify the output query but i don't find where. Someone can help ?

Thanks

0x572f00 commented 9 years ago

print_r($args) in build_query is :

Array ( [0] => post_content [1] => post_title [2] => post_type [3] => post_excerpt [4] => post_date ) Array ( [query] => Array ( [bool] => Array ( [must] => Array ( [0] => Array ( [query_string] => Array ( [fields] => Array ( [0] => category_name^5 [1] => post_tag_name^8 [2] => post_content.english^8 [3] => post_title.english^10 [4] => post_excerpt.english^10 [5] => main_dominante_color.english^10 )

                                        [query] => signature
                                    )

                            )

                    )

            )

    )

)

Looks that I miss something before here.