开发者

Lucene.NET query + highlighting

I am using Umbraco and came across Lucene. I found a lot of code and articles on Lucene, but I still can't build an acceptable search.

I have a number of fields to search from, eg. "nodeName" and "bodyText"

What I need:

  • When I search for "men shoes", it should only return results that have both "men" and "shoes", but also return a page where the nodeName only has "shoes" and the bodyText only has "men".

  • When I search for "shoes", I want results containing "shoe" or "shoes." but not "hoes" if possible

  • Boost the nodeName field

  • Get a snippet of bodyText that contains the matched word(s)

  • Highlight the matched words on both the page name and the snippet of the bodyText

Has anyone ever d开发者_开发百科one this?


This might get you started.

var manager = ExamineManager.Instance;
var searcher = manager.SearchProviderCollection["YOURSearcher"];
var query = manager.SearchProviderCollection["YOURSearcher"].CreateSearchCriteria(BooleanOperation.Or)
   .Field("nodeName", keywords.Boost(10))
   .Or().Field("nodeName", keywords.Fuzzy())
   .Or().Field("bodyContent", keywords.Boost(5))
   .Or().Field("otherField", keywords.Boost(3));
var results = searcher.Search(query.Compile());


The code by Jonathan Lathigee works, it's the most google-like I could find so far

http://our.umbraco.org/forum/developers/extending-umbraco/19329-Search-multiple-fields-for-multiple-terms-with-examine?p=0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