Skip to content

Commit

Permalink
[FEATURE] add ext. Solr support (#485)
Browse files Browse the repository at this point in the history
* [WIP] require composer

* [TASK] implement solr url modifier

* [TASK] make header template compatible with new solr

* [TASK] add special configuration file for solr

* [TASK] make suggest script compatible with new solr suggest

* [TASK] remove url modifier for solr

* [TASK] new TypoScript solr configuration

* [TASK] changes in solr templates according to changes in solr 9

* [TASK] add backward compatibility template for document results

* [TASK] remove comma and semicolon in suggest.js

* [TASK] compile less and css

* [TASK] mvoe suggest solr configuration
  • Loading branch information
anjeylink authored and dmh committed Mar 5, 2019
1 parent 3342e0d commit e8ee00d
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[applicationContext = Development/Docker]
#[applicationContext = Development/Docker]

# set solr host to t3kit_solr
plugin.tx_solr.solr.host = t3kit_solr

[global]
#[global]
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<div class="tx-solr-searchbox">

<s:searchForm id="tx-solr-search-form-pi-results" additionalFilters="{additionalFilters}">
<input type="hidden" name="L" value="{languageUid}" />
<input type="hidden" name="id" value="{pageUid}" />
<f:if condition="{addPageAndLanguageId}">
<input type="hidden" name="L" value="{languageUid}" />
<input type="hidden" name="id" value="{pageUid}" />
</f:if>

<div class="header-middle__search-wrp" >
<div class="header-middle__search-box" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<div class="tx-solr-searchbox">

<s:searchForm id="tx-solr-search-form-pi-results" additionalFilters="{additionalFilters}">
<input type="hidden" name="L" value="{languageUid}" />
<input type="hidden" name="id" value="{pageUid}" />

<f:if condition="{addPageAndLanguageId}">
<input type="hidden" name="L" value="{languageUid}" />
<input type="hidden" name="id" value="{pageUid}" />
</f:if>

<div class="main-navigation__search-btn-wrp _header-top-search-btn">
<a class="main-navigation__search-btn js__main-navigation__search-btn" href="">{s:translate(key:'submit',default:'Search')}<span></span></a>
</div>
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Extensions/Solr/Layouts/Main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<div class="tx_solr">
<f:render section="main" />
</div>
44 changes: 44 additions & 0 deletions Resources/Private/Extensions/Solr/Partials/Result/Document.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:s="http://typo3.org/ns/ApacheSolrForTypo3/Solr/ViewHelpers">

<f:section name="Document">

<li class="results-entry{f:if(condition:document.isElevated, then: ' results-elevated')}"
data-document-score="{document.score}"
data-document-id="{document.id}"
data-document-url="{document.url}"
>
<f:if condition="{document.isElevated}">
<div class="results-elevated-label"><s:translate key="sponsored"/></div>
</f:if>

<h5 class="results-topic"><a href="{s:uri.result.addSearchWordList(url:document.url, searchWords:resultSet.usedQuery.keywords)}">{document.title}</a></h5>

<div class="results-teaser">
<f:render partial="Result/RelevanceBar" section="RelevanceBar" arguments="{resultSet:resultSet, document:document}" />

<p class="result-content">{s:document.highlightResult(resultSet:resultSet, document:document, fieldName:'content')}</p>

<f:if condition="{document.type} == 'tx_solr_file'">
<p>
<s:translate key="file_mimetype" />: {document.fileMimeType}<br />
<s:translate key="file_referenced" />:

<ul class="references">
<f:if condition="{document.fileReferenceUrl}">
<li><f:link.typolink title="{document.fileReferenceTitle}" parameter="{document.fileReferenceUrl}">{document.fileReferenceTitle}</f:link.typolink></li>
</f:if>
<f:if condition="{document.variants}">
<f:for each="{document.variants}" as="variant">
<li><f:link.typolink title="{variant.fileReferenceTitle}" parameter="{variant.fileReferenceUrl}">{variant.fileReferenceTitle}</f:link.typolink></li>
</f:for>
</f:if>
</ul>
</p>
</f:if>
<s:debug.documentScoreAnalyzer document="{document}" />
</div>
</li>

</f:section>
9 changes: 9 additions & 0 deletions Resources/Private/Extensions/Solr/Templates/Search/Form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:s="http://typo3.org/ns/ApacheSolrForTypo3/Solr/ViewHelpers/">

<f:layout name="Main"/>

<f:section name="main">
<f:render partial="Search/Form" section="Form" arguments="{search:search, additionalFilters:additionalFilters, pluginNamespace:pluginNamespace}" />
</f:section>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</p>
</f:if>

<f:if condition="{hasSearched}">
<f:if condition="{resultSet.hasSearched}">
<f:if condition="{resultSet.usedSearch.numberOfResults}">
<f:render partial="Result/PerPage" section="PerPage" arguments="{resultSet: resultSet}" />
</f:if>
Expand All @@ -65,7 +65,7 @@
</div>

<div id="tx-solr-search-functions" class="col-md-3">
<f:if condition="{hasSearched}">
<f:if condition="{resultSet.hasSearched}">
<f:if condition="{resultSet.usedSearchRequest.contextTypoScriptConfiguration.searchSorting}">
<f:render partial="Result/Sorting" section="Sorting" arguments="{resultSet:resultSet}" />
</f:if>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Enable search field autocomplete/suggest
# Ajaxify the suggest/results
tx_solr_suggest = PAGE
tx_solr_suggest {
typeNum = 7384
config {
disableAllHeaderCode = 1
xhtml_cleaning = 0
admPanel = 0
additionalHeaders = Content-type: text/plain
no_cache = 0
}

10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = Solr
pluginName = pi_suggest
vendorName = ApacheSolrForTypo3
controller = Suggest
action = suggest
}
}

