mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-11-03 20:15:52 +01:00 
			
		
		
		
	Refactor Search API and allow analyzer per field (#1755)
The Search api is now simpler, because it provides useful defaults. Only if you want to deviate from the defaults, you can set these values. This is mostly reached by using the builder pattern. Furthermore it is now possible to configure an analyzer per field. The default analyzer is still the one which is derived from the index options, but it is possible to configure a new indexer with the analyzer attribute of the indexed annotation. The attribute allows the configuration for code, identifiers and path. The current implementation uses the same analyzer code, identifiers and path. The new implemented splits tokens on more delimiters as the default analyzer e.g.: dots, underscores etc. Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
		@@ -24,28 +24,37 @@
 | 
			
		||||
 | 
			
		||||
import React, { FC } from "react";
 | 
			
		||||
import { Hit as HitType } from "@scm-manager/ui-types";
 | 
			
		||||
import classNames from "classnames";
 | 
			
		||||
 | 
			
		||||
export type HitProps = {
 | 
			
		||||
  hit: HitType;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type Props = {
 | 
			
		||||
  className?: string;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type SearchResultType = FC & {
 | 
			
		||||
  Title: FC;
 | 
			
		||||
  Left: FC;
 | 
			
		||||
  Content: FC;
 | 
			
		||||
  Right: FC;
 | 
			
		||||
  Title: FC<Props>;
 | 
			
		||||
  Left: FC<Props>;
 | 
			
		||||
  Content: FC<Props>;
 | 
			
		||||
  Right: FC<Props>;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const Hit: SearchResultType = ({ children }) => {
 | 
			
		||||
  return <article className="media p-1">{children}</article>;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Hit.Title = ({ children }) => <h3 className="has-text-weight-bold is-ellipsis-overflow">{children}</h3>;
 | 
			
		||||
Hit.Title = ({ className, children }) => (
 | 
			
		||||
  <h3 className={classNames("has-text-weight-bold is-ellipsis-overflow", className)}>{children}</h3>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
Hit.Left = ({ children }) => <div className="media-left">{children}</div>;
 | 
			
		||||
Hit.Left = ({ className, children }) => <div className={classNames("media-left", className)}>{children}</div>;
 | 
			
		||||
 | 
			
		||||
Hit.Right = ({ children }) => <div className="media-right is-size-7 has-text-right">{children}</div>;
 | 
			
		||||
Hit.Right = ({ className, children }) => (
 | 
			
		||||
  <div className={classNames("media-right is-size-7 has-text-right", className)}>{children}</div>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
Hit.Content = ({ children }) => <div className="media-content">{children}</div>;
 | 
			
		||||
Hit.Content = ({ className, children }) => <div className={classNames("media-content", className)}> {children}</div>;
 | 
			
		||||
 | 
			
		||||
export default Hit;
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,7 @@ import { isHighlightedHitField } from "./fields";
 | 
			
		||||
type Props = {
 | 
			
		||||
  hit: Hit;
 | 
			
		||||
  field: string;
 | 
			
		||||
  truncateValueAt?: number;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type HighlightedTextFieldProps = {
 | 
			
		||||
@@ -48,14 +49,18 @@ const HighlightedTextField: FC<HighlightedTextFieldProps> = ({ field }) => (
 | 
			
		||||
  </>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const TextHitField: FC<Props> = ({ hit, field: fieldName }) => {
 | 
			
		||||
const TextHitField: FC<Props> = ({ hit, field: fieldName, truncateValueAt = 0 }) => {
 | 
			
		||||
  const field = hit.fields[fieldName];
 | 
			
		||||
  if (!field) {
 | 
			
		||||
    return null;
 | 
			
		||||
  } else if (isHighlightedHitField(field)) {
 | 
			
		||||
    return <HighlightedTextField field={field} />;
 | 
			
		||||
  } else {
 | 
			
		||||
    return <>{field.value}</>;
 | 
			
		||||
    let value = field.value;
 | 
			
		||||
    if (typeof value === "string" && truncateValueAt > 0 && value.length > truncateValueAt) {
 | 
			
		||||
      value = value.substring(0, truncateValueAt) + "...";
 | 
			
		||||
    }
 | 
			
		||||
    return <>{value}</>;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user