搜索范围很容易以编程方式进行管理。 见here。
当搜索范围需要作为功能的一部分发布时,我已经完成了这项工作。
工作正常。
下面,代码从上面的MS文章中解除。
private ServerContext serverctx = null;
private SearchContext searchctx = null;
serverctx = ServerContext.GetContext("SharedServices1");
searchctx = SearchContext.GetContext(serverctx);
Scopes scopes = new Scopes(searchctx);
foreach (Scope scope in scopes.GetSharedScopes())
TreeNode node = treeViewScopes.Nodes.Add(scope.Name);
foreach (TreeNode node in treeViewScopes.Nodes)
{
foreach (ScopeRule rule in scope.Rules)
{
if (rule is PropertyQueryScopeRule)
{
PropertyQueryScopeRule prule = (PropertyQueryScopeRule)rule;
TreeNode childnode = node.Nodes.Add("Property Query Rule: ");
childnode.Text += prule.Property.Name + " = " + prule.Value;
}
if (rule is AllContentScopeRule)
{
AllContentScopeRule arule = (AllContentScopeRule)rule;
node.Nodes.Add("All Content Rule");
}
if (rule is UrlScopeRule)
{
UrlScopeRule urule = (UrlScopeRule)rule;
TreeNode childnode = node.Nodes.Add("URL Rule: ");
childnode.Text += urule.MatchingString;
}
}
}
UPDATE
我将一个属性添加到每个站点,并使用该属性来确定每个网站需要被添加到该范围。 然后,控制台样式的应用程序可以通过服务器上的每个网站并添加范围规则以将每个网址添加到正确的范围。
这将允许将文档添加到网站,而不必明确设置文档级别“项目”属性,确保文档在特定范围内不会被排除在搜索范围之外。
对此的另一个解决方案是遍历每个文档,如果尚未存在指定项目名称的字段,则添加一个字段,并在文档与该网站的属性不匹配时在该文档上设置该项目名称。最终可能是一项长期运行的任务。使用我想的搜索范围会更好。
来源
2008-11-19 20:34:58
Nat
这种方法的问题,我相信,是我们的范围是OR范围。所以基本上我们要搜索属性“ProjectName”== Wolf的所有文档或者该属性不存在的地方。使用范围我们可以将其限制为“ProjectName == Wolf”,但是这会排除大量文档... – noocyte 2008-11-27 11:06:32