# Enable suggest
plugin.tx_solr.search {
suggest = 1
suggest {
numberOfSuggestions = 10
suggestField = spell
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

plugin.tx_solr.index.queue {

news = 1
news {
table = tx_news_domain_model_news

fields {
abstract = teaser

author = author
authorEmail_stringS = author_email

title = title

datetime_stringS = TEXT
datetime_stringS {
field = datetime
date = d.m.Y H:i
}

datetime_dateS = TEXT
datetime_dateS {
field = datetime
date = Y-m-d\TH:i:s\Z
}

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 = CASE
url {
key.field = type

# Internal
1 = TEXT
1 {
if.isTrue.field = internalurl
typolink.parameter.field = internalurl
typolink.useCacheHash = 1
typolink.returnLast = url
}

# External
2 = TEXT
2 {
if.isTrue.field = externalurl
field = externalurl
}

default = TEXT
default {
typolink.parameter = {$themes.configuration.features.newsDefaultDetailPid}
typolink.additionalParams = &tx_news_pi1[controller]=News&tx_news_pi1[action]=detail&tx_news_pi1[news]={field:uid}&L={field:__solr_index_language}
typolink.additionalParams.insertData = 1
typolink.useCacheHash = 1
typolink.returnLast = url
}
}
}

attachments = 1
attachments {
fields = fal_related_files
fileExtensions = *
}
}

}

plugin.tx_solr.logging.indexing.queue.news = 1
35 changes: 23 additions & 12 deletions Resources/Private/Extensions/Solr/TypoScript/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@
plugin.tx_solr.enabled = {$themes.configuration.features.enableSolr}

# Solr default ts setup
plugin.tx_solr.suggest = 1
plugin.tx_solr.search.faceting = 1
plugin.tx_solr.search.spellchecking = 1

plugin.tx_solr.search.results.resultsHighlighting = 1
plugin.tx_solr.search.results.resultsHighlighting.wrap = <mark>|</mark>
plugin.tx_solr.search.sorting = 1
plugin.tx_solr.search.targetPage = {$themes.configuration.features.searchTargetPage}
plugin.tx_solr.solr.path = /solr/{$themes.configuration.features.solrBaseCoreName}_{$themes.languages.default.isoCode}/


plugin.tx_solr.solr {
read.path = /solr/{$themes.configuration.features.solrBaseCoreName}_{$themes.languages.default.isoCodeShort}/
write.path < .read.path
}

[globalVar = GP:L > 0]
plugin.tx_solr.solr {
read.path = /solr/{$themes.configuration.features.solrBaseCoreName}_{$themes.languages.current.isoCodeShort}/
write.path < .read.path
}
[end]

# Add teaser to search query
plugin.tx_solr.search.query.queryFields := addToList(abstract^39.0)
Expand Down Expand Up @@ -78,7 +89,7 @@ plugin.tx_solr.search.faceting.facets.type {
key.field = optionValue
# pages
pages = TEXT
pages.value = {LLL:EXT:lang/locallang_common.xlf:pages}
pages.value = {LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:pages}
pages.insertData = 1
# tx_news
tx_news_domain_model_news = TEXT
Expand All @@ -93,10 +104,6 @@ plugin.tx_solr.index.queue.pages.fields.category_stringM {
multiValue = 1
}

# Change solr core if language other than default
[globalVar = GP:L > 0]
plugin.tx_solr.solr.path = /solr/{$themes.configuration.features.solrBaseCoreName}_{$themes.languages.current.isoCode}/
[global]

# Additional when solr is enabled
[globalVar = LIT:1 = {$themes.configuration.features.enableSolr}]
Expand All @@ -107,15 +114,19 @@ plugin.tx_solr.index.queue.pages.fields.category_stringM {

## Docker configuration
[applicationContext = Development/Docker, Production/Docker]
plugin.tx_solr.solr.path = /solr/{$themes.configuration.features.solrBaseCoreName}_{$themes.languages.default.isoCodeShort}/
[global]

[globalVar = GP:L > 0] && [applicationContext = Development/Docker, Production/Docker]
plugin.tx_solr.solr.path = /solr/{$themes.configuration.features.solrBaseCoreName}_{$themes.languages.current.isoCodeShort}/
# set solr host to t3kit_solr
plugin.tx_solr.solr {
read.host = t3kit_solr
write.host = t3kit_solr
}
[global]

# enable suggest on devices with touch support
#page.jsInline {
# 1910 = TEXT
# 1910.value = var forceEnableSuggest = false;
#}


<INCLUDE_TYPOSCRIPT: source="DIR:EXT:theme_t3kit/Resources/Private/Extensions/Solr/TypoScript/IndexConfiguration/" extensions="typoscript">
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:theme_t3kit/Resources/Private/Extensions/Solr/TypoScript/Includes/" extensions="typoscript">
14 changes: 9 additions & 5 deletions Resources/Public/css/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ var mainSearchInputList = {}
autoFirst: true
})
var req = false

$(this).on('keyup.search.suggest', function (e) {
var c = e.keyCode
if (c === 13 || c === 27 || c === 38 || c === 40) {
Expand All @@ -716,16 +717,19 @@ var mainSearchInputList = {}
req = true
$.ajax({
url: that.closest('form').data('suggest'),
dataType: 'json',
dataType: 'jsonp',
jsonp: 'tx_solr[callback]',
data: {
termLowercase: that.val().toLowerCase(),
termOriginal: that.val(),
L: that.closest('form').find('input[name="L"]').val()
tx_solr: {
queryString: that.val().toLowerCase()
}
},
success: function (data) {
var suggestions = data.suggestions || []

req = false
var arrr = []
$.each(data, function (term) {
$.each(suggestions, function (term) {
arrr.push(term)
})
mainSearchInputList['searchItem' + index]._list = arrr
Expand Down
14 changes: 9 additions & 5 deletions Resources/Public/less/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ var mainSearchInputList = {}
autoFirst: true
})
var req = false

$(this).on('keyup.search.suggest', function (e) {
var c = e.keyCode
if (c === 13 || c === 27 || c === 38 || c === 40) {
Expand All @@ -716,16 +717,19 @@ var mainSearchInputList = {}
req = true
$.ajax({
url: that.closest('form').data('suggest'),
dataType: 'json',
dataType: 'jsonp',
jsonp: 'tx_solr[callback]',
data: {
termLowercase: that.val().toLowerCase(),
termOriginal: that.val(),
L: that.closest('form').find('input[name="L"]').val()
tx_solr: {
queryString: that.val().toLowerCase()
}
},
success: function (data) {
var suggestions = data.suggestions || []

req = false
var arrr = []
$.each(data, function (term) {
$.each(suggestions, function (term) {
arrr.push(term)
})
mainSearchInputList['searchItem' + index]._list = arrr
Expand Down
Loading

0 comments on commit e8ee00d

Please sign in to comment.