Return only distinct combinations of 2 field values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Return only distinct combinations of 2 field values

PeterKerk
I'm searching on cities and returning city and province, some cities exist in different provinces, which is ok.
However, I have some duplicates, meaning 2 cities occur in the same province. In that case I only want to return 1 result.
I therefore need to have a distinct and unique city+province combination.

How can I make sure that only unique city+province combinations are returned by my query?

http://localhost:8983/solr/tt-cities/select/?indent=off&facet=false&fl=id,title,provincetitle_nl&q=*:*&defType=lucene&start=0&rows=15

The respective fields are title and provincetitle_nl. Below my schema.xml

    <fieldType name="text_lower_exact" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_dutch.txt"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_dutch.txt"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>       

<field name="title" type="text_lower_exact" indexed="true" stored="true"/>
<field name="provincetitle_nl" type="string" indexed="true" stored="true"/>