Making WordPress.org


Ignore:
Timestamp:
06/19/2016 12:31:50 PM (10 years ago)
Author:
tellyworth
Message:

Search: include modified date cutoff, phrase query.

Modified timestamps in the DB right now are incorrect, so the 2-year age cutoff is not currently reflected in search results; but it should work once the data is fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r3310 r3470  
    251251                        $posts_per_page = 15;
    252252
     253                $date_cutoff = strftime( '%Y-%m-%d', strtotime( '-2 years' ) );
     254                $date_today = strftime( '%Y-%m-%d' );
     255
    253256                // Start building the WP-style search query args
    254257                // They'll be translated to ES format args later
    … …  
    259262                        'orderby'        => $query->get( 'orderby' ),
    260263                        'order'          => $query->get( 'order' ),
     264                        // plugin directory specific:
     265                        'date_range'     =>  array( 'field' => 'modified', 'gte' => $date_cutoff, 'lte' => $date_today ),
    261266                );
    262267
    … …  
    553558                if ( $args['query'] ) {
    554559                        $analyzer = Jetpack_Search::get_analyzer_name( $this->blog_lang );
    555                         $query = array( 'multi_match' => array(
    556                                 'query'  => $args['query'],
    557                                 'fields' => $args['query_fields'],
    558                                 'operator'  => 'and',
    559                                 'type'  => 'cross_fields',
    560                                 'analyzer' => $analyzer
    561                         ) );
     560                        $query = array(
     561                                'bool' => array(
     562                                        'must' => array(
     563                                                'multi_match' => array(
     564                                                        'query'  => $args['query'],
     565                                                        'fields' => $args['query_fields'],
     566                                                        'type'  => 'cross_fields',
     567                                                        'analyzer' => $analyzer
     568                                                ),
     569                                        ),
     570                                        'should' => array(
     571                                                'multi_match' => array(
     572                                                        'query'  => $args['query'],
     573                                                        'fields' => $args['query_fields'],
     574                                                        'type'  => 'phrase',
     575                                                        'analyzer' => $analyzer
     576                                                ),
     577                                        ),
     578                                ),
     579                        );
     580
    562581                        $es_query_args['query'] = Jetpack_Search::score_query_by_recency( $query );
    563582
    … …  
    611630                        $es_query_args['filter'] = array( 'match_all' => new stdClass() );
    612631                }
    613        
     632
    614633                return $es_query_args;
    615634        }
Note: See TracChangeset for help on using the changeset viewer.