Search code examples
phpzend-frameworklucenezend-search-lucene

Zend Lucene search related fields?


I have a lot of paired fields (hoursDistance1, cityName1, hoursDistance2, cityName2, hoursDistance3, cityName3, etc.).

What query do I need to search for so that Lucene scores based on both fields having the correct terms instead of just one of them? i.e. if I search for a city 3 hours from here with this name, how do I get it to return results where hoursDistanceN is 3 hours from here AND cityNameN is this without scoring the other pairs of fields?


Solution

  • You could create a document for each pair. So instead of

    id | hours1 | name1 | hours2 | name2 | ...
    

    You would have:

    id | pair_num = 1 | hours | name
    id | pair_num = 2 | hours | name
    ...
    

    Since you only want to search one pair at a time, you shouldn't need to merge the results together or anything.