3 Replies Latest reply on Dec 23, 2014 4:26 PM by cinthara

    solr search returns 0 results if search phrase is in double quotes

    cinthara

      sI have one search result that looks like this:

       

      Outlook Out of Office Assistant

      Jul, 28, 2014 - To activate the Out of Office Assistant: On the Tools menu click Out of Office Assistant. In the Out of Office Assistant dialog box select the Send Out of Office auto-replies radio button. If you want to specify a set time and date range select the Only send during this time range check box. Then set the Start time and then set the...

       

      When I do this search, I get 10 results back including the one above.

      <cfsearch

      name="qTechTips"

      collection="#collection#"

      criteria='secondary_id_i:24 out of office'

      orderby="sort_date_s desc"

      />

       

      But when I do a phrase search for "Out of Office":

       

      <cfsearch

      name="qTechTips"

      collection="#collection#"

      criteria='secondary_id_i:24 "out of office"'

      orderby="sort_date_s desc"

      />

       

      or

      <cfsearch

      name="qTechTips"

      collection="#collection#"

      criteria='secondary_id_i:24 "Out of Office"'

      orderby="sort_date_s desc"

      />

       

      I get 0 results. What am I doing wrong? I would like to do a phrase match to what is in the body, not the "title".

       

      I am on ColdFusion 11, update 3

        • 2. Re: solr search returns 0 results if search phrase is in double quotes
          vishu#13 Level 3

          Try escaping the quotes in your query like "secondary_id_i:24 \"Out of Office\""

          • 3. Re: solr search returns 0 results if search phrase is in double quotes
            cinthara Level 1

            Escaping the quotes didn't help .I already read the solr search examples by Adobe but that didn't help me much. I don't know if this is documented in the CF documentation anywhere (I couldn't find it). What I worked for me after looking at the Apache Solr documentation was that you need to add "+" in between the words in the phrase:

             

            <cfsearch

            name="qTechTips"

            collection="#collection#"

            criteria='secondary_id_i:24 "Out+of+Office"'

            orderby="sort_date_s desc"

            />

             

            Expecting my users to enter "+" is a bit much but I know they can handle putting double quotes about phrases they want an exact match for. After some googling, this is my solution for automatically adding the "+" between the exact phrase for cfsearch processing (if you have a better solution, please let me know) :

             

              <!--- ////START: solr search --->
              <cfset solr_criteria = "">
             
              <!--- //START:Process the user's input if they use exact phrase search (in double quotes). I change their keyword input so it is cfsearch friendly. If a user enters 'how to set "Out of Office" and "Web Access"', we clean it up so it is 'how to set  "Out+of+Office" and "Web+Access"' for the cfsearch--->
              <!--- I don't know if there is a better way to do this, but this is what I came up with. --->
             
              <cfset txt_keyword_solr = #txt_keyword#>
              <cfif find('"',txt_keyword_solr)>
                <cfset stringphrase = reMatch('"([^"]*)"',txt_keyword_solr)>


                <!--- <cfdump var="#stringphrase#" label="Example REMatch"> --->

             

                <cfloop array="#stringphrase#" index="i">
                  <cfset txt_keyword_solr = #ReplaceNoCase(txt_keyword_solr,i,rereplace(i, " ","+","all"),"all")#>     
                </cfloop>

              </cfif>
              <cfif LEN(TRIM(txt_keyword_solr)) GT 0>
                <cfset solr_criteria = solr_criteria & ' ( #Trim(preservesinglequotes(txt_keyword_solr))# ) '>
              </cfif>
              <!--- //END:Process the user's input if they use exact phrase search (in double quotes). --->
             
              <cfsearch
            name="qTechTips"
            collection="#collection#"
            criteria="#solr_criteria#"
            orderby="sort_date_s desc"
            />
              <p><cfoutput>#solr_criteria#</cfoutput></p>
              <!--- ////END: solr search --->