<?xml version="1.0" encoding="UTF-8" ?>
<!--
 Solr Schema for StoryCove Authors Core
 Based on AuthorSearchDto data model
-->
<schema name="storycove-authors" version="1.6">

  <!-- Field Types -->

  <!-- String field type for exact matching -->
  <fieldType name="string" class="solr.StrField" sortMissingLast="true" />

  <!-- Text field type for full-text search -->
  <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
      <filter class="solr.SynonymGraphFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>

  <!-- Enhanced text field for names -->
  <fieldType name="text_enhanced" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="15"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>

  <!-- Integer field type -->
  <fieldType name="pint" class="solr.IntPointField" docValues="true"/>

  <!-- Long field type -->
  <fieldType name="plong" class="solr.LongPointField" docValues="true"/>

  <!-- Double field type -->
  <fieldType name="pdouble" class="solr.DoublePointField" docValues="true"/>

  <!-- Date field type -->
  <fieldType name="pdate" class="solr.DatePointField" docValues="true"/>

  <!-- Multi-valued string for URLs -->
  <fieldType name="strings" class="solr.StrField" sortMissingLast="true" multiValued="true"/>

  <!-- Random sort field type for random ordering -->
  <fieldType name="random" class="solr.RandomSortField" indexed="true"/>

  <!-- Fields -->

  <!-- Required Fields -->
  <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
  <field name="_version_" type="plong" indexed="false" stored="false"/>

  <!-- Core Author Fields -->
  <field name="name" type="text_enhanced" indexed="true" stored="true" required="true"/>
  <field name="notes" type="text_general" indexed="true" stored="true"/>
  <field name="authorRating" type="pint" indexed="true" stored="true"/>
  <field name="averageStoryRating" type="pdouble" indexed="true" stored="true"/>
  <field name="storyCount" type="pint" indexed="true" stored="true"/>
  <field name="urls" type="strings" indexed="true" stored="true"/>
  <field name="avatarImagePath" type="string" indexed="false" stored="true"/>

  <!-- Multi-tenant Library Separation -->
  <field name="libraryId" type="string" indexed="true" stored="true" required="false" default="default"/>

  <!-- Timestamp Fields -->
  <field name="createdAt" type="pdate" indexed="true" stored="true"/>
  <field name="updatedAt" type="pdate" indexed="true" stored="true"/>

  <!-- Search-specific Fields -->
  <field name="searchScore" type="plong" indexed="false" stored="true"/>

  <!-- Combined search field for general queries -->
  <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

  <!-- Copy Fields for comprehensive search -->
  <copyField source="name" dest="text"/>
  <copyField source="notes" dest="text"/>
  <copyField source="urls" dest="text"/>

  <!-- Default Search Field -->

  <!-- Dynamic Fields -->

  <!-- Random sort dynamic field for generating random orderings -->
  <dynamicField name="random_*" type="random" indexed="true" stored="false"/>

  <!-- UniqueKey -->
  <uniqueKey>id</uniqueKey>

</schema>