Programmer's Reference Guide

Indexing

Searching

Searching is performed by using the find() method:

Example #1 Searching through the index

  1. $hits = $index->find($query);
  2.  
  3. foreach ($hits as $hit) {
  4.     printf("%d %f %s\n", $hit->id, $hit->score, $hit->title);
  5. }

This example demonstrates the usage of two special search hit properties - id and score.

id is an internal document identifier used within a Lucene index. It may be used for a variety of operations, including deleting a document from the index:

Example #2 Deleting an Indexed Document

  1. $index->delete($id);

Or retrieving the document from the index:

Example #3 Retrieving an Indexed Document

  1. $doc = $index->getDocument($id);

Note: Internal Document Identifiers
Important note! Internal document identifiers may be changed by index optimization or the auto-optimization process, but it's never changed within a single script's execution unless the addDocument() (which may involve an auto-optimization procedure) or optimize() methods are called.

The score field is a hit score. Search results are ordered by score by default (best results returned first).

It's also possible to order result sets by specific field values. See the Zend_Search_Lucene documentation for more details about this possibility.

The example also demonstrates an ability to access stored fields (e.g., $hit->title). At the first access to any hit property other than id or score, document stored fields are loaded, and the corresponding field value is returned.

This causes an ambiguity for documents having their own id or score fields; as a result, it's not recommended to use these field names within stored documents. Nevertheless, they still can be accessed via the getDocument() method:

Example #4 Accessing the original document's "id" and "score" fields

  1. $id    = $hit->getDocument()->id;
  2. $score = $hit->getDocument()->score;

Indexing

Comments

Hi,

I'm having trouble with Unicode as I'm getting incorrect result when suing Unicode characters with search input like á é ç õ etc... As it always ends with irrelevant result of showing all result without considering the input string. Can anybody help me to fix this issue?

Thanks,

Syam
Hi,

I'm having trouble search using Unicode characters like á é ç õ, etc... as it never returns the correct result or it returns all data irrelevant of the input search string. Can anybody tell me how to fix this issue?

Thanks & Regards,

Syam

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual