• Resolved kolshix

    (@kolshix)


    search form

    	<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ) ?>" >
    	<label class="screen-reader-text" for="s">search: </label>
    	<input type="text" value="<?php echo '' . get_search_query()  ?>" name="s" id="s" />
    	
    	<input type="hidden" value="1" name="sentence" /> or 	<input type="hidden" value="1" name="exact" />
    
    	<input type="submit" id="searchsubmit" value="search" />
    	</form>

    a search form – do not work in terms of her – sentence and exact/

    How to fix it and make it work with relevansi sentence and exact?
    I’m looking for a “good friend” but finds “a good big friend”

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mikko Saari

    (@msaari)

    If you want exact phrase matching, you need to use quotes. Search for "good friend" instead of good friend.

    Thread Starter kolshix

    (@kolshix)

    I know that (ordinary users do not know it) and so just in case asked.
    Now I am looking for a solution how to create a search form with checkbox “exact match” – where the user search in the address bar will be added to quotes

    old
    /?s=good+friends

    new “exact match” search
    /?s=”good+friends”

    —————
    without plugin – sentence and exact – working, but I like relevanssi and I want to continue to use it

    • This reply was modified 7 years, 3 months ago by kolshix.
    Plugin Author Mikko Saari

    (@msaari)

    Create a pre_get_posts filter function that adds quotes around the search term when the checkbox is set, it’s simple as that.

    Thread Starter kolshix

    (@kolshix)

    That’s right?

    in searh form

    
    <input type="checkbox" name="exact-match" value="1" />
    </form>
    

    in Functions

    
    function search_exact_match($query) {	
    	if ($query->is_search && isset( $_GET['exact-match'] )   ) {
    		$exact_match = '"' . get_search_query( s ) . '"';
    		$query->set( 's', $exact_match) ;
    	} else {
    		return false;
    	}
    }
    add_action('pre_get_posts', 'search_exact_match');
    
    • This reply was modified 7 years, 3 months ago by kolshix.
    • This reply was modified 7 years, 3 months ago by kolshix.
    Plugin Author Mikko Saari

    (@msaari)

    Yes, that’s how – though it may be a good idea to check if there are any quotes in the search query before adding your own, multiple quotes may break the search.

    Also, get_search_query() is escaped with esc_attr(), that may be a problem. Probably better to use $query->query_vars['s'].

    Thread Starter kolshix

    (@kolshix)

    not working with ” ‘ ” – not found

    
    function search_exact_match($query) {	
    	if ($query->is_search && isset( $_GET['exact-match'] )   ) {
    		$exact_match = '"' . esc_attr( get_search_query( ) ). '"';
                    $query->query_vars['s'] = $exact_match;
                    //  $query->query_vars['s'] = esc_attr($exact_match);
                    //  $query->query_vars['s'] = '"' . $exact_match . '"';
    	} else {
    		return false;
    	}
    }
    add_action('pre_get_posts', 'search_exact_match');
    

    if search ” mom’s good friends “- not found

    how to set up Search Terms with an apostrophe?

    • This reply was modified 7 years, 2 months ago by kolshix.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘sentence and exact’ is closed to new replies.