HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Search problems when "-" in search

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#99242 (In Topic #19516)
TQ
Avatar

Honoured member

Hi All,

I have many downloads that include a "-" in the title eg programming software for a ZT-Q5. ZT-Q5 is the model of a radio and many other radios have similarly formatted model numbers on my site.

If you search my site for ZT-Q5 it returns no results but if you search for ZT or Q5 the correct result is obtained.

Dose anyone know of a fix for this problem?

Nick
hamfiles.co.uk
Back to the top
 
Posted
Rating:
#99255
Avatar

Did you try with quotes, or as a boolean search? MySQL full-text search would definitely consider this two separate words, except each is less than the word length so would not have been indexed. Writing that makes me think even quotes would not work. But a boolean would.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#99260
TQ
Avatar

Honoured member

Hi Chris,

Thanks for the reply.

Neither quotes or Boolean search produce results using ZT-V5.

With or without a boolean search for the first 2 characters (ZT) results were produced.

With or without a boolean search for the last 2 characters (V5) no results were produced.

Any ideas on how I can work around this problem?

Thanks

Nick

Back to the top
 
Posted
Rating:
#99262
Avatar

We might be able to fudge it.

Boolean search will actually still use the Fulltext index in some cases, because MySQL provides a feature for that and that provides decent performance. However, as discussed above, fulltext has limitations.

Try creating a sources_custom/database_search.php file with this in it:

Code

<?php

/**
 * Find whether a phrase is too small for fulltext search.
 *
 * @param  string      The phrase
 * @return boolean   Whether it is
 */
function is_under_radar($test)
{
   if (preg_match('#\w-\w#',$test)!=0) return true; // Avoid fulltext search when using hyphenated strings

   if (get_value('disable_boolean_search')==='1') return false;

   static $min_word_length=NULL;
   if (is_null($min_word_length))
   {
      $min_word_length=4;
      if (substr(get_db_type(),0,5)=='mysql')
      {
         $_min_word_length=$GLOBALS['SITE_DB']->query('SHOW VARIABLES LIKE \'ft_min_word_len\'',NULL,NULL);
         if (array_key_exists(0,$_min_word_length))
            $min_word_length=intval($_min_word_length[0]['Value']);
      }
   }

   return ((strlen($test)<$min_word_length) && ($test!=''));
}

This overrides the function that decides whether to use fulltext search for boolean searches, adding a case for it to recognise your hyphenation issue.


Last edit: by Chris Graham


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#99267
TQ
Avatar

Honoured member

Thanks Chris,

Unfortunately I get a critical error...

Code

Critical error – bailing out

This is an error that has been elevated to critical error status because it occurred during the primary error mechanism reporting system itself (possibly due to it occuring within the standard output framework). It may be masking a secondary error that occurred before this, but was never output - if so, it is likely strongly related to this one, thus fixing this will fix the other.
PHP WARNING [2] preg_match() expects at least 2 parameters, 1 given in sources_custom\database_search.php on line 11 (version: 9.0.8, PHP version: 5.3.24, URL: /data/iframe.php?zone=&utheme=Golden&page=search&type=results&content=zq-v5&search_download_categories=1&search_downloads=1&author=&days=-1&sort=relevance&direction=DESC&only_titles=0&only_search_meta=0&boolean_search=0&conjunctive_operator=AND)

Stack trace…

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\failure.php'
Line -> 792
Function -> 'die_html_trace'
Args -> array

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\global2.php'
Line -> 1012
Function -> '_fatal_exit'
Args -> array ( 0 => 'PHP WARNING [2] preg_match() expects at least 2 parameters, 1 given in sources_custom\\database_search.php on line 11', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\failure.php'
Line -> 224
Function -> 'fatal_exit'
Args -> array ( 0 => 'PHP WARNING [2] preg_match() expects at least 2 parameters, 1 given in sources_custom\\database_search.php on line 11', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\global2.php'
Line -> 875
Function -> '_ocportal_error_handler'
Args -> array ( 0 => 'warning', 1 => 2, 2 => 'preg_match() expects at least 2 parameters, 1 given', 3 => 'sources_custom\\database_search.php', 4 => 11, )

Function -> 'ocportal_error_handler'
Args -> array ( 0 => 2, 1 => 'preg_match() expects at least 2 parameters, 1 given', 2 => 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources_custom\\database_search.php', 3 => 11, 4 => array ( 'test' => 'zq-v5', ), )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources_custom\\database_search.php'
Line -> 11
Function -> 'preg_match'
Args -> array ( 0 => '#\\w-\\w#', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\global.php(206) : eval()\'d code'
Line -> 955
Function -> 'is_under_radar'
Args -> array ( 0 => 'zq-v5', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\site\\pages\\modules\\search.php'
Line -> 642
Function -> 'build_content_where'
Args -> array ( 0 => 'zq-v5', 1 => false, 2 => 'AND', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\site\\pages\\modules\\search.php'
Line -> 546
Function -> 'results'
Class -> 'Module_search'
Object -> Module_search::__set_state(array( ))
Type -> '->'
Args -> array ( 0 => '', 1 => '', 2 => NULL, 3 => -1, 4 => 'relevance', 5 => 'DESC', 6 => false, 7 => '!', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\site\\pages\\modules\\search.php'
Line -> 262
Function -> 'form'
Class -> 'Module_search'
Object -> Module_search::__set_state(array( ))
Type -> '->'
Args -> array ( )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\zones.php'
Line -> 425
Function -> 'run'
Class -> 'Module_search'
Object -> Module_search::__set_state(array( ))
Type -> '->'
Args -> array ( )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\site.php'
Line -> 858
Function -> 'load_module_page'
Args -> array ( 0 => 'site/pages/modules/search.php', 1 => 'search', )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\sources\\misc_scripts.php'
Line -> 233
Function -> 'request_page'
Args -> array ( 0 => 'search', 1 => true, )

File -> 'C:\\HostingSpaces\\hamfiles.co.uk\\hamfiles.co.uk\\wwwroot\\data\\iframe.php'
Line -> 37
Function -> 'iframe_script'
Args -> array ( )



Sorry to be a pain

Nick
hamfiles.co.uk
Back to the top
 
Posted
Rating:
#99268
Avatar

Post edited


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: