【问题标题】:Ignite TextQueries on multiple fields在多个字段上点燃 TextQueries
【发布时间】:2018-01-18 12:19:32
【问题描述】:

我有以下对象:

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

如您所见,我使用 lucene 索引启用了两个文件。我现在很困惑如何创建TextQuery 以仅搜索特定字段或同时搜索两个字段。我希望能够在品牌字段或描述字段或两者中进行文本搜索。有一个 ignite 示例展示了如何创建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 = ?

【问题讨论】:

  • 点燃使用 Lucene 和 StandardAnalyzer。您是否尝试过使用标准语法 [1]? AFAIK,可能存在错误和字段名称大小写(大写或小写)问题。 [1]stackoverflow.com/questions/15728569/…

标签: lucene ignite


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多