Forum Replies Created

Viewing 15 replies - 1 through 15 (of 167 total)
  • Thread Starter syrupcore

    (@syrupcore)

    Clarifies them both perfectly. Thank you for very much taking the time.

    Thread Starter syrupcore

    (@syrupcore)

    Cheers, Mikko. Yep, having the minimum set to “1” is working fine in practice.

    There’s no easy solution to make the minimum length apply to just one thing, because the same minimum length is used in indexing and in searching.

    Makes sense. Indexing takes roughly the same time regardless of minimum. When searching for one or two character phrases though, it takes quite a bit longer but that is sort of expected (though I dunno if regular users will be expecting it!). Almost want to say the length doubles with each character removed but I haven’t measured it or anything.

    Try replacing:

    $search_results = new WP_Query( array( 's' => $s, 'posts_per_page' => -1 ) );
    $total = $search_results->post_count;

    with

    $total = $wp_query->found_posts;

    instead of instantiating a new WP_Query. Think that’s basically wiping out relevanssi.

    Also note $wp_query->found_posts will give you the total results for the query while $wp_query->post_count will only return how many posts objects were returned for the current view. That is, you may have 40 total results for the term red but if you have it set to display 10 results per page, post_count will be 10 while found_posts will be 40. For normal WP searches, the code you have would be fine due to the -1 but Relevanssi doesn’t work with posts_per_page.

    You can use relevanssi_match filter for this.

    See the second example on this page: https://www.relevanssi.com/knowledge-base/relevanssi-match/

    Do you mean including the author of each search result on the search results page? That would depend on your search.php set up. If so, you can just include author template tags within your loop.

    As far as a Google Maps search, you can just do that with Javascript within your search results template. Probably easiest to include the script block directly within the results template (or included template part) because then you’ll have access to the searched term.

    Using Google’s example code, replace performSearch().request{}.keyword (set to “best view” in the example) with <?php the_search_query(); ?>. There are other ways to use the maps API for searching, depending on what you want to do, but presuming you’ve including the HTML and API JS properly, that orta ‘just work’. It will appear a little after the local results appear but gmaps searches are blazing fast on the whole.

    I’ve been thinking about building a keyword suggestion UI on top of Relevanssi. Haven’t started but here’s what I’m thinking in case you want to give it a go @world2cycle.

    1. Polling the wp_relevanssi_log table, pull any log entry that has more than, say, 5 in the hits column. Create a JS object with it (keeping the hits number).
    2. Make a JS array from that object that is (somehow) sorted by 1) number of hits and 2) number of occurrences within the log. That would make the list sorted by both usefulness (# of hits) and popularity (# of occurrences).
    3. Use something like Awesomeplete/Typeahead/whateverlibrary to actually offer the suggestions from the JS object.
    4. Can also pull post titles, tags, categories, etc to put into the same JS object the autocomplete library will pull from. Typeahead actually has some create facilities for using multiple JS objects and presenting them separately within the suggestions so you could, for example, have keywords, posts and tags all separated.

    I don’t think it would actually be all that hard I just haven’t found the time to try it out.

    Thread Starter syrupcore

    (@syrupcore)

    Thank you, Mikko!

    Thread Starter syrupcore

    (@syrupcore)

    Aha! in /lib/search.php, there is a variable called $remove_stopwords which is hard coded to true. A couple of lines later, this happens:

    $terms = relevanssi_tokenize($q, $remove_stopwords);

    And since the second argument for relevanssi_tokenize is $remove_stops, the stopwords never get through. When I set “$remove_stopwords” to false, all works as expected. Guess that would need to be somehow tied into the possible filter?

    Thread Starter syrupcore

    (@syrupcore)

    Thanks for this, Mikko. I changed the line in /lib/indexing.php and reindexed. Good news is: it indexed the stopwords in titles (I checked the wp_relevanssi table via mysql directly). Unfortunately, when I search for one of the stopwords I know it indexed… I get no results. Do I need to change something else?

    Thank you both! Helped me quite a bit. I’m using CMB2’s “Related Posts Field” which stores a single ‘related’ post ID. Here’s what worked for me:

    add_filter('relevanssi_content_to_index', 'MY_include_related_content', 10, 2);
    add_filter('relevanssi_excerpt_content', 'MY_include_related_content', 10, 2);
    
    function MY_include_related_content($content, $post) {
    
        $related = get_post_meta( $post->ID, 'custom_field_with_post_id', true );
    
        if (is_numeric($related)) {
    		$content .= apply_filters('the_content', get_post_field('post_content', $related));
    	}
    
        return $content;
    }
    

    @mikko also posted this over on the blog post that lead me.

    Thread Starter syrupcore

    (@syrupcore)

    I’m in!

    Thread Starter syrupcore

    (@syrupcore)

    Thanks very much, Michael. Totally missed that hook. I saw https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#using-the-dynamic-beforeafter-form-hooks at some point but didn’t put 2 and 2 together. Using that along with separated meta boxes (I was cramming it all into one giant box) is what I c/should do.

    I guess this is a feature request then. ?? To whatever extent is reasonable, have feature parity for group fields. I understand enough to know that they’re very different beasts and feature parity isn’t possible (or even needed for parts of it) but it would be sweet to have these sorts of row manipulators available to them if possible.

    Would also be handy to have a single CMB2 wiki page with all of the available CMB2 hooks listed on it. A sort of one-stop-shop to look in when you want to augment the behavior of CMB2. I browsed the wiki and searched around the internets before asking this here but I don’t think I know/knew enough to plop in the right keywords to have that appear.

    Anyway, thanks again. Marking as resolved.

    Thread Starter syrupcore

    (@syrupcore)

    Thanks, Michael.

    Basic test code follows. In this example I tried basically all options on both places I could think to try them. I’m tried reading through the source to see if this was even possible but TBH, got a little (ok, a lot) lost.

    My use case is: this group contains a set of fields with 4 different fields. I want to have some introductory text in a particular set of styles before the group starts. I found a way around that by including a “title” field which does support all of the before/after stuff. I’m also using CSS to cheat and make the group look like a separate set of meta boxes. Without before and after, that requires some fairly fragile CSS selectors instead of generic classes.

    On this same note, it would be lovely if group fields also supported row_classes.

    $local_actions_group_field = $coa_cmb->add_field( array(
    	'id' => $prefix . 'local_conservation_actions_and_plans',
    	'type'        => 'group',
    	'description' => __( 'Local Conservation Action or Plans', 'odfw' ),
    	'before_row'   => '<p>Testing <b>"before_row"</b> parameter</p>',
    	'before'       => '<p>Testing <b>"before"</b> parameter</p>',
    	'before_field' => '<p>Testing <b>"before_field"</b> parameter</p>',
    	'after_field'  => '<p>Testing <b>"after_field"</b> parameter</p>',
    	'after'        => '<p>Testing <b>"after"</b> parameter</p>',
    	'after_row'    => '<p>Testing <b>"after_row"</b> parameter</p>',
    	'options'     => array(
    		'group_title'   => __( 'Action or Plan {#}', 'odfw' ),
    		'add_button'    => __( 'Add another Local Conservation Action or Plan', 'odfw' ),
    		'remove_button' => __( 'Remove this entry', 'odfw' ),
    		'sortable'      => true, // beta
    		'before_row'   => '<p>Options Testing <b>"before_row"</b> parameter</p>',
    		'before'       => '<p>Options Testing <b>"before"</b> parameter</p>',
    		'before_field' => '<p>Options Testing <b>"before_field"</b> parameter</p>',
    		'after_field'  => '<p>Options Testing <b>"after_field"</b> parameter</p>',
    		'after'        => '<p>Options Testing <b>"after"</b> parameter</p>',
    		'after_row'    => '<p>Options Testing <b>"after_row"</b> parameter</p>',
    		)
    ));
    Thread Starter syrupcore

    (@syrupcore)

    Well, I tried this and it seems to be working. I took out the negative look aheads and added > and < to either side main capture. In some brief testing it seems to be fine but my Regex Fu is weak enough that I’m not entirely sure what problem I’ve just created! Can anyone tell me?

    Here’s the original:

    $regex = "(?!<.*?)([\s\'\"\.\x98\x99\x9c\x9d\xCB\x9C\xE2\x84\xA2\xC5\x93\xEF\xBF\xBD\(\[\{])($old_text)([\s\'\"\x98\x99\x9c\x9d\xCB\x9C\xE2\x84\xA2\xC5\x93\xEF\xBF\xBD\?\!\.\,\-\+\]\)\}])(?![^<>]*?>)";

    Here’s the one I’m using:

    $regex = "([\s\>\'\"\.\x98\x99\x9c\x9d\xCB\x9C\xE2\x84\xA2\xC5\x93\xEF\xBF\xBD\(\[\{])($old_text)([\s\<\'\"\x98\x99\x9c\x9d\xCB\x9C\xE2\x84\xA2\xC5\x93\xEF\xBF\xBD\?\!\.\,\-\+\]\)\}])";

Viewing 15 replies - 1 through 15 (of 167 total)