点燃多个字段

时间:2018-01-18 12:19:33

标签: lucene ignite

我有以下对象:

@Data
@AllArgsConstructor
public class SearchItem implements Serializable {
    private String id;
    @QueryTextField
    private String description;
    @QueryTextField
    private String brand;
}

正如您所看到的,我使用lucene索引启用了两个文件。我现在很困惑如何创建TextQuery来搜索特定字段或两个字段。我希望能够在品牌领域或descritption领域或两者中进行文本搜索。有一个点燃示例显示如何创建TextQuery

private static void textQuery() {
    IgniteCache<Long, Person> cache = Ignition.ignite().cache(PERSON_CACHE);

    //  Query for all people with "Master Degree" in their resumes.
    QueryCursor<Cache.Entry<Long, Person>> masters =
        cache.query(new TextQuery<Long, Person>(Person.class, "Master"));

    // Query for all people with "Bachelor Degree" in their resumes.
    QueryCursor<Cache.Entry<Long, Person>> bachelors =
        cache.query(new TextQuery<Long, Person>(Person.class, "Bachelor"));

    print("Following people have 'Master Degree' in their resumes: ", masters.getAll());
    print("Following people have 'Bachelor Degree' in their resumes: ", bachelors.getAll());
}

但是这个例子只显示我必须传入类和搜索字符串。当我有多个用@QueryTextField注释的字段时,如何定义应该执行搜索的类的哪个字段?

搜索字符串示例:

description = ?, brand = ?

1 个答案:

答案 0 :(得分:4)

您可以使用Apache Lucene的查询语法:https://lucene.apache.org/core/2_9_4/queryparsersyntax.html

如果它不适用于你的字段名称,我建议改用大写字母。