Add additional help to quick search and an advanced search documentation page (#1757)

Co-authored-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com>
This commit is contained in:
Konstantin Schaper
2021-08-09 12:07:28 +02:00
committed by GitHub
parent f2249cea73
commit ddd2fc1055
43 changed files with 1494 additions and 94 deletions

View File

@@ -0,0 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
export default `Unsere Suche basiert auf Lucene. Sie können die [vollständige Syntax](http://lucene.apache.org/core/8_9_0/index.html) nutzen.
Um mehr über die fortgeschrittene Suche zu erfahren, lesen sie unsere [Expertenseite](/help/search-syntax).
### Einfache Suche
- Die relevantesten Repositories werden in den Quick Results angezeigt.
- Über die Eingabe-Taste oder den Button "Alle Ergebnisse anzeigen" bekommen Sie Ergebnisse aller durchsuchten Entitäten wie Nutzern oder Gruppen.
- Eine Wildcard für eine beliebige Anzahl an beliebigen Zeichen wird Ihrer Suche standardmäßig angehängt.
- Geben Sie keine Wildcards vor dem Suchbegriff ein!`;

View File

@@ -0,0 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
export default `Our search uses Lucene and you may use the [full syntax](http://lucene.apache.org/core/8_9_0/index.html).
To learn about advanced search read our [Expert Search Site](/help/search-syntax).
### Basic Search
- The most relevant repositories are shown in the quick results.
- Press "enter" or click the "Show all results" button to find more results for all entities like users or groups.
- A multi-character wildcard (*) is added to your search by default.
- Do not enter Wildcards in front of the search!`;

View File

@@ -0,0 +1,148 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
export default `## Modifikatoren
Hinweis: Sie können keine Wildcards als erstes Zeichen einer Suche verwenden.
<table>
<tr>
<th>Definition</th>
<th>Beispiel</th>
</tr>
<tr>
<td>? - Einzelzeichen-Wildcard</td>
<td>Ultimate?Repo - findet z.B. Ultimate-Repo, Ultimate Repo, Ultimate+Repo</td>
</tr>
<tr>
<td>* - mehrstelliger Platzhalter</td>
<td>Ultimat*y - findet z.B. Ultimate Repository, Ultimates-Spezial-Repository, Ultimate</td>
</tr>
</table>
### Bereiche
Bereichsabfragen ermöglichen den Abgleich von Dokumenten, deren Feldwerte zwischen der unteren und der oberen Grenze liegen, die in der Bereichsabfrage angegeben sind. Bereichsabfragen können die obere und untere Grenze einschließen oder ausschließen. Die Sortierung erfolgt lexikografisch.
Bereiche sind nicht auf numerische Felder beschränkt.
<table>
<tr>
<th>Definition</th>
<th>Beispiel</th>
</tr>
<tr>
<td>[ … TO … ] - inklusiver Bereich</td>
<td>creationDate:[1609459200000 TO 1612137600000] findet z.B. Repositories, die zwischen dem 01.01.2021 und dem 01.02.2021 angelegt wurden.</td>
</tr>
<tr>
<td>{… TO …} - ausschließender Bereich</td>
<td>name:{Aida TO Carmen} findet Namen zwischen Aida und Carmen, jedoch ohne die beiden Namen einzuschließen.</td>
</tr>
</table>
## Boosten
Mit dem Boosting können Sie die Relevanz eines Dokuments steuern, indem Sie seinen Term verstärken.
<table>
<tr>
<th>Definition</th>
<th>Beispiel</th>
</tr>
<tr>
<td>term^Zahl</td>
<td>ultimate^2 repository erhöht die Relevanz von „ultimate"</td>
</tr>
</table>
Standardmäßig ist der Boost-Faktor 1. Obwohl der Boost-Faktor positiv sein muss, kann er kleiner als 1 sein (z. B. 0,2)
Standardmäßig werden Repository-Namen um 1,5 und Namespace-Namen um 1,25 geboostet.
## Boolesche Operatoren
Hinweis: Logische Operatoren müssen in Großbuchstaben eingegeben werden (z. B. „AND").
<table>
<tr>
<th>Definition</th>
<th>Beispiel</th>
</tr>
<tr>
<td>AND beide Terme müssen enthalten sein</td>
<td>Ultimate AND Repository findet z.B. Ultimate Repository, Ultimate Special Repository
</td>
</tr>
<tr>
<td>OR mindestens einer der Terme muss enthalten sein</td>
<td>Ultimate OR Repository findet z.B.. Ultimate Repository, Ultimate User, Special Repository</td>
</tr>
<tr>
<td>NOT der nachfolgende Term darf nicht enthalten sein. „!" kann alternativ verwendet werden.</td>
<td>Ultimate NOT Repository findet z.B.. Ultimate user, nicht jedoch z.B. Ultimate Repository</td>
</tr>
<tr>
<td> schließt den folgenden Term von der Suche aus</td>
<td>Ultimate Repository -Special findet z.B. Ultimate Repository, schließt z.B. Ultimate Special Repository aus</td>
</tr>
<tr>
<td> der folgende Term muss enthalten sein</td>
<td>Ultimate +Repository findet z.B. my Repository, Ultimate Repository</td>
</tr>
</table>
## Gruppieren
Die Suche unterstützt die Verwendung von Klammern zur Gruppierung von Begriffen, um Teilabfragen zu bilden. Dies kann sehr nützlich sein, wenn Sie die boolesche Logik für eine Abfrage steuern möchten.
<table>
<tr>
<th>Definition</th>
<th>Beispiel</th>
</tr>
<tr>
<td>() Terme zwischen den Klammern werden gruppiert</td>
<td>(Ultimate OR my) AND Repository findet z.B.. Ultimate Repository, my Repository, schließt z.B. Super Repository. Entweder "Ultimate" oder “My” müssen im Ergebnis existieren, “Repository” muss immer enthalten sein.
</td>
</tr>
</table>
## Umgang mit Sonderzeichen
Die Suche unterstützt Sonderzeichen, die Teil der Abfragesyntax sind. Die aktuellen Sonderzeichen der Liste sind
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \\ /
Um diese Zeichen zu nutzen, verwenden Sie das „\\" vor dem jeweiligen Zeichen. Um zum Beispiel nach (1+1):2 zu suchen, verwenden Sie diese Abfrage:
\\(1\\+1\\)\\:2
Partiell übersetzt mit www.DeepL.com/Translator (kostenlose Version)
Quelle [https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description](https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description)`;

View File

@@ -0,0 +1,145 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
export default `### Modifiers
Note: You can not use wildcards as the first character of a search.
<table>
<tr>
<th>Definition</th>
<th>Example</th>
</tr>
<tr>
<td>? - single character Wildcard</td>
<td>Ultimate?Repo finds e.g. Ultimate-Repo, Ultimate Repo, Ultimate+Repo</td>
</tr>
<tr>
<td>* - multiple character Wildcard</td>
<td>Ultimat*y - finds e.g. Ultimate Repository, Ultimate-Special-Repository, Ultimately</td>
</tr>
</table>
### Ranges
Range Queries allow one to match documents whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexicographically.
Ranges are not reserved to numerical fields.
<table>
<tr>
<th>Definition</th>
<th>Example</th>
</tr>
<tr>
<td>[ … TO … ] - inclusive range</td>
<td>creationDate:[1609459200000 TO 1612137600000] finds e.G. repositories created between 2021-01-01 and 2021-02-01 </td>
</tr>
<tr>
<td>{… TO …} - exclusive range</td>
<td>name:{Aida TO Carmen} finds e.G. repositories with names between Aida and Carmen, excluding these to values.</td>
</tr>
</table>
### Boosting
Boosting allows you to control the relevance of a document by boosting its term.
<table>
<tr>
<th>Definition</th>
<th>Example</th>
</tr>
<tr>
<td>term^number</td>
<td>ultimate^2 repository makes the term "ultimate" more relevant. </td>
</tr>
</table>
By default, the boost factor is 1. Although the boost factor must be positive, it can be less than 1 (e.g. 0.2)
By default Repository names are boosted by 1.5, namespace by 1.25.
## Boolean Operators
Note: Logical Operators must be entered in upper case (e.g. "AND").
<table>
<tr>
<th>Definition</th>
<th>Example</th>
</tr>
<tr>
<td>AND both terms must be included</td>
<td>Ultimate AND Repository finds e.g. Ultimate Repository, Ultimate Special Repository</td>
</tr>
<tr>
<td>OR at least one of the terms must be included</td>
<td>Ultimate OR Repository finds e.g. Ultimate Repository, Ultimate User, Special Repository</td>
</tr>
<tr>
<td>NOT following term may not be included, "!" may be used alternatively</td>
<td>Ultimate NOT Repository finds e.g. Ultimate user, excludes e.g. Ultimate Repository</td>
</tr>
<tr>
<td> excludes following term from search</td>
<td>Ultimate Repository -Special finds e.g. Ultimate Repository, excludes e.g. Ultimate Special Repository</td>
</tr>
<tr>
<td> following term must be included</td>
<td>Ultimate +Repository finds e.g. my Repository, Ultimate Repository</td>
</tr>
</table>
## Grouping
Search supports using parentheses to group clauses to form sub queries. This can be very useful if you want to control the boolean logic for a query.
<table>
<tr>
<th>Definition</th>
<th>Example</th>
</tr>
<tr>
<td>() terms inside parentheses are grouped together</td>
<td>(Ultimate OR my) AND Repository finds e.g. Ultimate Repository, my Repository, excludes e.g. Super Repository. Either "Ultimate" or “My” must exist, “Repository” must always exist.
</td>
</tr>
</table>
## Escaping Special Characters
The search supports escaping special characters that are part of the query syntax. The current list special characters are
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \\ /
To escape these characters use the "\\" before the character. For example to search for (1+1):2 use the query:
\\(1\\+1\\)\\:2
Source: [https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description](https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description)`;

View File

@@ -23,6 +23,7 @@
*/
import * as urls from "./urls";
export { urls };
export * from "./errors";

View File

@@ -22,11 +22,12 @@
* SOFTWARE.
*/
import { ApiResult, useIndexLinks } from "./base";
import { Link, QueryResult } from "@scm-manager/ui-types";
import { ApiResult, useIndexJsonResource, useIndexLinks } from "./base";
import { Link, QueryResult, SearchableType } from "@scm-manager/ui-types";
import { apiClient } from "./apiclient";
import { createQueryString } from "./utils";
import { useQueries, useQuery } from "react-query";
import { useEffect, useState } from "react";
export type SearchOptions = {
type: string;
@@ -46,6 +47,8 @@ export const useSearchTypes = () => {
.filter(isString);
};
export const useSearchableTypes = () => useIndexJsonResource<SearchableType[]>("searchableTypes");
export const useSearchCounts = (types: string[], query: string) => {
const searchLinks = useSearchLinks();
const queries = useQueries(
@@ -113,3 +116,31 @@ export const useSearch = (query: string, optionParam = defaultSearchOptions): Ap
}
);
};
const useObserveAsync = <D extends any[], R, E = Error>(fn: (...args: D) => Promise<R>, deps: D) => {
const [data, setData] = useState<R>();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<E>();
useEffect(() => {
setLoading(true);
fn(...deps)
.then(setData)
.catch(setError)
.finally(() => setLoading(false));
}, deps);
return { data, isLoading, error };
};
const supportedLanguages = ["de", "en"];
const pickLang = (language: string) => {
if (!supportedLanguages.includes(language)) {
return "en";
}
return language;
};
export const useSearchHelpContent = (language: string) =>
useObserveAsync((lang) => import(`./help/search/modal.${pickLang(lang)}`).then((module) => module.default), [language]);
export const useSearchSyntaxContent = (language: string) =>
useObserveAsync((lang) => import(`./help/search/syntax.${pickLang(lang)}`).then((module) => module.default), [language]);