1

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

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

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

4

3 回答 3

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);
于 2013-03-13T21:31:08.123 回答
0

Sitecore Advanced Database Crawler 是 Sitecore.Search API 的扩展,Sitecore.Search API 是 Lucene 的包装器。

在 Lucene 中,您可以使用NOT-排除诸如"Sitecore NOT awesome"or之类的用户查询"Sitecore -awesome"

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

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

于 2013-03-13T11:53:56.170 回答
0

这是未经测试的,但您可能会幸运地使用 aMatchAllDocsQuery并以 a 的形式提供关键字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, ...)
}
于 2013-03-13T16:45:53.380 回答