如何使用Sitecore Advanced Database Crawler搜索不包含某些关键字的项目?

时间:2013-03-13 02:37:34

标签: sitecore sitecore6

我在数据库中有数百万个项目。用户可以根据关键字搜索这些项目。在搜索功能中,我需要提供一个搜索NOT该关键字的功能。

例如,Item A有一个名为msg的字段,其值为Sitecore is awesome and great。 在搜索框中,用户可以选中复选框,指示显示任何不包含关键字的项目。也许用户键在is关键字中,因此ADC不会显示或检索Item A

编辑:目前我正在使用sitecore6.6,因此不推荐使用Search方法。我已经使用Occurrence.MustNot尝试了Not关键字,但它没有返回任何结果。

3 个答案:

答案 0 :(得分:0)

Sitecore高级数据库抓取工具是Sitecore.Search API的扩展,Sitecore.Search API是Lucene的包装。

在Lucene中,您可以使用NOT-进行查询,以排除"Sitecore NOT awesome""Sitecore -awesome"之类的内容。

要排除某些内容,至少需要一个包含术语。

不确定它是否有效,但试一试。

答案 1 :(得分:0)

这是未经测试的,但您可以通过使用MatchAllDocsQuery并以Filter的形式提供关键字来获得好运。

BooleanQuery booleanQuery = new BooleanQuery();

QueryParser queryParser = new QueryParser("msg", new StandardAnalyzer());
Query userQuery = queryParser.Parse("Sitecore is awesome and great");
booleanQuery.Add(userQuery, reverseQuery.Checked ? BooleanClause.Occur.MUST_NOT : BooleanClause.Occur.MUST);

MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery();
Filter filter = new QueryFilter(booleanQuery);

using (QueryRunner queryRunner = new QueryRunner("myIndex"))
{
    var skinnyItems = queryRunner.RunQuery(matchAllQuery, filter, ...)
}

答案 2 :(得分:0)

我所做的不包括与结果项目集关联的关键字是:

 protected List<Item> getSearchResults(string queryToSearch, string selectedFilter, string notToSearch)
    {
        Database db = Sitecore.Context.Database;
        var index = SearchManager.GetIndex("siteSearchIndexName");

        using (SortableIndexSearchContext context = new SortableIndexSearchContext(index))
        {
            if (!String.IsNullOrWhiteSpace(query))
            {
                query.ToLower();
                CombinedQuery cq = new CombinedQuery();
                QueryBase qbKeyword = new FieldQuery("_orderkeywordpair", query);
                QueryBase qbContent = new FieldQuery("_content", query);
                QueryBase qbHtml = new FieldQuery("html", query);

                if (!String.IsNullOrWhiteSpace(selectedFilter) && selectedFilter.ToLower() != "all")
                {
                    QueryBase qbFilter = new FieldQuery("_pagetype", selectedFilter);
                    cq.Add(qbFilter, QueryOccurance.Must);
                }
                cq.Add(qbKeyword, QueryOccurance.Should);
                cq.Add(qbContent, QueryOccurance.Must);
                cq.Add(qbHtml, QueryOccurance.MustNot);

                SearchHits hits = context.Search(cq);
相关问题