【问题标题】:Is there a way to ignore Windows search indexing for certain patterns?有没有办法忽略某些模式的 Windows 搜索索引?
【发布时间】:2017-04-19 19:38:42
【问题描述】:

有没有办法忽略某些模式的 Windows 搜索索引?

例如,我想跳过以下文件夹:

C:\Git**.git\ C:\Git**\包\ C:\杂项\git**.git\ C:\misc\git**\packages\

这些会导致搜索结果中出现数千个额外的噪音匹配。

我确实想索引 C:\misc\git 中的各种文件夹,除了 .git 或 .packages 子文件夹中的内容。我只找到了一种静态方法来做到这一点,而没有任何基于模式的方法。这似乎是一个常见的用例,有点像 git 使用 .gitignore 将某些内容排除在版本控制之外的方式。在这种情况下,它会将其排除在搜索索引之外。

我在“索引位置”中没有看到任何类似模式的工具。我认为可以通过运行某种脚本来完成,以在每次内容更改时排除当前匹配项(例如添加 C:\misc\git\somethingnew),但这与优雅相反。

任何帮助将不胜感激。

一分钱

【问题讨论】:

    标签: git windows-search


    【解决方案1】:

    根据this answer by @PryrtCJ Windows 注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\CrawlScopeManager\Windows\SystemIndex\WorkingSetRules\ 包含允许使用通配符的规则。

    要添加此类规则,我建议在索引选项中将一个 .git 文件夹添加到排除路径,然后找到正确的键(URL 将是 sth. like file:///C:\[partition-or-disk-id]\path\to\.git\)。 然后编辑密钥权限(选择包含 .git URL 的密钥并右键单击它) - 您需要将密钥所有者从 SYSTEM 更改为您的帐户,并允许管理员组修改密钥。

    如果您有权修改它,请右键单击 URL,选择修改并将其内容更改为 file:///*\.git\。稍后恢复以前的权限(只是为了避免问题)。

    这样您就可以创建任何 * 过滤器,例如。 file:///C:\misc\*\packages\*

    【讨论】:

      【解决方案2】:

      可以通过编程方式管理 Windows 搜索索引。

      您可以使用以下模式从搜索索引中排除文件夹:

      • file:///C:\*\packages\ 匹配名为“packages”的文件夹及其内容
      • file:///D:\*\obj\ 匹配名为“obj”的文件夹及其内容

      我在 Windows 11 21h2 下使用 C# 成功测试了这些模式。

      添加新规则的示例 (Powershell)

      # [wsearch-add-rule.ps1]
      # Source: https://stackoverflow.com/questions/13390514/how-to-add-a-location-to-windows-7-8-search-index-using-batch-or-vbscript/13454571#13454571
      Add-Type -path ".\Microsoft.Search.Interop.dll"
      $sm = New-Object Microsoft.Search.Interop.CSearchManagerClass 
      $cat = $sm.GetCatalog("SystemIndex")
      $csm = $cat.GetCrawlScopeManager()
      $csm.AddUserScopeRule("file:///D:\*\obj\", $true, $false, $null)
      $csm.SaveAll()
      

      列出现有规则的示例 (Powershell)

      # [wsearch-list-rules.ps1]
      # Source: https://powertoe.wordpress.com/2010/05/17/powershell-tackles-windows-desktop-search/
      Add-Type -path "Microsoft.Search.Interop.dll"
      $sm = New-Object Microsoft.Search.Interop.CSearchManagerClass 
      $cat = $sm.GetCatalog("SystemIndex")
      $csm = $cat.GetCrawlScopeManager()
      $scopes = @()
      $begin = $true
      [Microsoft.Search.Interop.CSearchScopeRule]$scope = $null
      $enum = $csm.EnumerateScopeRules() 
      while ($scope -ne $null -or $begin) {
           $enum.Next(1,[ref]$scope,[ref]$null)
           $begin = $false
           $scopes += $scope
      }
      $scopes|ogv
      

      所需的Microsoft.Search.Interop.dll可以在in the old Windows Search 3x SDK on web archive上找到

      资源:

      【讨论】:

      • 只能通过安装外部dll来管理吗?
      • Microsoft.Search.Interop.dll 在通过 .NET(托管项目或 Powershell)处理索引时是必需的。请注意,也可以动态生成 dll。更多信息here
      猜你喜欢
      • 1970-01-01
      • 2022-06-22
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多