Using Zend Search Lucene with Symfony 2

1.5k views Asked by At

I have a searchform in my webapp where users can search others by name, clubname, ... This is the code I'm using for the search but it's not giving me any 'hits'.

$search = $this->get('ewz_search.lucene');

$query = new MultiTerm();
$query->addTerm(new Term($form->getData()->getName()));
$query->addTerm(new Term($form->getData()->getClub()->getId()));

// See point 1 to see what this displays
var_dump($query);

// See point 2 to see what this displays
die("debug: " . $query);

// If I use this instead of the MultiTerm, I do get a hit
// $query = 'Mathew';

$hits = $search->find($query);

Point 1: object(Zend\Search\Lucene\Search\Query\MultiTerm)#644 (9) { ["_terms":"Zend\Search\Lucene\Search\Query\MultiTerm":private]=> array(2) { [0]=> object(Zend\Search\Lucene\Index\Term)#638 (2) { ["field"]=> NULL ["text"]=> string(12) "Mathew" } [1]=> object(Zend\Search\Lucene\Index\Term)#637 (2) { ["field"]=> NULL ["text"]=> int(1) } } ["_signs":"Zend\Search\Lucene\Search\Query\MultiTerm":private]=> array(2) { [0]=> NULL [1]=> NULL } ["_resVector":"Zend\Search\Lucene\Search\Query\MultiTerm":private]=> NULL ["_termsFreqs":"Zend\Search\Lucene\Search\Query\MultiTerm":private]=> array(0) { } ["_coord":"Zend\Search\Lucene\Search\Query\MultiTerm":private]=> NULL ["_weights":"Zend\Search\Lucene\Search\Query\MultiTerm":private]=> array(0) { } ["_boost":"Zend\Search\Lucene\Search\Query\AbstractQuery":private]=> int(1) ["_weight":protected]=> NULL ["_currentColorIndex":"Zend\Search\Lucene\Search\Query\AbstractQuery":private]=> int(0) }

Point 2: debug: Mathew 1

Thx.

2

There are 2 answers

1
ilanco On

Check the default term operator. If you have separate field indexes for clubid and name you can prefix the field name.

$query = "name:Mathew AND clubid:1";

See the parser syntax for more information.

0
mattyh88 On

Found it! I had this:

$document->addField(Field::text('Name', $user->getName()));

Instead of:

$document->addField(Field::text('name', $user->getName()));