Advanced Woo Search - Version 1.92

Version Description

  • Update - Flatsome theme support
  • Update - Taxonomies search query
  • Fix - Bug with exclude filter for taxonomies search
  • Add - aws_search_tax_exclude filter
Download this release

Release Info

Developer Mihail Barinov
Plugin Icon 128x128 Advanced Woo Search
Version 1.92
Comparing to
See all releases

Code changes from version 1.91 to 1.92

advanced-woo-search.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
- Version: 1.91
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  exit;
17
  }
18
 
19
- define( 'AWS_VERSION', '1.91' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
@@ -109,6 +109,7 @@ final class AWS_Main {
109
  include_once( 'includes/class-aws-table.php' );
110
  include_once( 'includes/class-aws-markup.php' );
111
  include_once( 'includes/class-aws-search.php' );
 
112
  include_once( 'includes/class-aws-search-page.php' );
113
  include_once( 'includes/class-aws-order.php' );
114
  include_once( 'includes/class-aws-integrations.php' );
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 1.92
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: advanced-woo-search
16
  exit;
17
  }
18
 
19
+ define( 'AWS_VERSION', '1.92' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
109
  include_once( 'includes/class-aws-table.php' );
110
  include_once( 'includes/class-aws-markup.php' );
111
  include_once( 'includes/class-aws-search.php' );
112
+ include_once( 'includes/class-aws-tax-search.php' );
113
  include_once( 'includes/class-aws-search-page.php' );
114
  include_once( 'includes/class-aws-order.php' );
115
  include_once( 'includes/class-aws-integrations.php' );
includes/class-aws-helpers.php CHANGED
@@ -712,79 +712,6 @@ if ( ! class_exists( 'AWS_Helpers' ) ) :
712
 
713
  }
714
 
715
- /*
716
- * Get taxonomies search array
717
- *
718
- * @return array Terms
719
- */
720
- static public function get_tax_search_array( $search_terms ) {
721
-
722
- global $wpdb;
723
-
724
- $search_array = array();
725
-
726
- foreach ( $search_terms as $search_term ) {
727
-
728
- $search_term_len = strlen( $search_term );
729
-
730
- $search_term_norm = AWS_Plurals::singularize( $search_term );
731
-
732
- if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
733
- $search_term = $search_term_norm;
734
- }
735
-
736
- $like = '%' . $wpdb->esc_like($search_term) . '%';
737
-
738
- $search_array[] = $wpdb->prepare('( name LIKE %s )', $like);
739
-
740
- if ( $terms_desc_search = apply_filters( 'aws_search_terms_description', false ) ) {
741
- $search_array[] = $wpdb->prepare('( description LIKE %s )', $like);
742
- }
743
-
744
- }
745
-
746
- return $search_array;
747
-
748
- }
749
-
750
- /*
751
- * Get taxonomies relevance array
752
- *
753
- * @return array Relevance array
754
- */
755
- static public function get_tax_relevance_array( $search_terms ) {
756
-
757
- global $wpdb;
758
-
759
- $relevance_array = array();
760
-
761
- foreach ( $search_terms as $search_term ) {
762
-
763
- $search_term_len = strlen( $search_term );
764
-
765
- $relevance = 40 + 2 * $search_term_len;
766
-
767
- $search_term_norm = AWS_Plurals::singularize( $search_term );
768
-
769
- if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
770
- $search_term = $search_term_norm;
771
- }
772
-
773
- $like = '%' . $wpdb->esc_like($search_term) . '%';
774
-
775
- $relevance_array[] = $wpdb->prepare( "( case when ( name LIKE %s ) then {$relevance} else 0 end )", $like );
776
-
777
- if ( $terms_desc_search = apply_filters( 'aws_search_terms_description', false ) ) {
778
- $relevance_desc = 10 + 2 * $search_term_len;
779
- $relevance_array[] = $wpdb->prepare( "( case when ( description LIKE %s ) then {$relevance_desc} else 0 end )", $like );
780
- }
781
-
782
- }
783
-
784
- return $relevance_array;
785
-
786
- }
787
-
788
  }
