2017-03-06 4 views
0

Luceneインデックスの結果を得るには、次のコードを使用しています。私は上記のクエリでDbFunctionsを使用しない場合、私は正確に一つのレコードを取得IQueryableでDbFunctionsを使用してLuceneインデックスを検索する方法

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. 

using (var context = ContentSearchManager.GetIndex("my_profile_index").CreateSearchContext()) 
    { 
     IQueryable<ProfileSearchItem> query = from profile in context.GetQueryable<ProfileSearchItem>() 
               where profile.LastName.Equals("Zafar") 
               let diffYears = DbFunctions.DiffYears(profile.Birthdate, DateTime.Today) 
               select profile; 
     return query.ToList(); 
    } 

私は理由DbFunctions.DiffYearsの例外を取得します。私はインデックスを検索中にDbFunctionsを使用する方法を知りたいです。これは単なるサンプルクエリです、私の唯一の目的はタイトルに記載されています。

ProfileSearchItemクラス:

public class ProfileSearchItem 
    { 
     [IndexField("_group")] 
     public string ItemId { get; set; } 

     [IndexField("_language")] 
     public string Language { get; set; } 

     [IndexField("birthdate")] 
     public DateTime Birthdate { get; set; } 

     [IndexField("first_name")] 
     public string FirstName { get; set; } 

     [IndexField("last_name")] 
     public string LastName { get; set; } 
    } 

答えて

0

私は、クエリは、その内部の機能を有するとクエリパーサが何かにこれを変換しようとしているのが好きとは思いません。

あなたの場合は、POCOのクエリの後に年差の計算を行うことができます。

ProfileSearchItem POCOにプロパティがあります。

public int YearsDifference { get { return Datetime.Now.Year - Birthdate.Year;} } 
0

日付フィールドが20170308のようにLuceneの中の文字列として保持されているので、私はDbFunctions.DiffYearsは、いくつかのラムダ式をやっていると思い.Yearデータ・メソッドの多くは、[日付フィールド]比較するようにもシンプルなものを動作しません。日付メソッドを使用して結果を入力します。

https://ggullentops.blogspot.com.au/2015/12/sitecore-lucene-index-and-datetime.htmlをご覧ください。より良い表示が得られる可能性があります。

関連する問題