0

I use symfony with Zend Lucene Search. I have

$query = Zend_Search_Lucene_Search_QueryParser::parse($query.'*');
$hits = self::getLuceneIndex()->find($query);

Sometimes I have error :

At least 3 non-wildcard characters are required at the beginning of pattern.

When I make like in documentations:

$pattern = new Zend_Search_Lucene_Index_Term($query.'*');
$query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$hits = self::getLuceneIndex()->find($query);

It finds nothing.

j0k
  • 22,600
  • 28
  • 79
  • 90
denys281
  • 2,004
  • 2
  • 19
  • 38

2 Answers2

1

Taken directly from the Zend Reference documentation, you can use:

  • Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() to query the minimum required prefix length and
  • use Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength() to set it.

So my suggestion would be either of two things:

  1. Set the prefixMinLength to 0 using Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0) - based on this, your original code snippet should work fine (it did for my Zend Lucene implementation)

  2. As you yourself suggested, validate all search queries using javascript or otherwise to ensure there is a minimum of Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() before any wildcards used (I recommend querying that instead of assuming the default of "3" so the validation is flexible)

sabeer
  • 31
  • 3
1

I do not is it right , but it is work for me :

So, query fail in my case, because it have < 3 characters or have some special characters, so in my search action :

 public function executeAds(sfWebRequest $request)
  {
      if (!$query = $request->getParameter('query'))
    {
      return $this->forward('search', 'adssearch');
    }

   $query = str_replace(" ", "", $query);
   $query = preg_replace("/[^A-Za-z0-9]/","",$query);
    if (strlen(trim($query))<3)

    {
         $this->redirect('search/notice');
    }

    $this->ads = Doctrine_Core::getTable('Ads') ->getAdsLuceneQuery($query); 

I do not use

$pattern = new Zend_Search_Lucene_Index_Term($query.'*');
$query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$hits = self::getLuceneIndex()->find($query);

Because it is not work for me.

denys281
  • 2,004
  • 2
  • 19
  • 38