Skip to content

Conversation

@gaborbernat
Copy link
Contributor

@gaborbernat gaborbernat commented Oct 2, 2025

Fixes #4740

@oracle-contributor-agreement
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Oct 2, 2025
@vladak
Copy link
Member

vladak commented Oct 14, 2025

The Apirary documentation in the apiary.apib file needs update for the /search endpoint.

@vladak
Copy link
Member

vladak commented Oct 14, 2025

Also, needs a test case.

@vladak
Copy link
Member

vladak commented Oct 14, 2025

Just a note: this conflicts with the changes done for Lucene 9.x update in PR #4867. It looks like this can be reconciled easily, though.

@gaborbernat
Copy link
Contributor Author

I signed the OCA on Friday any idea when it will be approved?

@gaborbernat gaborbernat force-pushed the 4740-feat branch 10 times, most recently from 41ef174 to db9f5fa Compare October 16, 2025 02:39
@gaborbernat gaborbernat requested a review from vladak October 16, 2025 02:39
@gaborbernat gaborbernat force-pushed the 4740-feat branch 3 times, most recently from 35d7af4 to 8fd284e Compare October 16, 2025 14:25
@oracle-contributor-agreement
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Oct 16, 2025
@gaborbernat
Copy link
Contributor Author

@vladak when you can please take another look, thanks!

@vladak
Copy link
Member

vladak commented Oct 21, 2025

@vladak when you can please take another look, thanks!

The failing tests need to be fixed first.

Signed-off-by: Bernát Gábor <[email protected]>
Signed-off-by: Bernát Gábor <[email protected]>
Signed-off-by: Bernát Gábor <[email protected]>
@gaborbernat
Copy link
Contributor Author

@vladak can you take another look please? Thanks!

@vladak
Copy link
Member

vladak commented Nov 14, 2025

In general this looks good; I will go through the test code in a little bit more detail before approving, though.

In the meantime you might want to add copyrights to the changed files.

repository.create(HistoryGuru.class.getResource("/repositories"));
URL url = HistoryGuru.class.getResource("/repositories");
repository.createEmpty();
repository.copyDirectoryWithUniqueModifiedTime(Path.of(url.toURI()), Path.of(repository.getSourceRoot()));
Copy link
Member

Choose a reason for hiding this comment

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

Please add assertNotNull for the url before the toURI() conversion like it is done in some other test classes to avoid code smells reported e.g. by SonarQube.

int hitsCount = instance.search();
List<Hit> hits = new ArrayList<>();
instance.results(0, hitsCount, hits);
assertTrue(hits.size() > 1, "Should return at least 2 hits for RELEVANCY sort to check order");
Copy link
Member

Choose a reason for hiding this comment

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

Why not check the exact count ? If count is different than the array length, it does not make sense to proceed with comparison.

Comment on lines +170 to +173
List<String> results = new ArrayList<>();
for (Hit hit : hits) {
results.add(hit.getPath() + "@" + hit.getLineno());
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer something like this over iterating:

        String[] results = hits.stream().
                map(hit -> hit.getPath() + "@" + hit.getLineno()).
                toArray(String[]::new);

Then for the assertArrayEquals call below toArray is not necessary.

Comment on lines +199 to +202
List<String> results = new ArrayList<>();
for (Hit hit : hits) {
results.add(hit.getPath() + "@" + hit.getLineno());
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

int hitsCount = instance.search();
List<Hit> hits = new ArrayList<>();
instance.results(0, hitsCount, hits);
assertTrue(hits.size() > 1, "Should return at least 2 hits for RELEVANCY sort to check order");
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@DefaultValue(MAX_RESULTS + "") final int maxResults,
@QueryParam(QueryParameters.START_PARAM) @DefaultValue(0 + "") final int startDocIndex
@QueryParam(QueryParameters.START_PARAM) @DefaultValue(0 + "") final int startDocIndex,
@QueryParam(QueryParameters.SORT_PARAM) @DefaultValue(DEFAULT_SORT_ORDER) final String sort
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add a test that ensures the default sort order (perhaps it would be sufficient to call just getSortOrder() on default SearchEngine construction and check its value rather than having a full blown test that checks the data returned from search which might change across Lucene upgrades)

Files.setLastModifiedTime(destPath, fileTime);
Files.setAttribute(destPath, "basic:creationTime", fileTime);
} catch (Exception ignored) {
// Not all filesystems support creationTime
Copy link
Member

Choose a reason for hiding this comment

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

Is the creation time necessary for the SearchEngine tests or for tests in general ? Also, I'd prefer having any exceptions from the last modified time to be propagated because otherwise some of the tests would fail anyway and it would not be clear why.

Comment on lines +144 to +146
// Create a deterministic order of paths for creation time, so last modified time indexing is stable in tests
// note we cannot use Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES)
// as the original creation time is the user checkout and not different accross files
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps move this comment to the method's javadoc so that it becomes more clear what it does.

Copy link
Member

Choose a reason for hiding this comment

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

Also, there is a typo in "accross".

allPaths = stream.filter(p -> !p.equals(src)).sorted().toList();
}
// Set base time to now, and go ahead in time for each subsequent path by 1 minute
java.time.Instant baseTime = java.time.Instant.now();
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to import java.time.Instant; and then use the Instant standalone.

Path sourcePath = allPaths.get(i);
Path destRelativePath = getDestinationRelativePath(src, sourcePath);
Path destPath = dest.resolve(destRelativePath);
var fileTime = java.nio.file.attribute.FileTime.from(baseTime.plusSeconds(i * 60L));
Copy link
Member

Choose a reason for hiding this comment

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

ditto for the java.nio.file.attribute.FileTime import.

} else {
// Ensure parent directory exists before copying file
Path parentDir = destPath.getParent();
if (parentDir != null && !Files.exists(parentDir)) {
Copy link
Member

Choose a reason for hiding this comment

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

no need to check whether the destination exists for Files.createDirectories().

Also, I am pretty sure @ginoaugustine would come with a way how to use Optional for this nullable variable.

public static final String PATH = "search";

private static final int MAX_RESULTS = 1000;
private static final String DEFAULT_SORT_ORDER = "relevancy";
Copy link
Member

Choose a reason for hiding this comment

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

should probably say this needs to be equal to SortOrder.RELEVANCY.name. Maybe add a test for it.

Cannot use it directly as as @DefaultValue needs a constant and besides the name field is currently private.

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

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search API allow sort by path

2 participants