views:

36

answers:

1

Hi,

I want to find articles when searched on following keyword:

"maruti sx4 maintenance costs against honda city"

I want a query or php regular expression which can find a article which having below text

"SX4 maintenance cost is lesser because of Maruti. Honda City maintenance is also okay."

i.e i want a function/code which can find article by matching "maintenance cost" ( which is common text )

Please guide me how to do it

Thanks Satish Kalepu

+2  A: 

Straightforward solution

The not-so-efficient solution is to match each of your search term one by one to your complete set of articles. For each new query you would repeat this process. Use explode to split your query string into an array of individual search terms, stripos too test if the term occurs within the text of an article.

Document Retrieval System

If you want to create a full document retrieval system from scratch, you probably should start by creating an inverted index mapping search terms to documents (articles).

Then for each individual search term you can retrieve matching document. The document which has most matches would be the output of the search system, or you can rank the found documents by the number of search terms matched.

This simple idea can become more advanced if you take into account word stemming and document/term frequency (i.e. the word "the" is less interesting as a search query than "honda" as almost all documents contain "the" but few contain "honda").

catchmeifyoutry
thank you very much
Satish Kalepu