Skip to content

Commit dfffe44

Browse files
committed
reduce gc pressure
fix
1 parent 70e7e46 commit dfffe44

21 files changed

Lines changed: 494 additions & 802 deletions

src/Infidex.Tests/MovieSearchParityTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,13 @@ public void Search_Star_VerifyGrouping()
329329
var stargirl = records.FirstOrDefault(r => movies[(int)r.DocumentId].Title == "Stargirl");
330330
var stardust = records.FirstOrDefault(r => movies[(int)r.DocumentId].Title == "Stardust");
331331

332-
if (starKid == default(ScoreEntry)) Console.WriteLine("MISSING: Star Kid");
333-
if (stardom == default(ScoreEntry)) Console.WriteLine("MISSING: Stardom");
332+
if (starKid.DocumentId == 0 && starKid.Score == 0 && movies[0].Title != "Star Kid") Console.WriteLine("MISSING: Star Kid");
333+
if (stardom.DocumentId == 0 && stardom.Score == 0 && movies[0].Title != "Stardom") Console.WriteLine("MISSING: Stardom");
334334

335335
// Verify we found the key documents
336-
// Note: ScoreEntry is a struct, so default is mostly zeros. We check DocumentId is not 0 (assuming 0 is not Star Kid/Stardom, which is safe given 40k movies)
337-
// Or safer: check if we found them by checking ID against list if we had map, but here we rely on FirstOrDefault logic
338-
// Better check:
339-
bool foundStarKid = starKid.Score > 0 || (starKid.DocumentId == 0 && movies[0].Title == "Star Kid");
336+
// Since ScoreEntry is a struct, default value has DocumentId=0 and Score=0.
337+
// We check if Score > 0 to confirm it was found (assuming no valid result has score 0).
338+
bool foundStarKid = starKid.Score > 0 || (starKid.DocumentId == 0 && movies[0].Title == "Star Kid" && starKid.Score > 0);
340339
bool foundStardom = stardom.Score > 0;
341340

342341
Assert.IsTrue(foundStarKid, "Should find 'Star Kid'");

src/Infidex.Tests/ReferenceMatchingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void Search_Battamam_ReturnsCorrectDocuments()
6969
Console.WriteLine($"battamam returned {result.Records.Length} results:");
7070
foreach (var r in result.Records)
7171
{
72-
Console.WriteLine($" [{r.Score:D3}] Doc {r.DocumentId}");
72+
Console.WriteLine($" [{r.Score:F3}] Doc {r.DocumentId}");
7373
}
7474

7575
// Expected: 1 result, Doc 6 at position 0

src/Infidex.Tests/SchoolSearchParityTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void MaterskaSkolaWithBelohrad_PrefersBelohradskaSkola_AllPermutations()
124124
}
125125

126126
int targetIndex = -1;
127-
int targetScore = -1;
127+
float targetScore = -1;
128128

129129
for (int i = 0; i < records.Length; i++)
130130
{
@@ -217,8 +217,8 @@ public void Sciozli_ZlinScoresHigherThanKolin()
217217
$"First result should be ScioŠkola Zlín, but was: {firstDoc.IndexedText}");
218218

219219
// Find scores for both schools
220-
int zlinScore = -1;
221-
int kolinScore = -1;
220+
float zlinScore = -1;
221+
float kolinScore = -1;
222222

223223
foreach (var record in records)
224224
{
@@ -299,8 +299,8 @@ public void Sciozlinskaskola_ZlinRanksFirst()
299299
$"First result should be ScioŠkola Zlín (query contains 'zlín'), but was: {firstDoc.IndexedText}");
300300

301301
// Find scores for both schools
302-
int zlinScore = -1;
303-
int kolinScore = -1;
302+
float zlinScore = -1;
303+
float kolinScore = -1;
304304

305305
foreach (var record in records)
306306
{
@@ -352,8 +352,8 @@ public void Sciozlin_Query_ReturnsSchool()
352352
$"First result should be ScioŠkola Zlín for 'sciozlín', but was: {topDoc.IndexedText}");
353353

354354
// If Kolín appears, it must have a lower score
355-
int zlinScore = records[0].Score;
356-
int kolinScore = -1;
355+
float zlinScore = records[0].Score;
356+
float kolinScore = -1;
357357

358358
foreach (var record in records)
359359
{
@@ -402,7 +402,7 @@ public void ScioskolaCityAbbreviation_RanksCorrectCityFirst(string query, string
402402
$"First result should contain '{expectedSchoolSubstring}', but was: {firstDoc.IndexedText}");
403403

404404
// Requirement 2: The correct ScioŠkola must have a strictly higher score than others
405-
int targetScore = records[0].Score;
405+
float targetScore = records[0].Score;
406406
for (int i = 1; i < records.Length; i++)
407407
{
408408
var doc = engine.GetDocument(records[i].DocumentId);
@@ -471,7 +471,7 @@ public void TyrsovkaCeskaLipa_PrefersCeskaLipaSchool()
471471
const string targetName = "Základní škola Dr. Miroslava Tyrše, Česká Lípa, Mánesova 1526, příspěvková organizace";
472472

473473
int targetIndex = -1;
474-
int targetScore = -1;
474+
float targetScore = -1;
475475

476476
for (int i = 0; i < records.Length; i++)
477477
{

src/Infidex.Tests/ScoreArrayTests.cs

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/Infidex/Api/Result.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Result
2626
/// <summary>
2727
/// Score of the last record in the result set (for pagination)
2828
/// </summary>
29-
public ushort TruncationScore { get; set; }
29+
public float TruncationScore { get; set; }
3030

3131
/// <summary>
3232
/// Indicates if the query execution timed out
@@ -59,7 +59,7 @@ public class Result
5959
/// Creates a result with full metadata
6060
/// </summary>
6161
public Result(ScoreEntry[] records, Dictionary<string, KeyValuePair<string, int>[]>? facets,
62-
int truncationIndex, ushort truncationScore, bool didTimeOut)
62+
int truncationIndex, float truncationScore, bool didTimeOut)
6363
{
6464
Records = records;
6565
Facets = facets;
@@ -80,16 +80,14 @@ public Result(ScoreEntry[] records, int totalCandidates)
8080
ExecutionTimeMs = 0;
8181
DidTimeOut = false;
8282
TruncationIndex = records.Length > 0 ? records.Length - 1 : 0;
83-
TruncationScore = records.Length > 0 ? records[^1].Score : (byte)0;
83+
TruncationScore = records.Length > 0 ? records[^1].Score : 0f;
8484
}
8585

8686
/// <summary>
8787
/// Creates an empty result
8888
/// </summary>
8989
public static Result MakeEmptyResult(bool timedOut = false)
9090
{
91-
return new Result([], null, 0, 0, timedOut);
91+
return new Result([], null, 0, 0f, timedOut);
9292
}
9393
}
94-
95-

src/Infidex/Core/ConcurrentDocumentCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public void Compact()
367367
_documents.AddRange(compacted);
368368

369369
_keyToIds.Clear();
370-
foreach (var kvp in newKeyToIds)
370+
foreach (KeyValuePair<long, List<int>> kvp in newKeyToIds)
371371
_keyToIds[kvp.Key] = kvp.Value;
372372
}
373373
finally

0 commit comments

Comments
 (0)