Understanding and Fixing Slow Drupal β Solr Queries
1. What Youβre Seeing
Drupalβs Search API and Facet API often generate large, complex Solr queries like this:
?q={!boost b=boost_document} *:* &
fq=(+available:true +display_in_catalog:Yes +(*:* -facet_field:X)) &
facet.field=field_languages &
facet.field=field_formats &
facet.field=field_categories &
facet.limit=-1 &
facet.mincount=1 &
rows=20
The Debug Output (Simplified)
From Solrβs debug section:
- Total time: ~2000ms
- Query time: 278ms
- Faceting time: 1704ms
- Facet processor:
SimpleFacets
- Facet method:
FCS (FieldCache Scanning)
- Facet fields: 10+
- Each with:
facet.limit=-1, facet.missing=false
So, the query itself is fine β itβs the faceting that eats up most of the runtime.
2. Why Itβs Slow
A. The *:* Query Pattern
Drupal often sends {!boost b=boost_document} *:*, meaning βmatch everything.β
Even with filters, Solr still evaluates the entire index before narrowing results.
Thatβs expensive, especially on big collections.
B. Many fq Filters
Dozens of filters like:
fq=field_a:valueA
fq=field_b:valueB
fq=(+available:true +display_in_catalog:Yes)
Each one adds cost β especially negations like (*:* -field:value) or range queries like [ * TO * ].
C. Excessive Facets
Fields such as field_language, field_format, field_category, etc. are all requested, often with:
facet.limit = -1
facet.missing = false
facet.sort = count
Each of these facets has to count every term across every matching document. Thatβs the main bottleneck β the facet block alone took ~1700ms.
D. The FCS (FieldCache) Method
Solrβs FCS method scans the entire field value space. When many documents or multi-valued fields are involved, itβs slow. The newer enum or stream methods, or JSON facets, are more efficient.
3. What to Fix β In Drupal
A. Reduce the Facet Count
In Configuration β Search API β View Modes, disable facets that arenβt visible on the page.
Every active facet triggers Solr work, even if Drupal doesnβt render it.
B. Limit Facet Results
In Facet API settings, set:
facet.limit = 50
facet.mincount = 1
Avoid facet.limit=-1 β that means βreturn everything.β
C. Avoid facet.missing=false
This setting forces Solr to calculate missing values. Unless your UX needs it, remove it.
D. Use the JSON Facet API
If your Solr core is 7.x or newer, switch Drupalβs Search API backend to use the JSON Facet API.
Itβs faster, parallelized, and supports streaming facet counts.
E. Cache Drupal Results
Enable Drupalβs Search API query cache and facet cache.
It prevents Solr from recomputing identical facets for repeated queries.
4. What to Fix β In Solr
A. Enable Filter Cache
Ensure your Solr solrconfig.xml includes:
<filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="128"/>
This helps repeated filters (like available:true) resolve instantly.
B. Increase facet.threads
If you must run many facets:
Parallelizes field facet computation.
C. Use DocValues
Ensure all facet fields are stored with docValues="true" in the schema:
<field name="field_languages" type="string" stored="true" indexed="true" docValues="true"/>
This speeds up both faceting and sorting.
D. Use JSON Facets or Streaming Facets
Switch from classic facet.field to:
json.facet={
categories: { type: "terms", field: "field_category", limit: 50 },
formats: { type: "terms", field: "field_format", limit: 50 }
}
These APIs skip legacy overhead.
5. Whatβs Actually Happening Internally
From your debug trace:
"facet-debug": {
"elapse": 1704,
"processor": "SimpleFacets",
"appliedMethod": "FCS",
"inputDocSetSize": 10
}
Even with only 10 returned documents, the facet engine must still traverse the full dataset to count terms. This is why even small result sets can be slow when facets are many or unbounded.
6. Checklist for Optimization
| Area |
Action |
Typical Gain |
| Drupal Facet Limit |
Set facet.limit=50 |
60β80% faster |
Remove facet.missing |
Disable |
5β15% faster |
| Enable caching |
Drupal + Solr |
Big |
| Use DocValues |
Schema config |
Major |
| Use JSON facets |
Modern Solr |
2β5Γ faster |
Avoid *:* base queries |
Use tighter filters |
Major |
| facet.threads=4 |
Solr config |
20β40% faster |
7. Example Fixed Query
Before:
?q={!boost b=boost_document} *:*&facet.limit=-1&facet.field=...
After:
?q=*:*&fq=available:true&fq=display_in_catalog:Yes&
facet.limit=50&
facet.threads=4&
json.facet={
languages:{type:terms,field:field_language,limit:50},
formats:{type:terms,field:field_format,limit:50}
}
8. Conclusion
The slowdown isnβt Solr being βslowβ β itβs Drupal asking for everything at once.
By trimming unnecessary facets, tightening query filters, and enabling JSON facets with DocValues, you can cut load time by 80β90% without losing functionality.
This tutorial applies to any Drupal + Apache Solr setup where complex facet-heavy queries are generated by the Search API or Facet API modules.