Zend_search_lucene limit result "length"
I'm using lunece to find in some file a string or a code number. I would like to know how can i "limit" the results content.
Example: i was searching for le string 'DC' in a long text (about 500 char).
I would like to have the 20 char before and 20 after the first matched string..
Like that: "开发者_如何学运维[..]altri inox 0 50 C aria filtrata senza lubrificazione * 1,5 mm 24V DC 10% (altre a richiesta) 2W Classe F IP 54 (IP 65 con connettore) ED 100% 5 ms Serie W * Nel cas[..]"
Does lucene have already a method or have i to write it? I only found highlightMatches()..
I don't believe lucene has a functionality that supports it. However you could do to with php while displaying the results.
$search = "DC";
$results = //whatever you get back from the search index
foreach($results as $result) {
$before = substr(stristr($result, $search, TRUE), -20);
$after = substr(stristr($result, $search), 20);
$text = $before . $search . $after;
}
Note: The foreach is a little 'raw'. I focused on the string processing.
精彩评论