TYPO3 10与Solr扩展:标题部分匹配搜索功能失效求助
Hey there, let's tackle this partial search issue you're facing! The problem you're seeing—where "fork" doesn't match "forklift" and "forklift" doesn't match "forklifttest"—is because Solr's default text fields are set up for exact or stemmed word matches, not partial/substring/prefix matches. Your attempt with _textNgramS didn't work likely because of incorrect field naming/typing, and we can fix this without modifying Solr's schema.xml (since you want to avoid that).
Step 1: Add EdgeNgram Fields to Your Index Configuration
Since you want prefix-based partial matches (e.g., "fork" → "forklift", "forklift" → "forklifttest"), EdgeNgram fields are perfect (they're more efficient than full Ngrams for prefix searches). Update your downloads index queue config to add EdgeNgram fields for both the file metadata title and the filename:
downloads = 1 downloads { indexingPriority = 160 table = sys_file_metadata additionalPageIds = 1,0 fields { # Keep all your existing fields here... title = title tabgroup_stringS = TEXT tabgroup_stringS.value = downloads size_intS = SOLR_RELATION size_intS { localField = file foreignLabelField = size } fileExtension = SOLR_RELATION fileExtension { localField = file foreignLabelField = extension } title_textS = SOLR_RELATION title_textS { localField = file foreignLabelField = name } url_stringS = SOLR_RELATION url_stringS { localField = file foreignLabelField = identifier } storageUid_intS = SOLR_RELATION storageUid_intS { localField = file foreignLabelField = storage.uid } storage_stringS = SOLR_RELATION storage_stringS { localField = file foreignLabelField = storage } category_stringM = SOLR_RELATION category_stringM { localField = categories removeEmptyValues = 1 multiValue = 1 } description = description keywords = keywords author = creator # Add these EdgeNgram fields for partial search # For sys_file_metadata.title title_edge_ngramS = title title_edge_ngramS.type = text_edge_ngram # For file.name (your existing title_textS field) title_text_edge_ngramS = SOLR_RELATION title_text_edge_ngramS { localField = file foreignLabelField = name type = text_edge_ngram } } }
Step 2: Update Search Query to Use EdgeNgram Fields
Next, you need to tell Solr to search these new EdgeNgram fields alongside your regular fields. Add this TypoScript to your site's configuration (e.g., in setup.typoscript):
plugin.tx_solr.search.query.fields = title^3, title_edge_ngramS^2, title_textS^2, title_text_edge_ngramS^1, description^1, keywords^1
The ^X values are weightings—adjust them to prioritize exact matches (higher numbers) over partial matches (lower numbers) so relevant results show up first.
Step 3: Reindex Your Data
For the new fields to take effect:
- Go to the TYPO3 backend → Solr module → Index Queue
- Select the
downloadsqueue, click Empty Queue - Click Add to Queue to repopulate it
- Run the indexer (either via the backend or CLI command:
./typo3/solr:indexqueue:worker downloads)
Step 4: Test the Search
Now try searching for "fork"—you should see files with "forklift" in their title/filename. Searching "forklift" should return files with "forklifttest" too.
Why Your Original Attempt Failed
_textNgramS = title didn't work because:
- The field naming doesn't align with TYPO3 Solr's conventions (we need to explicitly define the field type as
text_edge_ngramortext_ngram) - Even if the field existed, you weren't including it in your search query fields, so Solr never checked it for matches
内容的提问来源于stack exchange,提问作者Benjamin