789
 
790
  endif;
712
 
713
  }
714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  }
716
 
717
  endif;
includes/class-aws-integrations.php CHANGED
@@ -123,6 +123,11 @@ if ( ! class_exists( 'AWS_Integrations' ) ) :
123
  add_filter( 'aws_posts_per_page', array( $this, 'wc_product_table_posts_per_page' ) );
124
  }
125
 
 
 
 
 
 
126
  }
127
 
128
  /*
123
  add_filter( 'aws_posts_per_page', array( $this, 'wc_product_table_posts_per_page' ) );
124
  }
125
 
126
+ // Flatsome theme remove search page blocl
127
+ if ( isset( $_GET['type_aws'] ) && function_exists( 'flatsome_pages_in_search_results' ) ) {
128
+ remove_action('woocommerce_after_main_content','flatsome_pages_in_search_results', 10);
129
+ }
130
+
131
  }
132
 
133
  /*
includes/class-aws-search.php CHANGED
@@ -204,19 +204,8 @@ if ( ! class_exists( 'AWS_Search' ) ) :
204
 
205
  if ( $taxonomies_archives && is_array( $taxonomies_archives ) && ! empty( $taxonomies_archives ) ) {
206
 
207
- foreach( $taxonomies_archives as $taxonomies_archive_name ) {
208
- $res = $this->get_taxonomies( $taxonomies_archive_name );
209
-
210
- if ( $taxonomies_archive_name === 'product_cat' ) {
211
- $res = apply_filters( 'aws_search_results_categories', $res, $s );
212
- }
213
-
214
- if ( $taxonomies_archive_name === 'product_tag' ) {
215
- $res = apply_filters( 'aws_search_results_tags', $res, $s );
216
- }
217
-
218
- $custom_tax_array[$taxonomies_archive_name] = $res;
219
- }
220
 
221
  }
222
 
@@ -759,176 +748,6 @@ if ( ! class_exists( 'AWS_Search' ) ) :
759
  return strlen( $b ) - strlen( $a );
760
  }
761
 
762
- /*
763
- * Query product taxonomies
764
- */
765
- private function get_taxonomies( $taxonomy ) {
766
-
767
- global $wpdb;
768
-
769
- $result_array = array();
770
- $excludes = '';
771
- $search_query = '';
772
- $relevance_query = '';
773
- $s_string_with_chars = $this->data['s_nonormalize'];
774
- $search_string_unfiltered = '';
775
-
776
- $filtered_terms = $this->data['search_terms'];
777
-
778
- $filtered_terms_full = $wpdb->prepare( '( name LIKE %s )', '%' . $wpdb->esc_like( $s_string_with_chars ) . '%' );
779
-
780
- /**
781
- * Max number of terms to show
782
- * @since 1.73
783
- * @param int
784
- */
785
- $terms_number = apply_filters( 'aws_search_terms_number', 10 );
786
-
787
- if ( $filtered_terms && ! empty( $filtered_terms ) ) {
788
-
789
- $search_array = AWS_Helpers::get_tax_search_array( $filtered_terms );
790
-
791
- $relevance_array = AWS_Helpers::get_tax_relevance_array( $filtered_terms );
792
-
793
- // Search terms with special chars
794
- $no_normalized_str = $s_string_with_chars;
795
-
796
- $no_normalized_str = AWS_Helpers::html2txt( $no_normalized_str );
797
- $no_normalized_str = trim( $no_normalized_str );
798
-
799
- $no_normalized_str = strtr( $no_normalized_str, AWS_Helpers::get_diacritic_chars() );
800
-
801
- if ( function_exists( 'mb_strtolower' ) ) {
802
- $no_normalized_str = mb_strtolower( $no_normalized_str );
803
- }
804
-
805
- $search_array_chars = array_unique( explode( ' ', $no_normalized_str ) );
806
- $search_array_chars = AWS_Helpers::filter_stopwords( $search_array_chars );
807
-
808
- if ( $search_array_chars ) {
809
- foreach ( $search_array_chars as $search_array_chars_index => $search_array_chars_term ) {
810
- if ( array_search( $search_array_chars_term, $filtered_terms ) ) {
811
- unset( $search_array_chars[$search_array_chars_index] );
812
- }
813
- }
814
- }
815
-
816
- if ( count( $search_array_chars ) === 1 && $search_array_chars[0] === $s_string_with_chars ) {
817
- $search_array_chars = array();
818
- }
819
-
820
- if ( $search_array_chars ) {
821
- $search_string_unfiltered = sprintf( 'OR ( %s )', implode( ' OR ', AWS_Helpers::get_tax_search_array( $search_array_chars ) ) );
822
- }
823
-
824
- } else {
825
-
826
- return $result_array;
827
-
828
- }
829
-
830
- if ( $relevance_array && ! empty( $relevance_array ) ) {
831
- $relevance_query = sprintf( ' (SUM( %s )) ', implode( ' + ', $relevance_array ) );
832
- } else {
833
- $relevance_query = '0';
834
- }
835
-
836
- $search_query .= sprintf( ' AND ( ( %s ) OR %s %s )', implode( ' OR ', $search_array ), $filtered_terms_full, $search_string_unfiltered );
837
-
838
- /**
839
- * Exclude certain terms from search
840
- * @since 1.58
841
- * @param array
842
- */
843
- $exclude_terms = apply_filters( 'aws_terms_exclude_' . $taxonomy, array() );
844
-
845
- if ( $exclude_terms && is_array( $exclude_terms ) && ! empty( $exclude_terms ) ) {
846
- $excludes = $wpdb->prepare( " AND ( " . $wpdb->terms . ".term_id NOT IN ( %s ) )", implode( ',', $exclude_terms ) );
847
- }
848
-
849
- $sql = "
850
- SELECT
851
- distinct($wpdb->terms.name),
852
- $wpdb->terms.term_id,
853
- $wpdb->term_taxonomy.taxonomy,
854
- $wpdb->term_taxonomy.count,
855
- {$relevance_query} as relevance
856
- FROM
857
- $wpdb->terms
858
- , $wpdb->term_taxonomy
859
- WHERE 1 = 1
860
- {$search_query}
861
- AND $wpdb->term_taxonomy.taxonomy = '{$taxonomy}'
862
- AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
863
- AND count > 0
864
- {$excludes}
865
- GROUP BY term_id
866
- ORDER BY relevance DESC, term_id DESC
867
- LIMIT 0, {$terms_number}";
868
-
869
- $sql = trim( preg_replace( '/\s+/', ' ', $sql ) );
870
-
871
- /**
872
- * Filter terms search query
873
- * @since 1.91
874
- * @param string $sql Sql query
875
- * @param string $taxonomy Taxonomy name
876
- * @param string $search_query Search query
877
- */
878
- $sql = apply_filters( 'aws_terms_search_query', $sql, $taxonomy, $search_query );
879
-
880
- $search_results = $wpdb->get_results( $sql );
881
-
882
- if ( ! empty( $search_results ) && !is_wp_error( $search_results ) ) {
883
-
884
- foreach ( $search_results as $result ) {
885
-
886
- if ( ! $result->count > 0 ) {
887
- continue;
888
- }
889
-
890
- if ( function_exists( 'wpml_object_id_filter' ) ) {
891
- $term = wpml_object_id_filter( $result->term_id, $result->taxonomy );
892
- if ( $term != $result->term_id ) {
893
- continue;
894
- }
895
- } else {
896
- $term = get_term( $result->term_id, $result->taxonomy );
897
- }
898
-
899
- if ( $term != null && !is_wp_error( $term ) ) {
900
- $term_link = get_term_link( $term );
901
- } else {
902
- continue;
903
- }
904
-
905
- $new_result = array(
906
- 'name' => $result->name,
907
- 'count' => $result->count,
908
- 'link' => $term_link
909
- );
910
-
911
- $result_array[] = $new_result;
912
-
913
- }
914
-
915
- /**
916
- * Filters array of custom taxonomies that must be displayed in search results
917
- *
918
- * @since 1.63
919
- *
920
- * @param array $result_array Array of custom taxonomies
921
- * @param string $taxonomy Name of taxonomy
922
- * @param string $s Search query
923
- */
924
- $result_array = apply_filters( 'aws_search_tax_results', $result_array, $taxonomy, $this->data['s'] );
925
-
926
- }
927
-
928
- return $result_array;
929
-
930
- }
931
-
932
  }
