2
votes


I am using Solr 6 to implement a search engine. The Problem I am facing is that when I searched for the word it returns some other results first and the actual query is at number 6.
For example I am searching for Cafe 9
It returns me this...

  • NECOS NATURAL STORE & CAFE
  • SATTAR BUKSH CAFE
  • THE PINK CADILLAC CAFE & RESTAURANT
  • CAFE ROCK LAHORE
  • CAFE CHEF ZAKIR
  • CAFE 9


  • What I want is that it show Cafe 9 in 1st place and then other results as Cafe 9 is the exact match..



    I have indexed all the fields with type text_general and the schema.xml is attached.

    Thanks in advance.

         <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
          <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <!-- in this example, we will only use synonyms at query time
            <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
            -->
            <filter class="solr.ApostropheFilterFactory"/>
            <filter class="solr.ShingleFilterFactory" maxShingleSize="5" outputUnigrams="true"/>
            <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
          <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
            <filter class="solr.ApostropheFilterFactory"/>
            <!-- <filter class="solr.ShingleFilterFactory" maxShingleSize="5" outputUnigrams="true"/> -->
            <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
        </fieldType>
    1
    if you are looking for exact match you can index the data using the string as fieldType or use the keyword tokenizer... - Abhijit Bashetti
    How are you querying your index? If you're using dismax/edismax, try applying a pf / pf2 weight to the fields. Are you querying just the name field? - MatsLindh
    Yes I am querying the name field. localhost:8983/solr/abc/select?q=name:(cafe 9) ... this is my url for the search.. - Abdul Subbooh Danyal

    1 Answers

    3
    votes

    If you want to boost the score of documents containing all the query terms in close proximity then you can pass the pf parameter with the value of the field name. In your case you should be passing pf=name (pf stands for phrase fields). The eDisMax query parser will attempt to make phrase queries out of all the terms in the q parameter, and if it’s able to find the exact phrase in any of the phrase fields, it will apply the specified boost to the match for that document.

    In case you're not using the eDisMax query parser by default you can use it temporarily for the current query by passing q={!edismax pf=name}cafe 9.

    You could also pass the pf2 parameter (as in pf2=name) which works in a way similar to pf except that the generated phrase queries are the bigrams in your query (that is, every two consecutive terms will be considered a boosting phrase). There's is also a pf3 parameter if that happens to be what you're looking for.

    You can also customize the boost and pass more than one field name to the phrase proximity parameters (for instance, pf=name^2 title^3).