Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. [ElasticType(Name = "WebResource", SearchAnalyzer = "full_name", IndexAnalyzer = "partial_name", DateDetection = true, NumericDetection = true)]
  2. public class WebResource
  3. {
  4. public string _id;
  5. [ElasticProperty(Type = FieldType.integer_type, Index = FieldIndexOption.not_analyzed)]
  6. public string Id
  7. {
  8. get
  9. {
  10. if (_id == null || _id == Guid.Empty.ToString())
  11. {
  12. _id = Guid.NewGuid().ToString();
  13. }
  14. return _id;
  15. }
  16. set
  17. {
  18. _id = value;
  19. }
  20. }
  21.  
  22. [ElasticProperty(Type = FieldType.string_type, Index = FieldIndexOption.analyzed)]
  23. public string Keywords { get; set; }
  24.  
  25. [ElasticProperty(Type = FieldType.string_type, Index = FieldIndexOption.analyzed)]
  26. public string Content { get; set; }
  27. }
  28.  
  29. Client.Search<WebResource>(g => g.Query(k => k.Term(l => l.Content, searchText) || k.Term(l => l.Keywords, searchText)).Highlight(k => k.OnFields(p => p.OnField("Keywords"), p => p.OnField("Content")).FragmentSize(200)));
  30.  
  31. Action<HighlightFieldDescriptor<WebResource>> actWeb = (t) => t.OnField(g => g.Content);
  32. Action<HighlightFieldDescriptor<WebResource>> actKey = (t) => t.OnField(g => g.Keywords);
  33.  
  34. Action<HighlightDescriptor<WebResource>> higDesc = t => t.OnFields(actWeb,actKey);
  35.  
  36. SearchDescriptor<WebResource> searchdesc = new SearchDescriptor<WebResource>();
  37.  
  38. searchdesc.Query( t => t.Term( k => k.Content,searchText) || t.Term( l =>l.Keywords,searchText));
  39. searchdesc.Highlight(higDesc);
  40.  
  41. var resp = Client.Search(searchdesc);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement