> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Solr MoreLikeThis Stage

export const schema = {
  "type": "object",
  "title": "Solr MoreLikeThis",
  "description": "Returns results similar to a given item using Solr's MoreLikeThis component. Provide parameters for the component here. For more information, see https://cwiki.apache.org/confluence/display/solr/MoreLikeThis",
  "required": ["useQueryParser"],
  "properties": {
    "skip": {
      "type": "boolean",
      "title": "Skip This Stage",
      "description": "Set to true to skip this stage.",
      "default": false,
      "hints": ["advanced"]
    },
    "label": {
      "type": "string",
      "title": "Label",
      "description": "A unique label for this stage.",
      "hints": ["advanced"],
      "maxLength": 255
    },
    "condition": {
      "type": "string",
      "title": "Condition",
      "description": "Define a conditional script that must result in true or false. This can be used to determine if the stage should process or not.",
      "hints": ["code", "code/javascript", "advanced"]
    },
    "useQueryParser": {
      "type": "boolean",
      "title": "Use Query Parser",
      "description": "Specifies whether to use the MLT Query Parser. Note, if you choose to use this you MUST specify a document id to run the MLT Query on and a Field to run the MLT with.",
      "default": true
    },
    "moreLikeThisFields": {
      "type": "array",
      "title": "More Like This Fields",
      "description": "Specifies the name of the field you want to run the mlt on. NOTE: If you don't supply any fields we will default to using the body field.",
      "items": {
        "type": "string"
      }
    },
    "docId": {
      "type": "string",
      "title": "DocId Field name",
      "description": "Specifies the name of the id field we are finding more like this terms on",
      "default": "id"
    },
    "mindf": {
      "type": "integer",
      "title": "mindf",
      "description": "Specify the frequency at which words will be ignored which occur in at least this many docs",
      "default": 2
    },
    "maxdf": {
      "type": "integer",
      "title": "maxdf",
      "description": "Specify the frequency at which words will be ignored which occur in more than this many docs",
      "default": 10000
    },
    "count": {
      "type": "integer",
      "title": "Count",
      "description": "Specifies the number of similar documents to be returned for each result."
    },
    "mintf": {
      "type": "integer",
      "title": "mintf",
      "description": "Specify the frequency below which terms will be ignored in the source doc"
    },
    "minwl": {
      "type": "integer",
      "title": "minwl",
      "description": "Sets the minimum word length for words to be recognized by the MoreLikeThis",
      "default": 3
    },
    "maxwl": {
      "type": "integer",
      "title": "maxwl",
      "description": "Sets the maximum word length"
    },
    "maxqt": {
      "type": "integer",
      "title": "maxqt",
      "description": "Sets the max number of query terms that will be included in any generate query"
    },
    "maxntp": {
      "type": "integer",
      "title": "maxntp",
      "description": "Sets the max number of tokens to parse in each example doc that is not stored with TV support"
    },
    "boost": {
      "type": "boolean",
      "title": "boost",
      "description": "Specifies if the query will be boosted by the interesting term relevant"
    },
    "matchInclude": {
      "type": "boolean",
      "title": "match include",
      "description": "Specifies whether the response should include the matched doc"
    },
    "matchOffset": {
      "type": "integer",
      "title": "match offset",
      "description": "Specifies an offset to the main query to find the doc on which the MoreLikeThis query should operate. By default it is 0"
    },
    "interestingTerms": {
      "type": "string",
      "title": "interesting terms",
      "description": "Controls how the More Like This component presents the interesting terms. Supports 3 settings, list lists the terms, none lists no terms and details lists the terms with the boosts",
      "enum": ["list", "none", "details"]
    }
  },
  "category": "Results Relevancy",
  "categoryPriority": 6,
  "unsafe": false
};

