Lucene搜索不工作 [英] Lucene search not working

查看:166
本文介绍了Lucene搜索不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有搜索一些文章在Sitecore的内容项功能,并给我的价值。到目前为止,我已经建立了我的指标,它显示在我的IndexViewer。但是,函数的返回值为0。我抬头一看此链接: http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in_25.html 了解详情。

I have a function which searches some articles in the Sitecore content items and give me the value. So far I have build up my indexes and it is showing in my IndexViewer. But the return of the function is 0. I looked up this link: http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in_25.html for more information.

 protected IEnumerable<Item> ShowHomePageNews(int numOfArticles, string stringofCountries)
    {
        List<Item> items = new List<Item>();
        Sitecore.Search.Index indx = SearchManager.GetIndex("newsArticles");
        using (IndexSearchContext searchContext = indx.CreateSearchContext())
        {
            var db = Sitecore.Context.Database;
            CombinedQuery query = new CombinedQuery();
            QueryBase catQuery = new FieldQuery("countries", stringofCountries); //FieldName, FieldValue.
            SearchHits results = searchContext.Search(catQuery); //Searching the content items by fields.
            SearchResultCollection result = results.FetchResults(0, numOfArticles);
            foreach (SearchResult i in result)
            {
                items = result
                              .Where(r => !r.Title.StartsWith("*"))
                              .Select(r => db.GetItem(new Sitecore.Data.ItemUri(r.Url).ToDataUri()))
                              .ToList();
                //Lucene.Net.Documents.Field url = i.Document.GetField("_url");
                //Sitecore.Data.ItemUri itemUri = new Sitecore.Data.ItemUri(url.StringValue());
                //Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(itemUri.ToDataUri());
                //items.Add(item);
            }
        }
        return items;
    }



在这里的结果为0,我在这里做什么wrond?

Over here the result is 0. What I am doing wrond here?

这是快照我所看到的我IndexViewer:

This is the snapshot of what I am seeing in my IndexViewer:

编辑:

我在'catQuery传递NZ,我得到的结果回来。因为在我的索引观众我看到的字段名称= _name,其中包含了新西兰在里面。我得到了这部分内容。不过,我想被索引我的每一个领域。我看到只有3个在我IndexViewer领域:_url,_group&安培; _名称。

I am passing a "NZ" in the 'catQuery' and I am getting the result back. Because in my index viewer I am seeing the Field Name = _name, which contains NZ in it. I got this part. However, I want my every field to be indexed. I am seeing only 3 fields in my IndexViewer: _url, _group & _name.

推荐答案

所以,你的国家,应通过索引标记化。作为一个多重表,他们将进行GUID标记化。搜索由GUID一个国家与您的代码上面应该工作。但是,如果你想搜索多个国家,任何国家通过了可以触发一场比赛,你需要以不同的结构查询。

So your countries should be tokenized by the indexer. As a multilist, they will be tokenized by GUID. Searching for a single country by GUID with your code above should work. However, if you want to search for multiple countries, where any of the passed in countries can trigger a match, you need to structure your query differently.

CombinedQuery query = new CombinedQuery();

//apply other filters here to query if need be

//and country filter by creating a new clause (combinedquery) and "ORing" within it (QueryOccurance.Should)
CombinedQuery query3 = new  CombinedQuery();
//here you would actually iterate over your country list
query3.Add(new FieldQuery("countries", country1GUID), QueryOccurance.Should);
query3.Add(new FieldQuery("countries", country2GUID), QueryOccurance.Should);
query.Add(query3, QueryOccurance.Must);

这篇关于Lucene搜索不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