2

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
mattyh88
  • 1,585
  • 5
  • 26
  • 48

2 Answers2

2

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.

ilanco
  • 9,581
  • 4
  • 32
  • 37
  • Thx for your input. I thought I was good to go until I started testing with a query that should give more than one result. I have this MultiTerm query that prints: "+name: +club:A.R.A. LA GANTOISE +natranking: +doublesranking:" (which doesn't give any results) and I tried doing it manually like $query="+name: +club:A.R.A. LA GANTOISE +natranking: +doublesranking:" (this works) .. Why is that? – mattyh88 May 28 '12 at 07:57
0

Found it! I had this:

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

Instead of:

$document->addField(Field::text('name', $user->getName()));
mattyh88
  • 1,585
  • 5
  • 26
  • 48