933
 
934
 
204
 
205
  if ( $taxonomies_archives && is_array( $taxonomies_archives ) && ! empty( $taxonomies_archives ) ) {
206
 
207
+ $tax_search = new AWS_Tax_Search( $taxonomies_archives, $this->data );
208
+ $custom_tax_array = $tax_search->get_results();
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  }
211
 
748
  return strlen( $b ) - strlen( $a );
749
  }
750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
751
  }
752
 
753
 
includes/class-aws-tax-search.php ADDED
@@ -0,0 +1,380 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ if ( ! class_exists( 'AWS_Tax_Search' ) ) :
8
+
9
+ /**
10
+ * Class for admin condition rules
11
+ */
12
+ class AWS_Tax_Search {
13
+
14
+ /**
15
+ * @var array AWS_Tax_Search Taxonomy name
16
+ */
17
+ private $taxonomy;
18
+
19
+ /**
20
+ * @var string AWS_Tax_Search Search string
21
+ */
22
+ private $search_string;
23
+
24
+ /**
25
+ * @var string AWS_Tax_Search Unfiltered search string
26
+ */
27
+ private $search_string_unfiltered;
28
+
29
+ /**
30
+ * @var array AWS_Tax_Search Search terms array
31
+ */
32
+ private $search_terms;
33
+
34
+ /*
35
+ * Constructor
36
+ */
37
+ public function __construct( $taxonomy, $data ) {
38
+
39
+ $this->taxonomy = $taxonomy;
40
+ $this->search_string = isset( $data['s'] ) ? $data['s'] : '';
41
+ $this->search_string_unfiltered = isset( $data['s_nonormalize'] ) ? $data['s_nonormalize'] : $this->search_string ;
42
+ $this->search_terms = isset( $data['search_terms'] ) ? $data['search_terms'] : array();
43
+
44
+ }
45
+
46
+ /**
47
+ * Get search results
48
+ * @return array Results array
49
+ */
50
+ public function get_results() {
51
+
52
+ if ( ! $this->search_terms || empty( $this->search_terms ) ) {
53
+ return array();
54
+ }
55
+
56
+ global $wpdb;
57
+
58
+ $search_query = '';
59
+ $search_string_unfiltered = '';
60
+
61
+ $filtered_terms_full = $wpdb->prepare( '( name LIKE %s )', '%' . $wpdb->esc_like( $this->search_string_unfiltered ) . '%' );
62
+
63
+ $search_array = $this->get_search_array( $this->search_terms );
64
+
65
+ $search_array_chars = $this->get_unfiltered_search_array();
66
+
67
+ if ( $search_array_chars ) {
68
+ $search_string_unfiltered = sprintf( 'OR ( %s )', implode( ' OR ', $this->get_search_array( $search_array_chars ) ) );
69
+ }
70
+
71
+ $search_query .= sprintf( ' AND ( ( %s ) OR %s %s )', implode( ' OR ', $search_array ), $filtered_terms_full, $search_string_unfiltered );
72
+
73
+ $search_results = $this->query( $search_query );
74
+ $result_array = $this->output( $search_results );
75
+
76
+ return $result_array;
77
+
78
+ }
79
+
80
+ /**
81
+ * Search query
82
+ * @param string $search_query SQL query
83
+ * @return array SQL query results
84
+ */
85
+ private function query( $search_query ) {
86
+
87
+ global $wpdb;
88
+
89
+ $excludes = '';
90
+ $taxonomies_array = array_map( array( $this, 'prepare_tax_names' ), $this->taxonomy );
91
+ $taxonomies_names = implode( ',', $taxonomies_array );
92
+
93
+ /**
94
+ * Max number of terms to show
95
+ * @since 1.73
96
+ * @param int
97
+ */
98
+ $terms_number = apply_filters( 'aws_search_terms_number', 10 );
99
+
100
+ $excludes_array = $this->get_excluded_terms();
101
+ if ( $excludes_array && ! empty( $excludes_array ) ) {
102
+ $excludes = sprintf( " AND ( " . $wpdb->terms . ".term_id NOT IN ( %s ) )", implode( ',', array_map( array( $this, 'prepare_tax_names' ), $excludes_array ) ) );
103
+ }
104
+
105
+ $relevance_array = $this->get_relevance_array();
106
+
107
+ if ( $relevance_array && ! empty( $relevance_array ) ) {
108
+ $relevance_query = sprintf( ' (SUM( %s )) ', implode( ' + ', $relevance_array ) );
109
+ } else {
110
+ $relevance_query = '0';
111
+ }
112
+
113
+ $sql = "
114
+ SELECT
115
+ distinct($wpdb->terms.name),
116
+ $wpdb->terms.term_id,
117
+ $wpdb->term_taxonomy.taxonomy,
118
+ $wpdb->term_taxonomy.count,
119
+ {$relevance_query} as relevance
120
+ FROM
121
+ $wpdb->terms
122
+ , $wpdb->term_taxonomy
123
+ WHERE 1 = 1
124
+ {$search_query}
125
+ AND $wpdb->term_taxonomy.taxonomy IN ( {$taxonomies_names} )
126
+ AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
127
+ AND count > 0
128
+ {$excludes}
129
+ GROUP BY term_id
130
+ ORDER BY relevance DESC, term_id DESC
131
+ LIMIT 0, {$terms_number}";
132
+
133
+
134
+ $sql = trim( preg_replace( '/\s+/', ' ', $sql ) );
135
+
136
+
137
+ /**
138
+ * Filter terms search query
139
+ * @since 1.91
140
+ * @param string $sql Sql query
141
+ * @param string $taxonomy Taxonomy name
142
+ * @param string $search_query Search query
143
+ */
144
+ $sql = apply_filters( 'aws_terms_search_query', $sql, $this->taxonomy, $search_query );
145
+
146
+ $search_results = $wpdb->get_results( $sql );
147
+
148
+ return $search_results;
149
+
150
+ }
151
+
152
+ /**
153
+ * Order and output search results
154
+ * @param array SQL query results
155
+ * @return array Array of taxonomies results
156
+ */
157
+ private function output( $search_results ) {
158
+
159
+ $result_array = array();
160
+
161
+ if ( ! empty( $search_results ) && !is_wp_error( $search_results ) ) {
162
+
163
+ foreach ( $search_results as $result ) {
164
+
165
+ if ( ! $result->count > 0 ) {
166
+ continue;
167
+ }
168
+
169
+ if ( function_exists( 'wpml_object_id_filter' ) ) {
170
+ $term = wpml_object_id_filter( $result->term_id, $result->taxonomy );
171
+ if ( $term != $result->term_id ) {
172
+ continue;
173
+ }
174
+ } else {
175
+ $term = get_term( $result->term_id, $result->taxonomy );
176
+ }
177
+
178
+ if ( $term != null && !is_wp_error( $term ) ) {
179
+ $term_link = get_term_link( $term );
180
+ } else {
181
+ continue;
182
+ }
183
+
184
+ $new_result = array(
185
+ 'name' => $result->name,
186
+ 'count' => $result->count,
187
+ 'link' => $term_link
188
+ );
189
+
190
+ $result_array[$result->taxonomy][] = $new_result;
191
+
192
+ }
193
+
194
+ /**
195
+ * Filters array of custom taxonomies that must be displayed in search results
196
+ *
197
+ * @since 1.63
198
+ *
199
+ * @param array $result_array Array of custom taxonomies
200
+ * @param string $taxonomy Name of taxonomy
201
+ * @param string $s Search query
202
+ */
203
+ $result_array = apply_filters( 'aws_search_tax_results', $result_array, $this->taxonomy, $this->search_string );
204
+
205
+ }
206
+
207
+ // Deprecated filters support
208
+ if ( is_array( $this->taxonomy ) ) {
209
+
210
+ if ( in_array( 'product_cat', $this->taxonomy ) ) {
211
+ $result_array = apply_filters( 'aws_search_results_categories', $result_array, $this->search_string );
212
+ }
213
+
214
+ if ( in_array( 'product_tag', $this->taxonomy ) ) {
215
+ $result_array = apply_filters( 'aws_search_results_tags', $result_array, $this->search_string );
216
+ }
217
+
218
+ }
219
+
220
+ return $result_array;
221
+
222
+ }
223
+
224
+ /**
225
+ * Get taxonomies relevance array
226
+ *
227
+ * @return array Relevance array
228
+ */
229
+ private function get_relevance_array() {
230
+
231
+ global $wpdb;
232
+
233
+ $relevance_array = array();
234
+
235
+ foreach ( $this->search_terms as $search_term ) {
236
+
237
+ $search_term_len = strlen( $search_term );
238
+
239
+ $relevance = 40 + 2 * $search_term_len;
240
+
241
+ $search_term_norm = AWS_Plurals::singularize( $search_term );
242
+
243
+ if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
244
+ $search_term = $search_term_norm;
245
+ }
246
+
247
+ $like = '%' . $wpdb->esc_like($search_term) . '%';
248
+
249
+ $relevance_array[] = $wpdb->prepare( "( case when ( name LIKE %s ) then {$relevance} else 0 end )", $like );
250
+
251
+ if ( $terms_desc_search = apply_filters( 'aws_search_terms_description', false ) ) {
252
+ $relevance_desc = 10 + 2 * $search_term_len;
253
+ $relevance_array[] = $wpdb->prepare( "( case when ( description LIKE %s ) then {$relevance_desc} else 0 end )", $like );
254
+ }
255
+
256
+ }
257
+
258
+ return $relevance_array;
259
+
260
+ }
261
+
262
+ /**
263
+ * Get taxonomies search array
264
+ * @param array Search terms array
265
+ * @return array Terms
266
+ */
267
+ private function get_search_array( $search_terms ) {
268
+
269
+ global $wpdb;
270
+
271
+ $search_array = array();
272
+
273
+ foreach ( $search_terms as $search_term ) {
274
+
275
+ $search_term_len = strlen( $search_term );
276
+
277
+ $search_term_norm = AWS_Plurals::singularize( $search_term );
278
+
279
+ if ( $search_term_norm && $search_term_len > 3 && strlen( $search_term_norm ) > 2 ) {
280
+ $search_term = $search_term_norm;
281
+ }
282
+
283
+ $like = '%' . $wpdb->esc_like($search_term) . '%';
284
+
285
+ $search_array[] = $wpdb->prepare('( name LIKE %s )', $like);
286
+
287
+ if ( $terms_desc_search = apply_filters( 'aws_search_terms_description', false ) ) {
288
+ $search_array[] = $wpdb->prepare('( description LIKE %s )', $like);
289
+ }
290
+
291
+ }
292
+
293
+ return $search_array;
294
+
295
+ }
296
+
297
+ /**
298
+ * Get taxonomies search array with special chars
299
+ *
300
+ * @return array Terms
301
+ */
302
+ private function get_unfiltered_search_array() {
303
+
304
+ $no_normalized_str = $this->search_string_unfiltered;
305
+
306
+ $no_normalized_str = AWS_Helpers::html2txt( $no_normalized_str );
307
+ $no_normalized_str = trim( $no_normalized_str );
308
+
309
+ $no_normalized_str = strtr( $no_normalized_str, AWS_Helpers::get_diacritic_chars() );
310
+
311
+ if ( function_exists( 'mb_strtolower' ) ) {
312
+ $no_normalized_str = mb_strtolower( $no_normalized_str );
313
+ }
314
+
315
+ $search_array_chars = array_unique( explode( ' ', $no_normalized_str ) );
316
+ $search_array_chars = AWS_Helpers::filter_stopwords( $search_array_chars );
317
+
318
+ if ( $search_array_chars ) {
319
+ foreach ( $search_array_chars as $search_array_chars_index => $search_array_chars_term ) {
320
+ if ( array_search( $search_array_chars_term, $this->search_terms ) ) {
321
+ unset( $search_array_chars[$search_array_chars_index] );
322
+ }
323
+ }
324
+ }
325
+
326
+ if ( count( $search_array_chars ) === 1 && $search_array_chars[0] === $this->search_string_unfiltered ) {
327
+ $search_array_chars = array();
328
+ }
329
+
330
+ return $search_array_chars;
331
+
332
+ }
333
+
334
+ /**
335
+ * Get array of terms that must be excluded
336
+ * @return array Terms ids
337
+ */
338
+ private function get_excluded_terms() {
339
+
340
+ $excludes_array = array();
341
+
342
+ /**
343
+ * Exclude certain taxonomies terms from search
344
+ * @since 1.92
345
+ * @param array $excludes_array Array of terms Ids
346
+ */
347
+ $excludes_array = apply_filters( 'aws_search_tax_exclude', $excludes_array, $this->taxonomy, $this->search_string );
348
+
349
+ foreach( $this->taxonomy as $taxonomy_name ) {
350
+
351
+ /**
352
+ * Exclude certain terms from search ( deprecated )
353
+ * @since 1.58
354
+ * @param array
355
+ */
356
+ $exclude_terms = apply_filters( 'aws_terms_exclude_' . $taxonomy_name, array() );
357
+
358
+ if ( $exclude_terms && is_array( $exclude_terms ) && ! empty( $exclude_terms ) ) {
359
+ $excludes_array = array_merge( $excludes_array, $exclude_terms );
360
+ }
361
+
362
+ }
363
+
364
+ return $excludes_array;
365
+
366
+ }
367
+
368
+ /*
369
+ * Prepare taxonomy names for query
370
+ * @param string $name Taxonomy name
371
+ * @return string Prepared string
372
+ */
373
+ private function prepare_tax_names( $name ) {
374
+ global $wpdb;
375
+ return $wpdb->prepare('%s', $name);
376
+ }
377
+
378
+ }
379
+
380
+ endif;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
5
  Requires at least: 4.0
6
  Tested up to: 5.3
7
- Stable tag: 1.91
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -104,6 +104,12 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
104
 
105
  == Changelog ==
106
 
 
 
 
 
 
 
107
  = 1.91 =
108
  * Add - aws_terms_search_query filter
109
  * Add - aws_search_terms_description filter
4
  Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
5
  Requires at least: 4.0
6
  Tested up to: 5.3
7
+ Stable tag: 1.92
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
104
 
105
  == Changelog ==
106
 
107
+ = 1.92 =
108
+ * Update - Flatsome theme support
109
+ * Update - Taxonomies search query
110
+ * Fix - Bug with exclude filter for taxonomies search
111
+ * Add - aws_search_tax_exclude filter
112
+
113
  = 1.91 =
114
  * Add - aws_terms_search_query filter
115
  * Add - aws_search_terms_description filter