Question

I'm attempting to index around 30,000 database records in a single collection and per my requirements I need to be able to include a list of items in a single custom field - and use that in my search.

Here's an example of my index:

<cfindex collection = "myCollection" 
             action = "refresh"
             type = "custom"
             query = "Local.myQuery" 
             key = "ID" 
             title="Title"
             applications_s="A_Comma_Separated_List"
             body = "a_field,a_nother_field">

In this example, applications_s is a dynamic custom field (introduced in CF10) containing a list of application IDs. An example of content for this field would be:

T1,T2,B4,G1

This all indexes splendidly, however I've been unable to figure out how to search, using a single item in the applications list as criteria.

So, I'd like to be able to do this:

<cfsearch name="Local.qSearch"
    collection="myCollection"
    criteria="test AND applications_s:T1">

This should return all records that contain the word 'test' in the body, and also contain 'T1' in the applications field. However, I can't find a criteria syntax that will treat the contents of the custom field as a comma separated list... it seems to only work as a string. Therefore my example record wouldn't be returned unless I include a wildcard - which could cause problems with extra records being returned by mistake.

Is there any way to explicitly specify that my custom field is a list and should contain my specified value?

Was it helpful?

Solution

I managed to get the following to work on CF9.0.1. Although the MYCUSTOMNAME_TYPE (e.g. applications_s) fields are CF10-only, I was able to use the custom1 field and specify it as a "string" type by editing the collection's schema.xml and restarting Solr. You shouldn't have to on CF10.

1) In the query you're indexing, add TWO commas to the beginning of the application list column, and ONE at the end, so an example row would look like:

,,T1,T1B,T2,B4,G1,

You could do this either in your SQL using concatenation (preferable), or by post-processing the query result with Query-of-Queries, or QueryNew() and looping over the query to build a copy.

2) Index the query with cfindex as in your question, using applications_s to ensure the field is a string type, not text. We don't want the list to be "tokenised" as words. The commas are critical and we don't want them to be ignored.

3) In your cfsearch pad the criteria as follows:

<cfset searchString= "test">
<cfset applicationFilter = "T1">
<cfsearch name="Local.qSearch"
    collection="myCollection"
    criteria="#searchString# AND applications_s:,*,#applicationFilter#,*">

Note there are 3 commas and 2 wildcard asterisks altogether. The first comma is there because you cannot start a Solr query with a wildcard. The second and third commas ensure that the wildcard search for T1 does not match T1B.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top