Commit 1ae81f4d authored by pestov's avatar pestov
Browse files

Add Ganzes Wort search option

parent 1b5dc88f
Pipeline #296318 passed with stages
in 13 minutes
......@@ -10,7 +10,7 @@ class Search {
let queryArr = [];
Object.keys(entries).forEach(key => {
let index = key.match(/\d+/g)?.[0];
let attribute = key.match(/field|operator|value/g)?.[0];
let attribute = key.match(/field|operator|value|phrase/g)?.[0];
const value = entries[key];
if (index === undefined && !attribute) {
......@@ -24,6 +24,7 @@ class Search {
operator: '',
field: '',
value: '',
phrase: ''
})
}
......@@ -40,7 +41,8 @@ class Search {
queryArr = [{
operator: '',
field: '',
value: ''
value: '',
phrase: ''
}];
}
......@@ -93,13 +95,15 @@ class Search {
return this.getTextField(data);
} else if (type === 'select') {
return this.getSelectField(data);
} else if (type === 'switch') {
return this.getSwitchField(data);
} else if (type === 'remove') {
return this.getRemoveButton(data);
}
}).join('');
this.appendTemplate(
`<div class="search-field-group input-group align-items-center mb-2">${fields}</div>`
`<div class="search-field-group input-group mb-2">${fields}</div>`
);
this.lastFieldGroupIndex++;
......@@ -107,8 +111,8 @@ class Search {
getRemoveButton({disabled}) {
return `<button type="button" class="btn btn-close ms-2 ${disabled ? 'disabled invisible' : ''}" aria-label="Close"
onclick="this.parentElement.parentElement.removeChild(this.parentElement)">
return `<button type="button" class="remove-button btn btn-outline-primary ms-2 mt-auto ${disabled ? 'disabled invisible' : ''}" aria-label="Close"
onclick="this.parentElement.parentElement.removeChild(this.parentElement)">Entfernen
</button>`;
}
......@@ -130,6 +134,13 @@ class Search {
</div>`;
}
getSwitchField({name, label, checked}) {
return `<div class="d-flex flex-column flex-grow-0 flex-shrink-0 ms-2 form-switch">
<label class="small fw-bold">${label}</label>
<input class="form-check-input" role="switch" type="checkbox" ${checked ? 'checked' : ''} name="${name}">
</div>`
}
convertToElement(template) {
const wrapper = document.createElement('div');
wrapper.innerHTML = template;
......@@ -148,7 +159,8 @@ class Search {
getFieldGroupData(index, query = {
operator: '',
field: '',
value: ''
value: '',
phrase: ''
}) {
const operatorQuery = query['operator'];
......@@ -197,6 +209,14 @@ class Search {
value: valueQuery
};
const phraseQuery = query['phrase'];
const wholeWordData = {
type: 'switch',
name: `q[${index}][phrase]`,
label: 'Ganzes Wort',
checked: phraseQuery === 'on'
}
const removeButtonData = {
type: 'remove',
disabled: index === 0,
......@@ -206,6 +226,7 @@ class Search {
operatorData,
fieldData,
valueData,
wholeWordData,
removeButtonData
];
}
......
.search-field-group {
&:not(:first-child) {
label {
display: none;
visibility: hidden;
height: 0;
}
}
label {
padding-left: 0.75rem;
margin-bottom: 0.2rem;
}
input[type=checkbox] {
margin-left: 0.75rem;
margin-top: 0.75rem;
}
.form-switch {
padding: 0;
}
.remove-button {
border-radius: 4px !important;
}
}
......@@ -263,6 +263,7 @@ class SolrSearchService implements SearchServiceInterface
$operator = $queryItem['operator'] ?? null;
$field = $queryItem['field'] ?? null;
$value = $queryItem['value'] ?? null;
$phrase = $queryItem['phrase'] ?? null;
if (isset($operator) && !empty($operator) && $operator !== 'none') {
if ($operator === 'NOT') {
......@@ -278,7 +279,11 @@ class SolrSearchService implements SearchServiceInterface
if ($value === '' || $value === '*') {
$value = '*';
} else {
$value = $containsSpecialChars > 0 ? $value : "*$value*";
$isPhrase = isset($phrase) && $phrase === 'on';
$valueTemp = $isPhrase ? '"' : '';
$valueTemp .= $containsSpecialChars > 0 || $isPhrase ? $value : "*$value*";
$valueTemp .= $isPhrase ? '"' : '';
$value = $valueTemp;
}
$queryString .= "$field:$value";
}
......@@ -287,7 +292,7 @@ class SolrSearchService implements SearchServiceInterface
$queryString .= ')';
}
}
$queryString .= ' AND doctype:article';
$select->setQuery($queryString);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment