• Resolved ivomasterche

    (@ivomasterche)


    Hi,

    I’ve managed to make relevanssi to search in custom fields using relevanssi_do_query(), but it doesn’t find posts containing the search term in serialized custom field.

    I am 100% sure that a few weeks ago it was working even without the relevanssi_do_query function, but i guess it stopped after an update, i am not sure when exactly.

    Please confirm that it should work in serialized custom fields too.

    Thank you in advance.

    http://wordpress.org/extend/plugins/relevanssi/

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

    (@msaari)

    Please provide more details. Exactly how are you searching custom fields using relevanssi_do_query()? If you’re using the hack that sets ‘cat’ to ‘custom’ in order to filter by custom field, do note that it was disabled in 3.0. You need Premium to filter by custom field (ie. search for term X in posts with word Y in custom field Z).

    If you don’t need filtering, but want just to search custom field content (ie. search for term X in post content or custom field content), that still works with free Relevanssi. If you’ve set “Custom fields to index” to list the custom fields you want to index (or to “all” or “visible”), you shouldn’t need any tricks to fetch posts by custom field content.

    Serialized custom fields should be no problem, as Relevanssi uses get_post_meta() to read the custom fields, and that should unserialize them.

    Thread Starter ivomasterche

    (@ivomasterche)

    Hi,

    Thank you for you answer.

    I am having an eshop site, which stores some of the custom information of the products in one serialized meta_key in wp_postmeta (like unique article id) and other information in normal custom fields (like price) when i search for that unique id it finds nothing but when i search with data found in the price it shows me the posts.

    It appeared that it is the same with both

    global $wp_query;
    $rq = new WP_Query();
    $rq->query_vars = $wp_query->query_vars;
    relevanssi_do_query($rq);

    in the search.php
    and with the general search.

    I have just updated to the last version – 3.0.4 and i am using Custom fields to index: all

    Plugin Author Mikko Saari

    (@msaari)

    I don’t know why it wouldn’t work. How the serialized meta_key is done? What does it unserialize into? If it’s an array, it should work, but if it’s an object then yes, it might not get indexed. Can you give me a sample field to experiment on?

    Thread Starter ivomasterche

    (@ivomasterche)

    Hi, again

    Thank you for keeping in touch.

    I am using a plugin called eshop, which i kind of DON’T recommend and i am not sure how exactly works but the following is one meta key:

    (22350, 8355, '_eshop_product', 'a:8:{s:3:"sku";s:7:"2502062";s:8:"products";a:30:{i:1;a:4:{s:6:"option";s:7:"2502062";s:5:"price";s:6:"102.42";s:6:"weight";s:0:"";s:9:"saleprice";s:5:"66.57";}i:2;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:3;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:4;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:5;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:6;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:7;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:8;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:9;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:10;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:11;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:12;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:13;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:14;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:15;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:16;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:17;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:18;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:19;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:20;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:21;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:22;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:23;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:24;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:25;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:26;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:27;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:28;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:29;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:30;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}}s:11:"description";s:17:"Стол Golf GTP";s:8:"shiprate";s:1:"F";s:8:"featured";s:3:"Yes";s:4:"sale";s:3:"yes";s:10:"cart_radio";s:1:"0";s:6:"optset";a:1:{i:0;s:2:"38";}}')

    the format is:

    wp_postmeta` (
    meta_id bigint(20) unsigned NOT NULL auto_increment,
    post_id bigint(20) unsigned NOT NULL default ‘0’,
    meta_key varchar(255) default NULL,
    meta_value longtext,
    PRIMARY KEY (meta_id),
    KEY post_id (post_id),
    KEY meta_key (meta_key)
    ) `

    It should contain all the info including predefined number of variations which if are not fulfilled … stay empty.

    Since i needed the price for other operations i’ve made a plugin of my own which unserializes the data and puts it in simple custom field, (that is indexed correctly) by using:

    $eshop_product=maybe_unserialize(get_post_meta( $post->ID, '_eshop_product',true ));
    $duplicate_price = $eshop_product['products']['1']['price'];
    Plugin Author Mikko Saari

    (@msaari)

    I tried the example field you posted, and it works – I tried searching for “saleprice” and Relevanssi found it. Relevanssi doesn’t unserialize the field, just passes the serialized value for tokenizer, which will then split it into words.

    So, yes, it should work. Are you sure the custom field is being indexed? Since it is a hidden field, setting the custom field option to “visible” is not going to grab it.

    Thread Starter ivomasterche

    (@ivomasterche)

    Ok, thank you for your efforts.

    In this case i guess it’s a collision with some other plugin. I’ll try to disable everything, reindex and search.

    How can i check the indexed date ?

    Plugin Author Mikko Saari

    (@msaari)

    You can’t, it’s not stored anywhere.

    Thread Starter ivomasterche

    (@ivomasterche)

    Hi,

    Unfortunately i couldn’t make it work.
    I tried to uninstall and the to install the plugin, tried disabling other plugins but it didn’t work.

    It is indexing the posts because i can search for other custom fields, but not for that serialized one.

    Maybe it’s something with the eshop plugin, as i said i found that i don’t like it very much but too late, after inserting a lot of products. Unfortunately it’s not even a single plugin, its needs some 3 or 4 additional plugins making small changes and adding features to the main plugin, so it’s quite complicated.

    Thank you once again for trying to help me i’ll still continue to use Relevanssi in other projects.

    Plugin Author Mikko Saari

    (@msaari)

    Ok, probably the other plugin then. That’s life with WP, and I know your pain – I had a rather unpleasant membership plugin at Relevanssi.com, took the trouble to switch to another and it’s been better – but far from perfect – afterwards.

    Anyway, based on my tests serialized custom fields should work, but the results may not always be what you expect, as Relevanssi does not unserialize the field contents.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] serialized custom fields problem’ is closed to new replies.