export const SchemaParamFields = ({schema}) => {
  const sanitize = str => {
    if (typeof str !== "string") return str;
    return str.replace(/^"(.*)"$/s, "$1").replace(/\\/g, "").replace(/"/g, "'");
  };
  const formatDescription = str => {
    const s = sanitize(str);
    return (/[.!?]\)*$/).test(s) ? s : `${s}.`;
  };
  const {description, properties = {}, required: requiredProps = []} = schema;
  const visibleProps = useMemo(() => Object.entries(properties).filter(([, prop]) => !prop.hints?.includes("hidden")), [properties]);
  return <div>
      {description && <p>{formatDescription(description)}</p>}

      {visibleProps.map(([name, prop]) => {
    const isRequired = requiredProps.includes(name);
    const hasDefault = prop.default !== undefined;
    const rawDefault = prop.default;
    const isComplexDefault = hasDefault && (typeof rawDefault === "object" || typeof rawDefault === "string" && (rawDefault.length > 20 || rawDefault.includes('"')));
    const fieldProps = {
      key: name,
      body: prop.title || name,
      type: prop.type,
      ...prop.title && ({
        post: [<><span className="text-stone-400 dark:text-stone-500">API property: </span>{name}</>]
      }),
      ...isRequired && ({
        required: true
      }),
      ...!isComplexDefault && hasDefault ? {
        default: sanitize(String(rawDefault))
      } : {}
    };
    const isObject = prop.type === "object" && prop.properties;
    const isArrayOfObjects = prop.type === "array" && prop.items?.type === "object" && prop.items.properties;
    return <ParamField {...fieldProps}>
            {prop.description && <p>{formatDescription(prop.description)}</p>}

            {isComplexDefault && <div className="flex">
                <p>
                  <strong>Default:</strong>
                </p>
                <pre className="!my-0">
                  <code>
                    {JSON.stringify(rawDefault, null, 2)}
                  </code>
                </pre>
              </div>}

            {isArrayOfObjects && <div className="flex">
              <p>
                <strong>Object attributes:</strong>
              </p>
              <pre className="!my-0">
                <code>
                  {'{\n'}
                  {Object.entries(prop.items.properties).map(([iname, iprop]) => <>
                      {`  ${iname}`}
                      {prop.items?.required?.includes(iname) && <span style={{
      color: 'red'
    }}> required</span>}
                      {`: {\n    display name: ${sanitize(iprop.title || '')}\n    type: ${iprop.type}\n  }\n`}
                    </>)}
                  {'}'}
                </code>
              </pre>
              </div>}

            {isObject && <Expandable title="properties">
                <SchemaParamFields schema={{
      properties: prop.properties,
      required: prop.required
    }} />
              </Expandable>}
          </ParamField>;
  })}
    </div>;
};

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/4/fusion-server/reference/pipeline-stages/query/solr-more-like-this-query-stage

[mintlify link]: https://doc.lucidworks.com/docs/4/fusion-server/reference/pipeline-stages/query/solr-more-like-this-query-stage

[old doc.lw link]: https://doc.lucidworks.com/fusion-server/4.2/256

This stage uses the content of the current document to query for similar documents, using [Solr’s MoreLikeThis component](https://solr.apache.org/guide/solr/latest/query-guide/morelikethis.html).

This stage provides content-based recommendations. For collaborative recommendations, use the [Recommend Items for Item stage](/docs/4/fusion-ai/reference/query-pipeline-stages/recommend-items-for-item-query-stage).

See [Recommendations and Boosting](/docs/4/fusion-ai/concepts/boosting/overview) for more information.

<LwTemplate />

## Tips

* The incoming query must include an `id` field in order to get recommendations from this stage. The stage returns documents similar to the one specified by this field.
* Since these secondary queries tend to be large, this stage can impact search performance. You can improve performance by first [clustering your documents](/docs/4/fusion-ai/reference/jobs/document-clustering), then configuring this stage to query a specific document cluster instead of all documents.

## Configuration

<Tip>
  When entering configuration values in the UI, use *unescaped* characters, such as `\t` for the tab character. When entering configuration values in the API, use *escaped* characters, such as `\\t` for the tab character.
</Tip>

<SchemaParamFields schema={schema} />
