Disable Searching 'Ending with' for Index Table

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Disable Searching 'Ending with' for Index Table

This topic contains 13 replies, has 2 voices, and was last updated by samyagshah samyagshah 5 years, 5 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #19759
    samyagshah
    samyagshah
    Participant

    Is there any way to disable searching ‘Ending with’ for Index Table?

    For example :
    – “kar” will match “karate”
    – “rate” shouldn’t match “karate”

    #19762
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Maybe, by editing the database table structure. You could try changing the ‘term_reverse’ row in the database from varchar(50) to boolean. That would basically make the field usable, but the information stored would be neglected.

    (before making any changes, I highly recommend having a full site + db backup!)
    If you have a GUI databse editor like PHPMyAdmin, then it should be easyer. The table you should look for is wp_asp_index. Then you could edit the term_reverse field, and change it to boolean.

    I have not tested this, it is just a theory, but there is a slight chance, that it may as well work.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #19779
    samyagshah
    samyagshah
    Participant

    Thanks its working. But one new problem.

    When searched for particular Taxonomy, products associated to it is displayed, but actual taxonomy with product count in bracket is not displayed.

    Say product category taxonomy named ‘Product-Category-1’ has 2 different products ‘Product-1’ & ‘Product-2’. When searched for ‘Product-Category-1’, ‘Product-1’ & ‘Product-2’ are displayed but actual ‘Product-Category-1’ with Product count is not displayed.

    #19788
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Make sure that the under the General Options -> Sources 2 the taxonomy in which the category belongs to is selected for returning as results: https://i.imgur.com/WmydGjP.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #19793
    samyagshah
    samyagshah
    Participant

    Under Sources 2, if taxonomies in which the category belongs to is selected, all 3 types of search logic viz. Starting with, ending with & anywhere is used only for Sources 2 but I want only “starting with” to be used.

    I am assuming you must be using operator like %keyword%. Can I update this logic to keyword%

    I tried changing General Options -> Logic & Behaviour -> Secondary logic -> AND but it didn’t work.

    #19794
    samyagshah
    samyagshah
    Participant

    I made following changes in /includes/classes/search/class-asp-search-terms.php :

    1. Changed default value of $wcl variable to empty string.

    $wcl = ''; // Wildcard Left

    2. Added another where clause to retrieve values where the word is not the first in the title string.

    /*----------------------- Title query ---------------------------*/
                    if ($kw_logic == 'or' || $kw_logic == 'and' || $is_exact ) {
                        $parts[] = "
                           (" . $pre_field . $wpdb->terms . ".name" . $suf_field . " LIKE $pre_like'$wcl" . $word . "$wcr'$suf_like 
                        OR  " . $pre_field . $wpdb->terms . ".name" . $suf_field . " LIKE $pre_like'$wcr " . $word . "$wcr'$suf_like
                        )";
    

    And its giving desire output, but its affecting the performance. Could you please review it.

    One quick question, since all required Taxonomies are indexed in index table can’t we disable source2 & add logic returning taxonomy terms as results in results returned by index table query?

    • This reply was modified 5 years, 6 months ago by samyagshah samyagshah.
    • This reply was modified 5 years, 6 months ago by samyagshah samyagshah.
    • This reply was modified 5 years, 6 months ago by samyagshah samyagshah.
    #19803
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    That query is redundant in my opinion, because the first part (before the OR) is included within the second part. Wildcard searches using the ‘%’ symbol, mean, that there is either anything before the phrase or nothing. Basically ‘%phrase%’ includes the matches from ‘phrase%’ as well.
    The performance degradation is because of the ‘%phrase%’ double wildcard query, as that cannot be performed as an indexed query by the database engine. Only the starting with queries (aka ‘phrase%’) can be performed as indexed (huge performance difference).
    So changing the $wcl to an empty string, and not adding any additional code will give you the fastest possible results in this case.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #19807
    samyagshah
    samyagshah
    Participant

    I have added 2nd query in order to retrieve values where the word is not the first in the string. Say for Example:
    Taxonomy Title is: “Ajax Search Pro – Very Powerful Search Plugin.”
    Search Keyword is: “Search”

    No results are retrieved since Search Keyword is not first in the string. (In case of Source 2)

    Logic used in 2nd query is : % search-keyword%
    There is space between % & search-keyword

    Are we on the same page?

    #19809
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I understand that. I am saying, that not changing $wcl should give the exact same results as changing + adding the query, as it is basically the same query but in a more complicated way.
    – Because without the change, one like query match is executed for ‘%phrase%’.
    – Whith the change, you have 2 like queries for ‘phrase%’ and ‘%phrase%’, where the ‘%phrase%’ actually includes everything matching the ‘phrase%’ as well.
    I am not sure if I explained correctly, sorry about that.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #19811
    samyagshah
    samyagshah
    Participant

    Please find my comments below:

    For #1: Because without the change, one like query match is executed for ‘%phrase%’.

    Comment: Yes you are right.

    For #2: Whith the change, you have 2 like queries for ‘phrase%’ and ‘%phrase%’, where the ‘%phrase%’ actually includes everything matching the ‘phrase%’ as well.

    Comment: For 2nd like query there is space between % & phrase.
    ‘<% phrase%>’

    You are the expert, you can only tell me what needs to be done in order to achieve desired result.

    #19812
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh, my bad, I didn’t notice that. That is very different then, sorry about that.
    In that case, that is perfectly correct, I don’t think it can be further optimized unfortunately.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #19814
    samyagshah
    samyagshah
    Participant

    No need to say sorry. 🙂

    Two quick questions:
    1. Since all required Taxonomies are indexed in index table can’t we disable source2 & add logic, returning taxonomy terms as results in results returned by index table query?
    2. If #1 is not possible, is there any other way of adding above discussed like statements without modifying core files?

    #19825
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    1. Unfortunately not, because the index table only contains the ID and the keyword from the taxonomy column. The taxonomy ID and the and term ID are not stored in there.

    2. Actually, I think there is. You can add additional WHERE clause using this filter:

    $add_where = apply_filters('asp_term_query_add_where', '', $args, $this->s, $this->_s);

    Basically a code like this:

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #19961
    samyagshah
    samyagshah
    Participant

    Ok Thanks. Let me try.

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.