user125264
user125264

Reputation: 1827

cfindex how many custom fields can we have

im currently putting together a search function for my site using cfsearch. We are using CF 10 so i believe it runs on Solr.

In the cfindex tag, i can see that we can add some custom fields, but due to the large amount of information our search is to return, im wondering how would we go about making additional fields be available as part of the return dataset ?

currently we have custom1 - custom4 being populated with a number of fields from a database query, but we still require additional attributes to be available to the user or within the template when the search is run.

Is there any way to add more than the 4 custom fields to a cfindex ?

thanks in advance

Upvotes: 3

Views: 653

Answers (1)

Miguel-F
Miguel-F

Reputation: 13548

Adobe made improvements with the Solr implementation in ColdFusion 10 so that it no longer has the custom field limitation with cfindex that previous versions of ColdFusion had. Namely - custom1, custom2, custom3, and custom4. As usual, the online documentation for the tag was simply carried over from the previous version so it is a bit confusing.

See this document for more information - Solr enhancements in ColdFusion 10.
From that documentation under the Storing your custom data section:

Variations from ColdFusion 9

  • ColdFusion 9 had limited support for custom fields namely custom1, custom2, custom3, and custom4. In ColdFusion 10, custom fields are dynamic.
  • In ColdFusion 9, all custom fields are displayed. In ColdFusion 10, cfdump yields only fields that have data{{}}. That is, if you have specified only custom 1 and custom 2, only those two fields are displayed.
  • Consider the following code:

    <cfsearch criteria='some_criteria and column_i: [ 10 - 20 ]'...>

    Here, some_criteria indicates filtering. For example column_i: [ 10 - 20 ] means search all items whose values are between 10 and 20. column_i is the custom field provided by user while indexing. This option was available in ColdFusion 9, but limited to four custom fields. In ColdFusion 10, the options are unlimited.

  • In ColdFusion 10, you can sort the order in which search results have to be returned.

Note: When you search a Solr collection for field type string, the criteria should be within quotes, for example criteria='string_s:"something missing"'


To specify custom fields, use the following syntax:

<cfindex ... 
   datefield_dt=#date1# 
   column_i=#secondaryColumn# 
   body=#primaryColumn# 
   ....../>

Note Custom fields can contain only lower case characters.

In the code, _i stands for integer custom data whose value is stored and indexed. Any field name that ends with _i is treated as a Solr integer. Similarly, _s stands for string custom data.

All the supported datatypes are listed in the schema.xml:

<dynamicfield name="*_i" type="sint" indexed="true" stored="true"/> 
<dynamicfield name="*_s" type="string" indexed="true" stored="true"/> 
<dynamicfield name="*_l" type="slong" indexed="true" stored="true"/> 
<dynamicfield name="*_t" type="text" indexed="true" stored="true"/> 
<dynamicfield name="*_b" type="boolean" indexed="true" stored="true"/> 
<dynamicfield name="*_f" type="sfloat" indexed="true" stored="true"/> 
<dynamicfield name="*_d" type="sdouble" indexed="true" stored="true"/> 
<dynamicfield name="*_dt" type="date" indexed="true" stored="true"/> 
<dynamicfield name="random*" type="random"/>

Note: _dt supports only the date formats supported by ColdFusion.

Upvotes: 4

Related Questions