3

私は最近、Nhibernate.Searchがクラスの整数プロパティを数値フィールドとしてインデックス付けすることを誤って想定しました。

[Indexed]
public class Location : Entity
{
    [IndexedEmbedded(Depth = 1, Prefix = "Country_")]
    public virtual Country Country { get; set; }
    [Field(Index.Tokenized)]
    public virtual string Name { get; set; }
    [Field(Index.Tokenized)]
    public virtual string AlternativeNames { get; set; }
    [Field(Index.Tokenized)]
    public virtual string OriginalNames { get; set; }
    [Field(Index.UnTokenized)]
    public virtual string LocationType { get; set; }
    [Field()]
    public virtual int? Population   { get; set; }
}

しかし、クエリの並べ替えを次のように設定すると、次のようになります。

 var words = query.Split(' ');

        var luceneQuery = string.Join(" AND ", words.Select(x => "Name:{0}*".F(x)));
        luceneQuery += " AND LocationType:locality";
        var results = search.CreateFullTextQuery<Location>(luceneQuery)
           .SetSort(new Sort(new SortField("Population", CultureInfo.CurrentCulture, true)))
            .SetMaxResults(100)
            .List<Location>();

次のような単語の並べ替えと同じスタイルで、番号順に結果を返します。

City       Country          Region          Population
New London     United States    North America   998
Nueva Londres  Paraguay         South America   971
New London     United States    North America   967
Londonderry    United Kingdom   British Islands 92133
London     Kiribati         Micronesia  921
London     United States    North America   8122
London     United Kingdom   British Islands 7869322
New London     United States    North America   7316

だから私の質問は、Nhibernate.Searchがこれをテキストフィールドとして扱っているので、どうすればそれを数値フィールドに変更でき、変換することができますか、またはすべてのレコードのインデックスを再作成する必要がありますか?それらの340K。

Nhibernateの便利さを感じ始めています。これができないと検索が失われます。たぶん、最初からやり直して、通常のLucene.Netを使用する必要がありますか?

助けてくれてありがとう

4

2 に答える 2

1

アップデート

役立つ可能性のあるリンク:


数値検索と範囲検索に関するあなたの質問は両方ともここで対処されていると思います: http://find.searchhub.org/link?url=http://wiki.apache.org/lucene-java/SearchNumericalFields

Apache Lucene は全文検索エンジンであり、従来のデータベースではないため、数値範囲を処理できません (たとえば、フィールド値がユーザー定義の境界内にあり、日付でさえ数値です)。私たちは、数値を可変精度の特別な文字列エンコード形式 (trie と呼ばれる) に格納する Apache Lucene の拡張機能を開発しました。異なる精度で)。

...

数値フィールドは並べ替えが可能で (特殊なパーサーがFieldCacheに含まれています)、関数クエリで ( FieldCacheを介して)使用できます。

また、数値の範囲検索LongClass.javaによる実装も見つけました。

+ve または -ve long を正しくソートする文字列にエンコードする「LongField」を実装しました。そのクラスをここに投稿しました: http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg04790.html

そこから文字列範囲検索を行うのはかなり簡単です。何か問題がありましたらお知らせください。

于 2013-01-09T12:52:41.807 に答える
0

これはhibernate.search用であり、NHibernate.search用ではないことは知っていますが、列に指定できる[NumericField]はありませんか? (残りはすべて似ています;-)

http://docs.jboss.org/hibernate/search/3.3/reference/en-US/html_single/#basic-mapping (4.1.1.3. @NumericField)

于 2013-01-09T14:44:45.917 に答える