Skip to content

Commit

Permalink
Merge pull request #87 from patriksvensson/feature/GH-70
Browse files Browse the repository at this point in the history
Search for partial words
  • Loading branch information
patriksvensson authored Nov 7, 2018
2 parents c3bd651 + 092522e commit 2acc141
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Jarvis.Addin.Files/Indexing/FileIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public Task<bool> Run(CancellationToken token)
foreach (var file in result)
{
// Index individual words as well as combinations.
Index(trie, file.Title, file);
Index(trie, file.Description, file);
Index(trie, file.Title, file, true);
Index(trie, file.Description, file, false);

// Also index the whole words without tokenization.
trie.Insert(file.Title, file);
Expand All @@ -86,8 +86,8 @@ public Task<bool> Run(CancellationToken token)
if (entryWithPath.Path is FilePath filePath)
{
// Index individual words as well as combinations.
Index(trie, filePath.GetFilenameWithoutExtension().FullPath, file);
Index(trie, filePath.GetFilename().RemoveExtension().FullPath, file);
Index(trie, filePath.GetFilenameWithoutExtension().FullPath, file, false);
Index(trie, filePath.GetFilename().RemoveExtension().FullPath, file, false);

// Also index the whole words without tokenization.
trie.Insert(filePath.GetFilenameWithoutExtension().FullPath, file);
Expand Down Expand Up @@ -146,7 +146,7 @@ private IEnumerable<IndexedEntry> LoadResults(CancellationToken token)
.ToList();
}

private void Index(Trie<IndexedEntry> trie, string word, IndexedEntry entry)
private void Index(Trie<IndexedEntry> trie, string word, IndexedEntry entry, bool permutations)
{
if (string.IsNullOrWhiteSpace(word))
{
Expand All @@ -172,8 +172,18 @@ private void Index(Trie<IndexedEntry> trie, string word, IndexedEntry entry)
}
}

// Build partial sentence.
trie.Insert(string.Join(" ", parts.Skip(i).Take(parts.Length - i)), entry);
if (permutations)
{
// Build partial sentence.
trie.Insert(string.Join(" ", parts.Skip(i).Take(parts.Length - i)), entry);

// Build all possible permutations.
for (var j = i + 1; j < parts.Length; j++)
{
var temp = string.Concat(parts[i], " ", parts[j]);
trie.Insert(temp, entry);
}
}
}
}

Expand Down

0 comments on commit 2acc141

Please sign in to comment.