Skip to content

Commit cd7ab5c

Browse files
authored
Have inventory search look at entity description in addition to names (#2582)
Closes #1879 . At first I tried doing fuzzy search within entity descriptions, just like we currently do for searching in entity names, but subjectively that yielded way too many false positives. The letters of any word you might type in could be found somewhere in almost all entity descriptions. Doing fuzzy search within names but literal substring search within descriptions subjectively seems to yield useful results.
1 parent c8f2b7b commit cd7ab5c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/swarm-scenario/Swarm/Game/Entity.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ entityNameFor _ = to $ \e ->
671671
Just pl -> pl
672672
Nothing -> plural (e ^. entityName)
673673

674-
-- | A longer, free-form description of the entity. Each 'Text' value
675-
-- represents a paragraph.
674+
-- | A longer, free-form description of the entity.
676675
entityDescription :: Lens' Entity (Document Syntax)
677676
entityDescription = hashedLens _entityDescription (\e x -> e {_entityDescription = x})
678677

src/swarm-tui/Swarm/TUI/Model.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import Data.Map (Map)
107107
import Data.Maybe (fromMaybe)
108108
import Data.Set (Set)
109109
import Data.Text (Text)
110+
import Data.Text qualified as T
110111
import Data.Vector qualified as V
111112
import GitHash (GitInfo)
112113
import Graphics.Vty (ColorMode (..))
@@ -124,6 +125,7 @@ import Swarm.Game.State.Runtime
124125
import Swarm.Game.State.Substate
125126
import Swarm.Game.Tick (TickNumber (..))
126127
import Swarm.Game.World (Seed)
128+
import Swarm.Language.Text.Markdown qualified as Markdown
127129
import Swarm.Log
128130
import Swarm.TUI.Inventory.Sorting
129131
import Swarm.TUI.Model.DebugOption (DebugOption)
@@ -278,7 +280,13 @@ populateInventoryList (Just r) = do
278280
&& not ((r ^. equippedDevices) `E.contains` e)
279281

280282
matchesSearch :: (Count, Entity) -> Bool
281-
matchesSearch (_, e) = maybe (const True) Fuzzy.test search (e ^. E.entityName)
283+
matchesSearch (_, e) =
284+
-- Fuzzy search within entity names.
285+
maybe (const True) Fuzzy.test search (e ^. E.entityName)
286+
-- Also do a literal substring search within entity
287+
-- descriptions. Since descriptions are long, a fuzzy
288+
-- search tends to yield too many false positives.
289+
|| maybe (const True) T.isInfixOf search (Markdown.docToText (e ^. E.entityDescription))
282290

283291
items =
284292
(r ^. robotInventory . to (itemList True mkInvEntry "Compendium"))

0 commit comments

Comments
 (0)