Advertisement:

Author Topic: Custom field search  (Read 5452 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #30 on: June 17, 2018, 09:08:47 pm »
This will slow down your db queries because it searches directly into your table.  The osclass search is made not into the table that helds the items' title and description, but in the full index generated when the item was saved. You can read more about this online.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #31 on: June 17, 2018, 09:29:14 pm »
In order to not loose the advantages offered by full index, you need to modify the core in order to generate full index for metas column and then modify the search to search also into that full index.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #32 on: June 17, 2018, 10:13:00 pm »
This will slow down your db queries because it searches directly into your table.  The osclass search is made not into the table that helds the items' title and description, but in the full index generated when the item was saved. You can read more about this online.

in this function, first part keyword_wildcard is also slow down db? or just second part customfield search in function slow down db?


can you please help me to fix it to search by location too?
« Last Edit: June 17, 2018, 10:15:08 pm by Sophia_OS »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #33 on: June 17, 2018, 10:45:50 pm »
The wildcard is used on full index, it returns more results, so yes, but not so much as querying directly into the db tabes.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #34 on: June 18, 2018, 12:12:25 am »
The wildcard is used on full index, it returns more results, so yes, but not so much as querying directly into the db tabes.

can you please help me to fix this function to search by location too?
why with this function it doesn't search by location?
« Last Edit: June 18, 2018, 12:16:02 am by Sophia_OS »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #35 on: June 18, 2018, 12:39:01 am »
I'm on my phone now. Try to var_dump();die; on a test server the whole query to see it.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #36 on: June 18, 2018, 01:26:34 am »
I'm on my phone now. Try to var_dump();die; on a test server the whole query to see it.

you know what? with this function it searches the custom-fields very good. the only problem is that on search.php (modern theme) when you select a location, it doesn't find by that location.
i'm waiting for you to take a look at this function and test it with a computer. hopefully you fix that. thanks.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #37 on: June 18, 2018, 08:56:41 am »
Quote from: Sophia_OS link=topic=37399.msg163186#msg163186 date=1529253

[code
function cust_search_keyword_wildcard_with_customfield($params) {

    if ($params['sPattern']) {
        $mSearch =  Search::newInstance();
        $query_elements = (array) json_decode($mSearch->toJson());
        $pattern = $query_elements['sPattern'];


        $query_elements['sPattern'] = str_replace(' ', '* ', $pattern) . '*';

        $mSearch->setJsonAlert($query_elements);

        // Search by customfield too
        $mSearch->addJoinTable(count($query_elements['tables_join']), DB_TABLE_PREFIX."t_item_meta u", "pk_i_id = u.fk_i_item_id", 'LEFT');

        $aPattern = explode(' ', $pattern);
        $customfieldCond = '';

        foreach ($aPattern as $word) {
            if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);
        }

        $mSearch->addConditions("1 = 1 " . $customfieldCond);
        $mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
    }
}

osc_add_hook('search_conditions', 'cust_search_keyword_wildcard_with_customfield', 1);

[/code]

I gues you need to add conditions for region and maybe category   keys from the $params parameter. I can't test it locally. Maybe Teseo can have a look.

Also, does your filter work? Is your search returning only results from a selected category?
« Last Edit: June 18, 2018, 08:58:18 am by marius-ciclistu »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #38 on: June 18, 2018, 09:58:16 am »
Alright, we wait for teseo to take a look at this function.
Search for custom fields is working great. The only problem is that dosnt work by selecting location in search.php (modern theme)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #39 on: June 18, 2018, 10:24:11 am »
Swich to bender(put that function into functions.php) and test. If it doesn't work it's not theme related.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #40 on: June 18, 2018, 07:34:23 pm »
Swich to bender(put that function into functions.php) and test. If it doesn't work it's not theme related.

no its not theme related

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Custom field search
« Reply #41 on: June 18, 2018, 08:53:31 pm »
I think this is the problem.

 foreach ($aPattern as $word) {
            if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);
        }

That || ( or ) makes results show even if they don't belong to a region.

Is that the behaviour?

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Custom field search
« Reply #42 on: June 18, 2018, 10:42:09 pm »
I think this is the problem.

 foreach ($aPattern as $word) {
            if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);
        }

That || ( or ) makes results show even if they don't belong to a region.

Is that the behaviour?

Hello,

I suggest you put OR queries between braces. I've had a similar problem on one plugin I worked on, if I would do this like I did on the plugin it would look like this:

Code: [Select]
<?php
$customfieldCond 
'(';

foreach (
$aPattern as $word) {
        if (
$word$customfieldCond .= sprintf(" || u.s_value like '%%%s%%'"$word);
}

$customfieldCond .= ')';
?>


Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #43 on: June 18, 2018, 11:18:56 pm »
I think this is the problem.

 foreach ($aPattern as $word) {
            if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);
        }

That || ( or ) makes results show even if they don't belong to a region.

Is that the behaviour?

but it doesn't work if i remove ||

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Custom field search
« Reply #44 on: June 18, 2018, 11:25:31 pm »
I think this is the problem.

 foreach ($aPattern as $word) {
            if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);
        }

That || ( or ) makes results show even if they don't belong to a region.

Is that the behaviour?

Hello,

I suggest you put OR queries between braces. I've had a similar problem on one plugin I worked on, if I would do this like I did on the plugin it would look like this:

Code: [Select]
<?php
$customfieldCond 
'(';

foreach (
$aPattern as $word) {
        if (
$word$customfieldCond .= sprintf(" || u.s_value like '%%%s%%'"$word);
}

$customfieldCond .= ')';
?>


Regards.

@patrickFromCroatia
it didn't work, it even didn't find custumfields  :(