Skip to content

Lut 32413 : Sorting issue in FormResponse Lists#635

Closed
rkaabeche wants to merge 1 commit into
lutece-platform:develop_core7from
rkaabeche:LUT-32413-sort-issue-in-list
Closed

Lut 32413 : Sorting issue in FormResponse Lists#635
rkaabeche wants to merge 1 commit into
lutece-platform:develop_core7from
rkaabeche:LUT-32413-sort-issue-in-list

Conversation

@rkaabeche

@rkaabeche rkaabeche commented Jul 8, 2026

Copy link
Copy Markdown

Add sorting for String fields with dynamic indexes in the form response view

@rkaabeche
rkaabeche force-pushed the LUT-32413-sort-issue-in-list branch 7 times, most recently from f513800 to f7a1e5c Compare July 10, 2026 14:26

@lobtx lobtx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your PR is great, I just required some code improvements that are not linked to the US

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use strAttributeName here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -261,11 +262,11 @@ private Sort buildLuceneSort( FormItemSortConfig sortConfig )
return new Sort( new SortedNumericSortField( sortConfig.getSortAttributeName( ), SortField.Type.LONG, sortConfig.isAscSort( ) ) );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use strAttributeName here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate return new Sort( new SortedNumericSortField( sortConfig.getSortAttributeName( ), SortField.Type.LONG, sortConfig.isAscSort( ) ) ); in both cases. Not in the scope of the US but could be great to unify conditions with an OR operator

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with SortField.Type.INT for better consistency with the field type

{
doc.add( new StringField( fieldNameBuilder.toString( ) + FormResponseSearchItem.FIELD_SELECT_SUFFIX, response.getResponseValue( ), Field.Store.YES ) );
doc.add( new SortedDocValuesField( fieldNameBuilder.toString( ) + FormResponseSearchItem.FIELD_SELECT_SUFFIX, new BytesRef( response.getResponseValue( ) ) ) );
String sortIndexList = LuceneUtils.createLuceneEntryKey( strQuestionCode, response.getIterationNumber( ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line throws IllegalArgumentException: DocValuesField "entry_code__iter_0" appears more than once in this document whenever a checkbox question has more than one option ticked (or any multi-valued question at the same iterationNumber).

In that case getEntryResponse() returns several Response objects sharing the same question code and the same iterationNumber. Since sortIndexList (line 791) is built from createLuceneEntryKey(code, iteration) without the field discriminant, each of those responses adds a SortedDocValuesField under the same field name to the same document — which Lucene forbids for a single-valued docvalues field.

As a result the document is never indexed: the form indexer daemon fails on every run and the response stays permanently unindexed (invisible in the multiview / search).

Fix suggestion: add the sort docvalue only once per sortIndexList key (dedup, e.g. a Set guard), or switch to a SortedSetDocValuesField if multi-value sorting is required.

sample:

near line 730

 // Sort docvalues key is built without the field discriminant : a multi-valued
  // response (e.g. checkbox with several options ticked) would add several
  // SortedDocValuesField under the same name, which Lucene forbids. Keep only
   // the first value per sort key.
     Set<String> setSortListFieldUsed = new HashSet<>( );

near line 792

 String sortIndexList = LuceneUtils.createLuceneEntryKey( strQuestionCode, response.getIterationNumber( ) );
                                        if ( setSortListFieldUsed.add( sortIndexList ) )
                                        {
                                            doc.add( new SortedDocValuesField( sortIndexList, new BytesRef( response.getResponseValue( ) ) ) );
                                        }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review, I hadn't thought of that case.

The change you suggested has been made.

@rkaabeche
rkaabeche force-pushed the LUT-32413-sort-issue-in-list branch from b5c85ac to 481b0e0 Compare July 17, 2026 14:16
LUT-32413 : Create sort utils and add unit tests

LUT-32413 : unit tests correction

LUT-32413 : Adding correct index to form numbers + new sort for string

LUT-32413 : pr review

LUT-32413 : pr review

LUT-32413 : Indexation Sort
@rkaabeche
rkaabeche force-pushed the LUT-32413-sort-issue-in-list branch from 5b5cc58 to 281fcea Compare July 22, 2026 14:58
@rkaabeche rkaabeche closed this Jul 22, 2026
@lobtx

lobtx commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

replaced by #642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants