Setting up default query field
Set up a catch-all field for searches when no field is specified by the query.
Procedure
-
Create a new index-only field:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD fields.field[ @name='catch_all', @type='TextField', @multiValued='true'];
Since this new field contains values from two fields, set multiValued to true.
Show the pending schema changes:
DESCRIBE PENDING SEARCH INDEX SCHEMA ON wiki.solr ;
The new field is listed in bold:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <schema name="autoSolrSchema" version="1.5"> <types> <fieldType class="org.apache.solr.schema.TextField" name="TextField"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> <fieldType class="org.apache.solr.schema.TrieDateField" name="TrieDateField"/> <fieldType class="org.apache.solr.schema.StrField" name="StrField"/> </types> <fields> <field indexed="true" multiValued="false" name="body" stored="true" type="TextField"/> <field docValues="true" indexed="true" multiValued="false" name="real_date" stored="true" type="TrieDateField"/> <field indexed="true" multiValued="false" name="title" stored="true" type="TextField"/> <field indexed="true" multiValued="false" name="id" stored="true" type="StrField"/> <field indexed="true" multiValued="false" name="date" stored="true" type="TextField"/> **<field indexed="true" multiValued="true" name="catch_all" type="TextField"/\>** </fields> <uniqueKey>id</uniqueKey> </schema>
-
Set up a copy field directive to collect the data from all CQL columns:
ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD copyField[@source='title', @dest='catch_all']; ALTER SEARCH INDEX SCHEMA ON wiki.solr ADD copyField[@source='body', @dest='catch_all'];
Show the pending schema changes:
DESCRIBE PENDING SEARCH INDEX SCHEMA ON wiki.solr ;
The new copy field directives are listed in bold below:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <schema name="autoSolrSchema" version="1.5"> <types> <fieldType class="org.apache.solr.schema.TextField" name="TextField"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> <fieldType class="org.apache.solr.schema.TrieDateField" name="TrieDateField"/> <fieldType class="org.apache.solr.schema.StrField" name="StrField"/> </types> <fields> <field indexed="true" multiValued="false" name="body" stored="true" type="TextField"/> <field docValues="true" indexed="true" multiValued="false" name="real_date" stored="true" type="TrieDateField"/> <field indexed="true" multiValued="false" name="title" stored="true" type="TextField"/> <field indexed="true" multiValued="false" name="id" stored="true" type="StrField"/> <field indexed="true" multiValued="false" name="date" stored="true" type="TextField"/> <field indexed="true" multiValued="true" name="catch_all" type="TextField"/> </fields> <uniqueKey>id</uniqueKey>** <copyField dest="catch_all" source="body"/\> <copyField dest="catch_all" source="title"/\> **</schema>
-
Define the default field in the search index config:
ALTER SEARCH INDEX CONFIG ON wiki.solr SET defaultQueryField = 'catch_all' ;
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <config> <luceneMatchVersion>LUCENE_6_0_1</luceneMatchVersion> <dseTypeMappingVersion>2</dseTypeMappingVersion> <directoryFactory class="solr.StandardDirectoryFactory" name="DirectoryFactory"/> <indexConfig> <ramBufferSizeMB>512</ramBufferSizeMB> <rt>false</rt> </indexConfig> <jmx/> <updateHandler> <autoSoftCommit> <maxTime>10000</maxTime> </autoSoftCommit> </updateHandler> <query> <filterCache class="solr.SolrFilterCache" highWaterMarkMB="2048" lowWaterMarkMB="1024"/> <enableLazyFieldLoading>true</enableLazyFieldLoading> <useColdSearcher>true</useColdSearcher> <maxWarmingSearchers>16</maxWarmingSearchers> </query> <requestDispatcher> <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048000"/> <httpCaching never304="true"/> </requestDispatcher> <requestHandler class="solr.SearchHandler" default="true" name="search">** <lst name="defaults"\> <str name="df"\>catch_all</str\> </lst\> ** </requestHandler> <requestHandler class="com.datastax.bdp.search.solr.handler.component.CqlSearchHandler" name="solr_query"> <lst name="defaults"> <str name="df">catch_all</str> </lst> </requestHandler> <requestHandler class="solr.UpdateRequestHandler" name="/update"/> <requestHandler class="solr.UpdateRequestHandler" name="/update/csv" startup="lazy"/> <requestHandler class="solr.UpdateRequestHandler" name="/update/json" startup="lazy"/> <requestHandler class="solr.FieldAnalysisRequestHandler" name="/analysis/field" startup="lazy"/> <requestHandler class="solr.DocumentAnalysisRequestHandler" name="/analysis/document" startup="lazy"/> <requestHandler class="solr.admin.AdminHandlers" name="/admin/"/> <requestHandler class="solr.PingRequestHandler" name="/admin/ping"> <lst name="invariants"> <str name="qt">search</str> <str name="q">solrpingquery</str> </lst> <lst name="defaults"> <str name="echoParams">all</str> </lst> </requestHandler> <requestHandler class="solr.DumpRequestHandler" name="/debug/dump"> <lst name="defaults"> <str name="echoParams">explicit</str> <str name="echoHandler">true</str> </lst> </requestHandler> </config>
-
Reload the schema and config to make the pending search index schema and config active:
RELOAD SEARCH INDEX ON wiki.solr ;
-
Rebuild the index to update the search index for the existing data:
REBUILD SEARCH INDEX ON wiki.solr ;