Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming "name", "address", "phone" are your fields of type Zend_Search_Lucene_Field::Text and you have one single field Zend_Search_Lucene_Field::Unstored called "content" This could be easily solved using "<strong>strpos</strong>":</p> <pre><code> $hits = $index-&gt;find($query); foreach ($hits as $hit) { $result = array(); if (strpos($hit-&gt;name , $query)) { $result[$hit-&gt;id]['name'] = $query-&gt;highlightMatches($hit-&gt;name) } else { $result[$hit-&gt;id]['name'] = $hit-&gt;name } if (strpos($hit-&gt;address, $query)) { $result[$hit-&gt;id]['address'] = $query-&gt;highlightMatches($hit-&gt;address) } else { $result[$hit-&gt;id]['address'] = $hit-&gt;address } if (strpos($hit-&gt;phone, $query)) { $result[$hit-&gt;id]['phone'] = $query-&gt;highlightMatches($hit-&gt;phone) } else { $result[$hit-&gt;id]['phone'] = $hit-&gt;phone } } </code></pre> <p>your phone field might be a Zend_Search_Lucene_Field::keyword or something else. if none of these previous fields was highlighted it means that you $query string was found in your content which is not saved because it's a Zend_Search_Lucene_Field::Unstored field. what you should do then is add another type Zend_Search_Lucene_Field::Text field to your $doc and call it "excerpt" </p> <pre><code>$doc-&gt;addField(Zend_Search_Lucene_Field::Text('excerpt', substr($content, 0, 100))); </code></pre> <p>and add this to you previous "foreach" loop</p> <pre><code>if (strpos($hit-&gt;excerpt, $query)) { $result[$hit-&gt;id]['excerpt'] = $query-&gt;highlightMatches($hit-&gt;excerpt) } else { $result[$hit-&gt;id]['excerpt'] = $hit-&gt;excerpt } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload