A standalone full-text search engine written in C#.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
960 B

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace LibSearchBox
{
public struct SearchOffset
{
public string Term;
public int Offset;
public SearchOffset(string inTerm, int inOffset)
{
Term = inTerm;
Offset = inOffset;
}
}
public class SearchResult
{
public string PageName { get; private set; }
public float Rank { get; private set; }
public List<SearchOffset> Offsets { get; private set; }
public SearchResult(string inPageName, float inRank, List<SearchOffset> inOffsets)
{
PageName = inPageName;
Rank = inRank;
Offsets = inOffsets;
}
public override string ToString()
{
StringBuilder result = new StringBuilder();
result.AppendLine($"{Rank.ToString().PadLeft(5)}: {PageName}");
result.Append($" {string.Join(", ", Offsets.Select((SearchOffset nextOffset) => $"{nextOffset.Term} @ {nextOffset.Offset}"))}");
return base.ToString();
}
}
}