### Install EXT:solr via Composer Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/InstallTYPO3Extension.html Use this command to install the extension using the Composer dependency manager. ```bash composer require apache-solr-for-typo3/solr ``` -------------------------------- ### Boost Function Examples Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Examples of using recip and termfreq functions to influence document relevance scores. ```text recip(ms(NOW,created),3.16e-11,1,1) ``` ```text termfreq(type,'tx_solr_file') ``` -------------------------------- ### Deploy EXT:solr configuration into Solr installation Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/Solr.html Copies the EXT:solr configSet directory and JAR files into a prepared Solr installation, replacing the solr.xml file. This is the recommended deployment approach for Infrastructure as Code (IaC). ```bash cp -r ${EXTENSION_ROOTPATH}/Resources/Private/Solr/* ${SOLR_INSTALL_DIR}/server/solr ``` -------------------------------- ### Manual sort order example Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example showing the default order of a category facet before applying manual sorting. ```text News Category + Politics (256) + Sports (212) + Economy (185) + Culture (179) + Health (132) + Automobile (99) + Travel (51) ``` -------------------------------- ### Manual sort order example Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Configuration/Reference/TxSolrSearch.rst.txt Demonstration of how manualSortOrder reorders facet options. ```bash News Category + Politics (256) + Sports (212) + Economy (185) + Culture (179) + Health (132) + Automobile (99) + Travel (51) ``` ```bash News Category + Travel (51) + Health (132) + Politics (256) + Sports (212) + Economy (185) + Culture (179) + Automobile (99) ``` -------------------------------- ### Install EXT:solr via Git Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/InstallTYPO3Extension.html Use this command to clone the latest development version of the extension from the GitHub repository. ```bash $ git clone git@github.com:TYPO3-Solr/ext-solr.git solr ``` -------------------------------- ### fieldProcessingInstructions example Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Assigns processing instructions to Solr fields. The example converts the 'changed', 'created', and 'endtime' fields to ISO dates. ```typoscript fieldProcessingInstructions { changed = timestampToIsoDate created = timestampToIsoDate endtime = timestampToIsoDate } ``` -------------------------------- ### Example core.properties file Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Solr/ConfigurationStructures.html Shows the structure of a core.properties file that references a configSet and schema. The path to the schema is relative to the root folder of the configSet. ```properties configSet=ext_solr_6_0_0 schema=german/schema.xml name=core_de dataDir=../../data/german ``` -------------------------------- ### Sort By Configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of setting a custom sort field for search results. ```typoscript plugin.tx_solr.search.query.sortBy = sortTitle asc ``` -------------------------------- ### Setup an options facet Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Frontend/Facets.html Configures a basic options facet on the 'type' Solr field using TypoScript. ```TypoScript plugin.tx_solr.search { faceting = 1 faceting { facets { contentType { label = Content Type field = type } } } } ``` -------------------------------- ### Full SolrFacetMaskAndCombineEnhancer configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Routing/FacetsInPathSegment.html A complete example demonstrating the integration of multi-value separators, character replacement, and route path requirements. ```yaml routeEnhancers: products: type: SolrFacetMaskAndCombineEnhancer limitToPages: - 42 extensionKey: tx_solr routePath: '/{productType}' # Note: All arguments inside of namespace tx_solr. See -> extensionKey # Example: Argument 'type' define as 'filter-type' will convert into 'tx_solr/filter-type' _arguments: productType: filter-productType # Important: Configure requirement for fields! If you wand to allow empty values, set .* requirements: productType: '.*' solr: multiValueSeparator: ';' replaceCharacters: ' ': '-' ``` -------------------------------- ### Set Faceting URL Parameter Style Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of setting the URL parameter style to associative mode in a TypoScript setup file. ```typoscript plugin.tx_solr.search.faceting { urlParameterStyle = assoc } ``` -------------------------------- ### Configure queue index types with TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Example showing how to define index types for different configurations, including extending existing configurations and overriding fields. ```typoscript plugin.tx_solr.index.queue.generalNews { type = tt_news fields.url = URL for the general news // more field configurations here ... } // extends the general news configuration plugin.tx_solr.index.queue.pressNews < plugin.tx_solr.index.queue.generalNews plugin.tx_solr.index.queue.pressNews { fields.url = overwriting URL for the press announcements // may overwrite or unset more settings from the general configuration } // completely different configuration plugin.tx_solr.index.queue.productNews { type = tt_news fields.url = URL for the product news } ``` -------------------------------- ### Boost Query Configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of using boostQuery to rank tt_news documents higher by a factor of 10. ```typoscript plugin.tx_solr.search.query.boostQuery.boostNews = type:tt_news^10 ``` -------------------------------- ### Build Dockerfile image and run container with local volume Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Shows how to build the Dockerfile image and start a container with a mapped local volume for data. Tested with Docker for Mac (not Docker Toolbox). Requires adding '/solrdata' as allowed volume in Docker configuration before executing. ```bash # build the image docker build -t typo3-solr -f Docker/SolrServer/Dockerfile . # create volume directory locally mkdir -p ~/solrdata # add Solr group to volume directory sudo chown :8983 ~/solrdata # run Docker container from image with volume docker run -d -p 127.0.0.1:8282:8983 -v ~/solrdata:/var/solr/data/data typo3-solr ``` -------------------------------- ### Configure Facet Selection Behavior Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example showing how to keep all facet options visible while maintaining accurate document counts, even for options with zero results. ```typoscript plugin.tx_solr.search.faceting.keepAllFacetsOnSelection = 1 plugin.tx_solr.search.faceting.countAllFacetsForSelection = 1 plugin.tx_solr.search.faceting.minimumCount = 0 ``` -------------------------------- ### Configure facet metrics Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of adding statistical metrics to a facet configuration to collect data like sums from index fields. ```typoscript plugin.tx_solr.search.faceting.facets { category { field = field label = Category metrics { downloads = sum(downloads_intS) } } } ``` -------------------------------- ### Fluent API for Queries with the QueryBuilder Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/Archive/solr-release-8-0.html Example of using the QueryBuilder to construct a search query by chaining configuration methods. ```php $query = $queryBuilder->newSearchQuery($rawQuery) ->useResultsPerPage($resultsPerPage) ->useReturnFieldsFromTypoScript() ->useQueryFieldsFromTypoScript() ->useInitialQueryFromTypoScript() ->useFiltersFromTypoScript() ->useFacetingFromTypoScript() ->useVariantsFromTypoScript() ->useGroupingFromTypoScript() ->useHighlightingFromTypoScript() ->usePhraseFieldsFromTypoScript() ->useBigramPhraseFieldsFromTypoScript() ->useTrigramPhraseFieldsFromTypoScript() ->getQuery(); ``` -------------------------------- ### Configure numericRange facet as a slider Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of configuring a facet with the numericRange type, including start, end, and gap settings. ```typoscript plugin.tx_solr.search.faceting.facets.size { field = size_intS label = Size type = numericRange numericRange { start = 0 end = 100 gap = 1 } } ``` -------------------------------- ### Build Docker image and run Solr container with local volume (Dockerfile_full) Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/FAQ/Index.rst.txt When the page is unclear as to the exact image name, but here the example shows an image called 'typo3-solr' and the commands to build, create a volume directory, set its ownership to the Solr group (GID 8983), and run the container mapping the local ~/solrdata volume to /var/solr/data/data. This was tested with Docker for Mac, and the 'solrdata' directory must be allowed as a Docker volume. ```shell # build the image docker build -t typo3-solr -f Docker/SolrServer/Dockerfile . ``` ```shell # create volume directory locally mkdir -p ~/solrdata ``` ```shell # add Solr group to volume directory sudo chown :8983 ~/solrdata ``` ```shell # run Docker container from image with volume docker run -d -p 127.0.0.1:8282:8983 -v ~/solrdata:/var/solr/data/data typo3-solr ``` -------------------------------- ### Configure custom GET parameter name Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Sets a custom GET parameter name for search queries, useful for compatibility with tracking tools. ```typoscript plugin.tx_solr.search.query.getParameter = q ``` -------------------------------- ### Run Docker container with TYPO3_SOLR_ENABLED_CORES to enable only specific cores Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Appendix/DockerTweaks.html Use this command to start the Apache Solr container with only the specified cores (e.g., english and german) enabled on start-up. This reduces memory usage by preventing initialization of unnecessary cores. ```bash docker run -e 'TYPO3_SOLR_ENABLED_CORES=english german' -it typo3solr/ext-solr ``` -------------------------------- ### Search Filter Configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Examples of defining search filters, including stdWrap usage and quoting terms with whitespaces. ```typoscript plugin.tx_solr.search.query.filter { pagesOnly = type:pages johnsPages = author:John badKeywords = {foo} badKeywords.wrap = -keywords:| badKeywords.data = GP:q } ``` ```typoscript plugin.tx_solr.search.query.filter { johnsDoesPages = author:"John Doe" } ``` -------------------------------- ### Define facet fields in TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of defining multiple facets under the plugin.tx_solr.search.faceting.facets configuration path. ```typoscript plugin.tx_solr.search.faceting.facets { type { field = type label = Content Type } category { field = category_stringM label = Category } } ``` -------------------------------- ### Configure Indexing Fields for Vector Content Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Configuration/Reference/TxSolrSearch.rst.txt Example of using SOLR_CONTENT to map specific fields to the index queue. ```typoscript plugin.tx_solr.index.queue.news.fields { vectorContent = SOLR_CONTENT vectorContent.cObject = COA vectorContent.cObject { 10 = TEXT 10 { field = name } 15 = TEXT 15 { field = bodytext } } } ``` -------------------------------- ### Index Solr queue with solr:queue:index Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Development/BestPractice.html Alternative command to index the Solr queue when EXT:solrconsole is installed. Use -n for non-interactive, -a 1 for all, and -s to specify the site. ```bash bin/typo3 solr:queue:index -n -a 1 -s ``` -------------------------------- ### Configure custom type field and facet Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Example of filling a dynamic field 'mytype_stringS' and creating a corresponding facet in TypoScript. ```typoscript plugin.tx_solr { index{ queue{ news = 1 news { type = tt_news fields { mytype_stringS = TEXT mytype_stringS.value = news } } } } search.faceting.facets.mytype_stringS { label = Type field = mytype_stringS } } ``` -------------------------------- ### Run Solr container with host volume Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/Solr.html These commands create a named volume on the host path and start the container with it. The folder for Solr data must exist on the host machine. ```bash mkdir .solrdata docker volume create --name typo3s-solr-server-data --opt type=none --opt device=$PWD/.solrdata --opt o=bind docker run --name=typo3s-solr-server --mount source=typo3s-solr-server-data,target=/var/solr -d -p 8983:8983 typo3solr/ext-solr ``` -------------------------------- ### Fluid template for iterating over search results Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Frontend/Results.html Default Fluid template from Templates/Search/Results.html that iterates over the search results and renders each document with the Result/Document partial. The pagination display range start is used as the start of the ordered list. ```html
``` -------------------------------- ### TypoScript host configuration from AdditionalConfiguration.php Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/FAQ/Index.rst.txt This example shows two steps: first, the TYPO3_CONF_VARS value is set in AdditionalConfiguration.php. Then the TypoScript uses a TEXT element with override.data to use the 'mysolrserver.de' host, falling back to 'localhost'. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['host'] = 'mysolrserver.de'; ``` ```typoscript plugin.tx_solr.solr { host = TEXT host { value = localhost override.data = global:TYPO3_CONF_VARS|EXTCONF|solr|host } } ``` -------------------------------- ### Index Queue Configuration for News (TypoScript) Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Backend/IndexQueue.html Example TypoScript configuration for indexing news records. It defines the queue entry 'news' with type 'tx_news_domain_model_news', maps fields to Solr fields, and enables logging for indexing. Uses custom objects SOLR_CONTENT, SOLR_RELATION, and SOLR_MULTIVALUE. ```typoscript plugin.tx_solr.index.queue { news = 1 news { type = tx_news_domain_model_news fields { abstract = teaser author = author authorEmail_stringS = author_email title = title content = SOLR_CONTENT content { cObject = COA cObject { 10 = TEXT 10 { field = bodytext noTrimWrap = || | } } } category_stringM = SOLR_RELATION category_stringM { localField = categories multiValue = 1 } keywords = SOLR_MULTIVALUE keywords { field = keywords } tags_stringM = SOLR_RELATION tags_stringM { localField = tags multiValue = 1 } url = TEXT url { typolink.parameter = {$plugin.tx_news.settings.detailPid} typolink.additionalParams = &tx_news_pi1[controller]=News& tx_news_pi1[action]=detail&tx_news_pi1[news]={field:uid} typolink.additionalParams.insertData = 1 typolink.useCacheHash = 1 typolink.returnLast = url } } attachments { fields = related_files } } } plugin.tx_solr.logging.indexing.queue.news = 1 ``` -------------------------------- ### Enable Indexing in TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/ConfigureExtension.html Required configuration to allow content indexing within the TYPO3 setup. ```TypoScript config { index_enable = 1 } ``` -------------------------------- ### Configure facet sorting by metric Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of sorting a facet by a defined metric using the sortBy configuration. ```TypoScript pid { label = Content Type field = pid metrics { newest = max(created) } sortBy = metrics_newest desc } ``` -------------------------------- ### Solr YAML Configuration Example Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Backend/ConnectionManager.html This YAML configuration demonstrates how to define Solr connection settings like host and core name at the language level, overriding global defaults. ```yaml base: 'http://solr-ddev-site.ddev.site/' baseVariants: { } errorHandling: { } languages: - title: English enabled: true base: / typo3Language: default locale: en_US.UTF-8 iso-639-1: en navigationTitle: '' hreflang: en-US direction: '' flag: global solr_host_read: solr-host-1 solr_core_read: core_en languageId: '0' - title: German enabled: true base: /de/ typo3Language: de locale: de_DE.UTF-8 iso-639-1: de navigationTitle: '' hreflang: de-DE direction: '' flag: global solr_host_read: solr-host-2 solr_core_read: core_de languageId: '1' rootPageId: 3 routes: { } solr_enabled_read: true solr_path_read: / solr_port_read: 8983 solr_scheme_read: http solr_use_write_connection: false ``` -------------------------------- ### Basic SOLR_RELATION configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Example of a basic relation configuration mapping a local category field to a multi-value index field. ```typoscript category_stringM = SOLR_RELATION category_stringM { localField = category multiValue = 1 } ``` -------------------------------- ### Configure facet rendering with renderingInstruction Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Overwrites how single facet options are rendered using TypoScript cObjects. This example demonstrates using a CASE object to map facet values to localized labels. ```typoscript plugin.tx_solr { search { faceting { facets { type { renderingInstruction = CASE renderingInstruction { key.field = optionValue pages = TEXT pages.value = Pages pages.lang.de = Seiten tx_solr_file = TEXT tx_solr_file.value = Files tx_solr_file.lang.de = Dateien tt_news = TEXT tt_news.value = News tt_news.lang.de = Nachrichten } } language { renderingInstruction = CASE renderingInstruction { key.field = optionValue 0 = TEXT 0.value = English 0.lang.de = Englisch 1 = TEXT 1.value = German 1.lang.de = Deutsch } } } } } } ``` -------------------------------- ### YAML site configuration with language-level Solr settings Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/Archive/solr-release-10-0.html Example YAML configuration for a TYPO3 site showing language-specific solr_host_read and solr_core_read settings. Demonstrates the fallback mechanism where settings can be defined per language and fall back to global settings if not configured. ```yaml base: 'http://solr-ddev-site.ddev.site/' baseVariants: { } errorHandling: { } languages: - title: English enabled: true base: / typo3Language: default locale: en_US.UTF-8 iso-639-1: en navigationTitle: '' hreflang: en-US direction: '' flag: global solr_host_read: solr_node_1 solr_core_read: core_en languageId: '0' - title: German enabled: true base: /de/ typo3Language: de locale: de_DE.UTF-8 iso-639-1: de navigationTitle: '' hreflang: de-DE direction: '' flag: global solr_host_read: solr_node_2 solr_core_read: core_de languageId: '1' rootPageId: 3 routes: { } solr_enabled_read: true solr_path_read: /solr/ solr_port_read: 8983 solr_scheme_read: http solr_use_write_connection: false ``` -------------------------------- ### Configure SOLR_CLASSIFICATION Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Example configuration for classifying content into categories like programming, cms, or database based on match patterns. ```typoscript topic_stringM = SOLR_CLASSIFICATION topic_stringM { field = __solr_content classes { programming { matchPatterns = php, java, javascript, go class = programming } cms { matchPatterns = TYPO3, joomla class = cms } database { matchPatterns = mysql, MariaDB, postgreSQL class = database } } } ``` -------------------------------- ### Overwrite facet rendering with cObject Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Configuration/Reference/TxSolrSearch.rst.txt Example demonstrating how to use a CASE cObject to customize the rendering of facet options based on their value. ```typoscript plugin.tx_solr { search { faceting { facets { type { renderingInstruction = CASE renderingInstruction { key.field = optionValue pages = TEXT pages.value = Pages pages.lang.de = Seiten tx_solr_file = TEXT tx_solr_file.value = Files tx_solr_file.lang.de = Dateien ``` -------------------------------- ### Create Solr core via REST API (not recommended) Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/Solr.html Alternative to file-based core creation using the Solr V2 API. This method is not recommended. The JSON payload includes the core name, configSet, schema, instanceDir, and dataDir. Note: the example contains a missing comma after instanceDir, which may cause a JSON parse error. ```bash curl -X POST http://localhost:8983/api/cores -H 'Content-Type: application/json' -d ' { "create": { "name": "", "configSet": "ext_solr_", "schema": "german/schema.xml", "instanceDir": "cores/" "dataDir": "/data/" } } ' ``` -------------------------------- ### Page Sections Filter and Rootline Configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of using the magic __pageSections filter and configuring the required rootline field for indexing. ```typoscript plugin.tx_solr.search.query.filter { __pageSections = TEXT __pageSections.data = leveluid:0 } ``` ```typoscript plugin.tx_solr.index.queue { news.fields.rootline = {$plugin.tx_news.settings.detailPid} _FILES.pageContext.__RecordContext.rootline = pid } ``` -------------------------------- ### Get index statistics Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Solr/IndexMaintenance.html Retrieves information and statistics about the index using the Luke request handler. ```bash curl 'http://host:port/path-to-solr/admin/luke' ``` -------------------------------- ### Index Queue configuration example for tt_news Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Defines an indexing configuration for tt_news records. It maps fields, uses special content objects (SOLR_CONTENT, SOLR_RELATION, SOLR_MULTIVALUE), and builds a URL via typolink. ```typoscript // enables indexing of tt_news records plugin.tx_solr.index.queue.news = 1 plugin.tx_solr.index.queue.news.fields { abstract = short author = author description = short title = title // the special SOLR_CONTENT content object cleans HTML and RTE fields content = SOLR_CONTENT content { field = bodytext } // the special SOLR_RELATION content object resolves relations category_stringM = SOLR_RELATION category_stringM { localField = category multiValue = 1 } // the special SOLR_MULTIVALUE content object allows to index multivalue fields keywords = SOLR_MULTIVALUE keywords { field = keywords } // build the URL through typolink, make sure to use returnLast = url url = TEXT url { typolink.parameter = {$plugin.tt_news.singlePid} typolink.additionalParams = &tx_ttnews[tt_news]={field:uid} typolink.additionalParams.insertData = 1 typolink.returnLast = url typolink.useCacheHash = 1 } sortAuthor_stringS = author sortTitle_stringS = title } ``` -------------------------------- ### Configure query-based grouping Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of how to group search results based on custom Solr queries defined by page IDs. ```typoscript plugin.tx_solr { search { grouping = 1 grouping { numberOfGroups = 5 numberOfResultsPerGroup = 5 allowGetParameterSwitch = 0 groups { pidQuery { queries { lessThenTen = pid:[0 TO 10] lessThen30 = pid:[11 TO 30] rest = pid:[30 TO *] } } } } } } ``` -------------------------------- ### Configure conditional facet rendering with requirements Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of defining a requirement for a facet so it only renders when specific options are selected in another facet. ```typoscript plugin.tx_solr { search { faceting { facets { type { label = Content Type field = type } category { label = Category field = category_stringS requirements { typeIsNews { # typeIsNews is the name of the requirement, c # choose any so you can easily recognize what it does facet = type # The name of the facet as defined above values = news # The value of the type facet option as # it is stored in the Solr index } } } } } } } ``` -------------------------------- ### Example PHP array for multi-value Solr field Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/solr-release-14-0.html This represents the structure of the PHP array before it is passed to json_encode(). ```php [ [ 'latitude' => 48.135125, 'longitude' => 11.581981, ], ] ``` -------------------------------- ### Configure Large Language Model JSON Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/solr-release-12-1.html Example JSON configuration for connecting an OpenAI embedding model to support vector search. ```json { "class": "dev.langchain4j.model.openai.OpenAiEmbeddingModel", "name": "llm", "params": { "baseUrl": "https://api.openai.com/v1", "apiKey": "apiKey-openAI", "modelName": "text-embedding-3-small", "timeout": 5, "logRequests": true, "logResponses": true, "maxRetries": 2 } } ``` -------------------------------- ### Set initialPagesAdditionalWhereClause for pages indexing configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Filters pages before the additionalWhereClause is applied, providing a stronger filter. The example excludes spacer pages and pages with no_search, hidden, or nav_hide set to zero. ```typoscript // Filter away pages that are "spacer" and have no_search, hidden and nav_hide set to zero plugin.tx_solr.index.queue.pages.initialPagesAdditionalWhereClause = doktype <> 199 AND no_search = 0 AND hidden = 0 AND nav_hide = 0 ``` -------------------------------- ### Configure metrics for options facet in TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/Archive/solr-release-8-0.html Adds a 'metrics' TypoScript option to an options facet to collect and show metrics from documents belonging to a facet option. The example configures 'newest' and 'oldest' metrics using max and min functions on the 'created' field. ```typoscript plugin.tx_solr.search.faceting.facets.type.metrics { newest = max(created) oldest = min(created) } ``` -------------------------------- ### Overwriting Facet Partial via TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Frontend/Facets.html Example of overriding the default partial used for rendering a specific facet. ```typoscript plugin.tx_solr.search { faceting = 1 faceting.facets { contentType { field = type label = Content Type partialName = mySpecialFacet } } } ``` -------------------------------- ### Set additionalWhereClause for pages indexing configuration Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Limits which records are added to the Index Queue using a WHERE clause. The example restricts indexing to standard and mount pages (doktype IN(1, 7)). ```typoscript // only index standard and mount pages, enabled for search plugin.tx_solr.index.queue.pages.additionalWhereClause = doktype IN(1, 7) ``` -------------------------------- ### getBaseDocument() - Create base Solr document with required fields Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Development/Indexing.rst.txt Creates a Solr document with core fields: id, variantId, type, appKey, access, site, siteHash, uid, and pid. Uses SiteRepository to get site domain and site hash. ```php /** * Creates a Solr document with the basic / core fields set already. * * @param array $itemRecord The record to use to build the base document * @param int $rootPageId root page id * @return Document A basic Solr document */ protected function getBaseDocument(array $itemRecord, int $rootPageId): Document { $siteRepository = GeneralUtility::makeInstance(SiteRepository::class); $site = $siteRepository->getSiteByRootPageId($rootPageId); /** @var Document $document */ $document = GeneralUtility::makeInstance(Document::class); // required fields $document->setField('id', 'custom_type_' . $itemRecord['uid']); $document->setField('variantId', 'custom_type' . $itemRecord['uid']); $document->setField('type', 'custom_type'); $document->setField('appKey', 'EXT:solr'); $document->setField('access', ['r:0']); // site, siteHash $document->setField('site', $site->getDomain()); $document->setField('siteHash', $site->getSiteHash()); // uid, pid $document->setField('uid', $itemRecord['uid']); $document->setField('pid', 1); return $document; } ``` -------------------------------- ### Run Solr container with anonymous volume Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/Solr.html Starts a Solr container with an anonymous volume for persistent data. The container is named 'typo3s-solr-server' and exposes port 8983. ```bash docker run --name=typo3s-solr-server -d -p 8983:8983 typo3solr/ext-solr ``` -------------------------------- ### Configure field-based grouping Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Example of how to group search results based on a specific Solr field named 'type'. ```typoscript plugin.tx_solr { search { grouping = 1 grouping { numberOfGroups = 5 numberOfResultsPerGroup = 5 allowGetParameterSwitch = 0 groups { typeGroup { field = type } } } } } ``` -------------------------------- ### Configure index queue fields Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Maps Solr field names to database table fields or content objects. The example demonstrates mapping content and title fields, and using a typolink for the URL field. ```typoscript plugin.tx_solr.index.queue.[indexConfig].fields { content = bodytext title = title url = TEXT url { typolink.parameter = {$plugin.tx_extensionkey.singlePid} typolink.additionalParams = &tx_extenionkey[record]={field:uid} typolink.additionalParams.insertData = 1 typolink.returnLast = url } } ``` -------------------------------- ### Configuring Facet Grouping via TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Frontend/Facets.html Example of changing the facet group name using TypoScript configuration to move a facet to a different area. ```typoscript plugin.tx_solr.search { faceting = 1 faceting.facets { contentType { field = type label = Content Type groupName = bottom } } } ``` -------------------------------- ### Bootstrap the test environment Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Development/CI.html Run this command once to bootstrap the test environment. It exports environment variables for the TYPO3 testing framework, creates the test database, and creates a test Solr instance. ```bash source ./Build/Test/bootstrap.sh --local ``` -------------------------------- ### Define nested TypoScript for multiValue fields Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/solr-release-12-1.html Example configuration for defining the contents of a vector field using nested TypoScript for multi-value fields. ```typoscript plugin.tx_solr.index.queue.pages.fields.someDoktypeSpecificCategory_stringM = CASE plugin.tx_solr.index.queue.pages.fields.someDoktypeSpecificCategory_stringM { key.field = doktype 80 = SOLR_RELATION 80 { localField = some_doktype_specific_sys_category multiValue = 1 } } ``` -------------------------------- ### Configure custom entry templates and partials with FLUID Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/Archive/solr-release-7-0.html Demonstrates how to configure template root paths, partials, and layouts, and define available templates for the editor in the flexform. ```typoscript plugin.tx_solr { view { templateRootPaths.100 = EXT:your_config_extension/Resources/Private/Templates/ partialRootPaths.100 = EXT:your_config_extension/Resources/Private/Partials/ layoutRootPaths.100 = EXT:your_config_extension/Resources/Private/Layouts/ templateFiles { results = Results results.availableTemplates { default { label = Default Searchresults Template file = Results } products { label = Products Template file = ProductResults } } } } } ``` -------------------------------- ### Customize vectorContent field via TypoScript Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/solr-release-12-1.html Example TypoScript configuration to define the contents of the vectorContent field used for vector generation during indexing. ```typoscript plugin.tx_solr.index.queue.news.fields { vectorContent = SOLR_CONTENT vectorContent.cObject = COA vectorContent.cObject { 10 = TEXT 10 { field = name } 15 = TEXT 15 { field = bodytext } } } ``` -------------------------------- ### Run the CI suite Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Development/CI.html Run this command after bootstrapping the test environment to execute all tests. A green bar indicates that everything is configured correctly. ```bash ./Build/Test/cibuild.sh ``` -------------------------------- ### SOLR_RELATION with additionalWhereClause Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Example of filtering related items using an additional SQL where clause. ```typoscript category_stringM = SOLR_RELATION category_stringM { localField = tags multiValue = 1 additionalWhereClause = pid=2 } ``` -------------------------------- ### Check available CLI commands Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Use the TYPO3 binary to list all available commands for the extension. ```bash bin/typo3 list ``` -------------------------------- ### Configure site dependencies in config.yaml Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/SiteSets.html Add EXT:solr configuration to your project by defining dependencies in the site configuration file. ```yaml dependencies: - apache-solr-for-typo3/solr - apache-solr-for-typo3/solr-stylesheets ``` -------------------------------- ### Run EXT:solr configuration with official Apache Solr Docker image Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/GettingStarted/Solr.html Mounts the EXT:solr configuration and data from a local volume into the official solr:8.5 container. Requires copying the configuration from Resources/Private/Solr and setting proper ownership for the Solr user (8983). On macOS, ensure the volume folder is added to Docker's file sharing preferences. ```bash mkdir -p ~/mysolr cp -r Resources/Private/Solr/* ~/mysolr/. mkdir ~/mysolr/data sudo chown -R 8983:8983 ~/mysolr docker run -d -p 8983:8983 -v ~/mysolr:/var/solr/data solr:8.5 ``` -------------------------------- ### SOLR_RELATION with foreignLabel dataWrap Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrIndex.html Example using foreignLabel with dataWrap to construct a custom label from multiple fields of the related record. ```typoscript authorsNames_stringM = SOLR_RELATION authorsNames_stringM { localField = author foreignLabel.dataWrap = {field : first_name} {field : last_name} multiValue = 1 } ``` -------------------------------- ### Build a Search Query with QueryBuilder Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Releases/Archive/solr-release-8-0.rst.txt Demonstrates the usage of the QueryBuilder class to construct a search query by chaining configuration methods before calling getQuery(). ```php $query = $queryBuilder->newSearchQuery($rawQuery) ->useResultsPerPage($resultsPerPage) ->useReturnFieldsFromTypoScript() ->useQueryFieldsFromTypoScript() ->useInitialQueryFromTypoScript() ->useFiltersFromTypoScript() ->useFacetingFromTypoScript() ->useVariantsFromTypoScript() ->useGroupingFromTypoScript() ->useHighlightingFromTypoScript() ->usePhraseFieldsFromTypoScript() ->useBigramPhraseFieldsFromTypoScript() ->useTrigramPhraseFieldsFromTypoScript() ->getQuery(); ``` -------------------------------- ### Configure Solr host from AdditionalConfiguration.php using override.data Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Shows how to set the Solr host in AdditionalConfiguration.php and use it in TypoScript with a TEXT element and override.data. The first block is added to AdditionalConfiguration.php, the second block is the TypoScript configuration. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['host'] = 'mysolrserver.de'; ``` ```typoscript plugin.tx_solr.solr { host = TEXT host { value = localhost override.data = global:TYPO3_CONF_VARS|EXTCONF|solr|host } } ``` -------------------------------- ### Configure Compound Index Format Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Releases/Archive/solr-release-6-0.rst.txt Set the useCompoundFile property in solrconfig.xml to manage index file creation and avoid 'too many open files' errors. ```xml false ``` -------------------------------- ### Configure Varnish Cache-Control for Indexing Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Use this configuration in sub vcl_fetch to force-reload pages and remove cache headers when no-cache is detected. ```vcl if (req.http.Cache-Control ~ "no-cache") { set beresp.ttl = 0s; # Make sure ESI includes are processed! esi; set beresp.http.X-Cacheable = "NO:force-reload"; # Make sure that We remove all cache headers, so the Browser does not cache it for us! remove beresp.http.Cache-Control; remove beresp.http.Expires; remove beresp.http.Last-Modified; remove beresp.http.ETag; remove beresp.http.Pragma; return (deliver); } ``` -------------------------------- ### JSON array for multiple coordinate values Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/solr-release-14-0.html Example of how multiple coordinate objects are represented within the same JSON array for a multi-value Solr field. ```json [ {"latitude":48.135125,"longitude":11.581981,"city":"Munich"}, {"latitude":50.110924,"longitude":8.682127,"city":"Frankfurt"}, {"latitude":53.551086,"longitude":9.993682,"city":"Hamburg"} ] ``` -------------------------------- ### Create cores with CoreAdmin API Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Solr/IndexMaintenance.html Creates a new Solr core using the CoreAdmin API with a specified configSet, schema, and data directory. ```bash curl 'http://host:port/path-to-solr/admin/cores?action=CREATE&name=core_de&configSet=ext_solr_8_0_0&schema=german/schema.xml&dataDir=../../data/german' ``` -------------------------------- ### Register a custom StatisticsWriterProcessor in ext_localconf.php Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Register your custom processor by assigning the class name to the $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['afterSearch']['statistics'] configuration key. ```php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['afterSearch']['statistics'] = MyVendor/Namespace/Statistics/CustomStatisticsWriterProcessor::class; ``` -------------------------------- ### Configure custom entry template in legacy EXT:solr Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Releases/Archive/solr-release-7-0.html Shows the legacy method for setting a custom entry template using TypoScript. ```typoscript plugin.tx_solr.templateFiles.search = EXT:solr/Resources/Templates/PiSearch/search.htm ``` -------------------------------- ### Configure numericRange facet for pid field Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Frontend/Facets.html This TypoScript configuration defines a numericRange facet for the 'pid' field with a specified start, end, and gap. ```typoscript plugin.tx_solr.search { faceting = 1 faceting.facets { pidRangeRange { field = pid label = Pid Range type = numericRange numericRange { start = 0 end = 100 gap = 1 } } } } ``` -------------------------------- ### JSON transport format for multi-value objects Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Releases/solr-release-14-0.rst.txt The resulting JSON format after applying json_encode to the PHP array, including single and multiple value examples. ```json [{"latitude":48.135125,"longitude":11.581981}] ``` ```json [ {"latitude":48.135125,"longitude":11.581981,"city":"Munich"}, {"latitude":50.110924,"longitude":8.682127,"city":"Frankfurt"}, {"latitude":53.551086,"longitude":9.993682,"city":"Hamburg"} ] ``` -------------------------------- ### Define OptionsToggle Partial Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Create the partial template to handle facet option rendering, including logic to toggle between adding and removing facet items. ```html
{facet.label}
``` -------------------------------- ### Configure results per page with resultsPerPage and resultsPerPageSwitchOptions Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Frontend/PerPage.html Configure the default number of search results per page and the switch options available to the user. The frontend will show 6 results by default and offer 12, 18, and 24 as alternatives. ```typoscript plugin.tx_solr { search { results { resultsPerPage = 6 resultsPerPageSwitchOptions = 12, 18, 24 } } } ``` -------------------------------- ### Configure route path for facets Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Routing/FacetsInPathSegment.html Define the route path for the products page to include a placeholder for the facet variable. ```yaml routeEnhancers: products: routePath: '/{productType}' ``` -------------------------------- ### Event listener registration before and after RecordInsertedEvent introduction Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Releases/solr-release-14-0.rst.txt Shows the YAML configuration for event listeners before and after the change. Before, one listener covered both record insertions and updates via RecordUpdatedEvent. After, separate registrations for RecordInsertedEvent and RecordUpdatedEvent are required. ```yaml # Before – one listener covering both cases tags: - name: event.listener event: ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent ``` ```yaml # After – separate registrations tags: - name: event.listener event: ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordInsertedEvent - name: event.listener event: ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent ``` -------------------------------- ### Index value into multiValue field using SOLR_MULTIVALUE Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/FAQ/Index.html Use SOLR_MULTIVALUE in TypoScript to index a value into a multiValue field from a user function. The example shows a USER object with a userFunc and a separator. ```typoscript plugin.tx_solr.index.queue.indexConfigName { fields { somevalue_stringM = SOLR_MULTIVALUE somevalue_stringM { stdWrap.cObject = USER stdWrap.cObject.userFunc = Vendor\Ext\Classname->getValues separator=, } } } ``` -------------------------------- ### createDocument() - Create Solr document with field mapping Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/Development/Indexing.rst.txt Builds a Solr document from a record, mapping fields like title, summary, information, keywords, area, and category to Solr fields. Sets the URL field to a placeholder 'todo' requiring custom implementation. ```php /** * Create a Solr document which then is sent to Solr * * @param array $row * @param int $pageId * @return Document */ protected function createDocument(array $row, int $pageId): Document { $document = $this->getBaseDocument($row, $pageId); $solrFieldMapping = [ 'title' => 'title', 'summary' => 'abstract', 'information' => 'content', 'keywords' => 'keywords', 'area' => 'area_stringS', 'category' => 'category_stringS' ]; foreach ($row as $key => $value) { if (isset($solrFieldMapping[$key])) { $document->setField($solrFieldMapping[$key], $value); } } // url generation $document->setField('url', 'todo'); // custom implementation required return $document; } ``` -------------------------------- ### Configure query.userFields with add and remove sub-keys Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/Configuration/Reference/TxSolrSearch.html Applies comma-separated deltas to the qf-derived base list when the scalar value is empty. ```typoscript plugin.tx_solr.search.query.userFields { add = customField, fileExtension remove = abstract } ``` -------------------------------- ### Configure indexing credentials for protected pages Source: https://docs.typo3.org/p/apache-solr-for-typo3/solr/main/en-us/_sources/FAQ/Index.rst.txt Provide htaccess username and password for the indexing queue. Ensure these files are protected from public access. ```typoscript plugin.tx_solr.index.queue.pages.indexer.authorization.username = your_username plugin.tx_solr.index.queue.pages.indexer.authorization.password = your_password ```