1 Reply Latest reply on Apr 6, 2010 3:18 PM by Fernis

    CF9, Solr, and Faceted Search

    WestSide Level 1

      Hi,

       

      I've heard that ColdFusion's implementation of Solr has functionality that would assist with faceted search, is that correct?  I want to build a faceted search interface off of some data in my database as opposed to files.  Does CF9' integration with Solr support that?

       

      If Solr isn't a viable option I'd be interested to hear how others may have built a faceted search using CF.

       

      Thanks,

       

      -ws

        • 1. Re: CF9, Solr, and Faceted Search
          Fernis Level 3

          I have actually never - in my 14 years with almost daily ColdFusion - used ColdFusion's search capabilities in a live application. Thus I'm far from an expert with the issue.

           

          However, I've done some playing around, and if I understand correctly, faceted search is where you want to narrow down your search results by specifying multiple search conditions for various fields.

           

          If that's right, maybe this piece of code might help you:

           

          <cfif isdefined("url.create")>
          <cfcollection action="create" categories="yes" collection="sitecontent" engine="solr" path="#expandpath('./')#">
          Collection created OK.
          </cfif>

           

          <cfif isdefined("url.index")>
          <cfset mq = queryNew("id,camera,cameratype,price","integer,varchar,varchar,varchar")>
          <cfset tmp = queryAddRow(mq,5)>

           

          <cfset tmp = querySetCell(mq,"id",1,1)>
          <cfset tmp = querySetCell(mq,"id",2,2)>
          <cfset tmp = querySetCell(mq,"id",3,3)>
          <cfset tmp = querySetCell(mq,"id",4,4)>
          <cfset tmp = querySetCell(mq,"id",5,5)>

           

          <cfset tmp = querySetCell(mq,"camera","Olympus 500",1)>
          <cfset tmp = querySetCell(mq,"camera","Canon D30",2)>
          <cfset tmp = querySetCell(mq,"camera","Konica Minolta Dimage A2",3)>
          <cfset tmp = querySetCell(mq,"camera","Sony Cybershot 300X",4)>
          <cfset tmp = querySetCell(mq,"camera","Sony Cybershot 50D2",5)>

           

          <cfset tmp = querySetCell(mq,"price","500",1)>
          <cfset tmp = querySetCell(mq,"price","1500",2)>
          <cfset tmp = querySetCell(mq,"price","700",3)>
          <cfset tmp = querySetCell(mq,"price","200",4)>
          <cfset tmp = querySetCell(mq,"price","400",5)>

           

          <cfset tmp = querySetCell(mq,"cameratype","Professional",1)>
          <cfset tmp = querySetCell(mq,"cameratype","Pro",2)>
          <cfset tmp = querySetCell(mq,"cameratype","SLR",3)>
          <cfset tmp = querySetCell(mq,"cameratype","SLR",4)>
          <cfset tmp = querySetCell(mq,"cameratype","Pocket",5)>

           

          Query to be indexed:

          <cfdump var="#mq#">

           

          Indexing...
          <cfindex action="update" collection="sitecontent" body="camera,cameratype,price" key="id" type="custom" query="mq" title="camera" custom1="price" custom2="cameratype">
          OK<BR>
          </cfif>

           

          <cfif isdefined("url.search")>
              <cfsearch collection="sitecontent" name="mysearch1" criteria="custom1:700 TO 1500">
              Search 1:
              <cfdump var="#mysearch1#">
              <cfsearch collection="sitecontent" name="mysearch2" criteria="custom2:pro">
              Search 2:
              <cfdump var="#mysearch2#">
              <cfsearch collection="sitecontent" name="mysearch3" criteria="custom1:700 TO 1500 AND custom2:pro">
              Search 3:
              <cfdump var="#mysearch3#">
          </cfif>

           

          The code above creates a query object, populates a cfcollection with it, indexing it with two custom fields, which can be searched individually. The limitation is that ColdFusion only allows 4 custom fields.

           

          Save the code into a template, and call it first with URL parameter "create=yes". The second time call it with "index=yes", and from there on, with "search=yes". CFDUMPs should demonstrate you what happens.

           

          There might be much more elegant solutions for such bracketing, and I don't know how that really works inside - does it use Solr faceting at all, or just internally query of queries...

           

          There are few people with any advice on ColdFusion and SolR best practices, so I just thought I'd throw in my 2 cents, even though I'm not too experienced on problem solving with Solr or Verity.

           

          -Fernis - fernis.net

          1 person found this helpful