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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
0

Found it! I had this:

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

Instead of:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.