English 中文(简体)
• 如何将田地数与模拟案文价值挂钩——自行搜索
原标题:How to index field with comma-separated text value - hibernate search

我正在执行一本基于藏匿搜查的书状。

书目中有一个称为作者名称的领域。 作者名称价值是姓名清单, com是分裂者,如“John Will,Robin Rod, James Timerberland”

@Field(index = org.hibernate.search.annotations.Index.UN_TOKENIZED,store=Store.YES)
@FieldBridge(impl=CollectionToCSVBridge.class)
private Set<String> authornames;

我每个名字都需要联合国。 ToKENIZED,从而使用户检索书以单一作者名称:John Will、Robin Rod或James Timerberland。

我用Luke来检查指数,在作者领域的价值被储存为“John Will、Robin Rod、James Timerberland”,但我无法通过询问“作者姓名:John Will”而得出结果。

Anybody can tell me how can I do it?

问题回答

I gues CollectionToCSVBridge is concatenating all names with a ", " in a larger string. You should keep them separate instead and add each element individually to the index:

@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
    if ( value == null ) {
        return;
    }
    if ( !( value instanceof Collection ) ) {
        throw new IllegalArgumentException( "This FieldBridge only supports collections." );
    }
    Collection<?> objects = (Collection<?>) value;

    for ( Object object : objects ) {
        luceneOptions.addFieldToDocument( name, objectToString( object ), document ); // in your case objectToString could do just a #toString
    }
}

另见https://forum.hibernate.org/viewtopic.php?f=9&t=1015286&start=0





相关问题
Lucene.NET in medium trust

How do I make Lucene.NET 2.3.2 run in a medium trust environment? GoDaddy doesn t like it the way it is.

Grails searchable plugin

In my Grails app, I m using the Searchable plugin for searching/indexing. I want to write a Compass/Lucene query that involves multiple domain classes. Within that query when I want to refer to the id ...

Search subset of objects using Compass/Lucene

I m using the searchable plugin for Grails (which provides an API for Compass, which is itself an API over Lucene). I have an Order class that I would like to search but, I don t want to search all ...

Lucene seems to be caching search results - why?

In my project we use Lucene 2.4.1 for fulltext search. This is a J2EE project, IndexSearcher is created once. In the background, the index is refreshed every couple of minutes (when the content ...

热门标签