views:

145

answers:

2

Say I need to make searching for related titles just like stackoverflow does before you add your question or digg.com before submitting news.

I didn't find a way how to do this with Zend Lucene. There are setSlop method for queries, but as I understand, it doesn't help.

Is there any way to do this kind of searches?

A: 

The easiest way to do this is to submit the document's text as a query. Take the document's text, tokenize it, put an OR term in between each token, and submit it as a Lucene query. I've done this before and it works reasonably well.

bajafresh4life
Yeah, but OR logic wouldn't help. Because it will find all documents that consist of any of these words whereas I need to find relevant documents.
Arty
+1  A: 

I figured that to do related search you should just pass the query string to the $index->find method. It will find not only the exact matches but also similar ones:

$index->find('top 10 cars');

result:

Top 10 Funniest Cars
Top 11 Celebrities Cars
Top 6 Barbeque Cars
Top 10 Futuristic Concept Cars
Top 5 Classic Oldest Cars Ever 
Arty