Java liferay lucene搜索不工作

Java liferay lucene搜索不工作,java,lucene,full-text-search,liferay,Java,Lucene,Full Text Search,Liferay,我正在尝试在Liferay 6.2中实现基于Lucene的索引和搜索。我有一个自定义服务生成器实体,我希望能够搜索该实体的所有字段。但问题是,除非我在搜索框中显式键入字段:value,否则它不会搜索所有索引字段。看起来它只是在搜索liferay默认值 Field.ASSET_CATEGORY_TITLES, Field.ASSET_TAG_NAMES, Field.COMMENTS, Field.CONTENT, Field.DESCRIPTION, Field.PROPERTIES, Fiel

我正在尝试在Liferay 6.2中实现基于Lucene的索引和搜索。我有一个自定义服务生成器实体,我希望能够搜索该实体的所有字段。但问题是,除非我在搜索框中显式键入
字段:value
,否则它不会搜索所有索引字段。看起来它只是在搜索liferay默认值

Field.ASSET_CATEGORY_TITLES, Field.ASSET_TAG_NAMES, Field.COMMENTS,
Field.CONTENT, Field.DESCRIPTION, Field.PROPERTIES, Field.TITLE,
Field.URL, Field.USER_NAME
这是我的实体

<entity name="Sample" local-service="true" remote-service="true" table="sample">
        <column name="uuid_" type="String" />
        <column name="sampleDbId" type="long" primary="true" />
        <column name="sampleCollectionDbId" type="long" />
        <column name="biobankDbId" type="long" />
        <column name="hashedSampleId" type="String" />
        <column name="hashedIndividualId" type="String" />
        <column name="materialType" type="String" />
        <column name="container" type="String" />
        <column name="storageTemperature" type="String" />
        <column name="sampledTime" type="Date"/>
        <column name="anatomicalPartOntology" type="String" />
        <column name="anatomicalPartOntologyVersion" type="String" />
        <column name="anatomicalPartOntologyCode" type="String" />
        <column name="anatomicalPartOntologyDescription" type="String" />
        <column name="anatomicalPartFreeText" type="String" />
        <column name="sex" type="String" />
        <column name="ageLow" type="long" />
        <column name="ageHigh" type="long" />
        <column name="ageUnit" type="String" />
        <column name="diseaseOntology" type="String" />
        <column name="diseaseOntologyVersion" type="String" />
        <column name="diseaseOntologyCode" type="String" />
        <column name="diseaseOntologyDescription" type="String" />
        <column name="diseaseFreeText" type="String" />
        <column name="countryOfOrigin" type="String" />
        <finder name="uuid" return-type="Collection">
            <finder-column name="uuid_" />
        </finder>

</entity>
我还在localserviceimpl类中定义了Hits搜索方法:

public Hits search(long companyId, String keywords) throws SearchException{
        System.out.println("-----SampleLocalServiceImpl search called------");

        SearchContext searchContext = new SearchContext();
        searchContext.setAndSearch(false);


        Map<String, Serializable> attributes = new HashMap<String, Serializable>();

        attributes.put("sampleCollectionName", keywords);
        attributes.put("biobankName", keywords);
        attributes.put("materialType", keywords);
        attributes.put("container", keywords);
        attributes.put("storageTemperature", keywords);
        attributes.put("sampledTime", keywords);
        attributes.put("anatomicalPartOntology", keywords);
        attributes.put("anatomicalPartOntologyVersion", keywords);
        attributes.put("anatomicalPartOntologyCode", keywords);
        attributes.put("anatomicalPartOntologyDescription", keywords);
        attributes.put("anatomicalPartFreeText", keywords);
        attributes.put("sex", keywords);
        attributes.put("ageLow", keywords);
        attributes.put("ageHigh", keywords);
        attributes.put("ageUnit", keywords);
        attributes.put("diseaseOntology", keywords);
        attributes.put("diseaseOntologyVersion", keywords);
        attributes.put("diseaseOntologyCode", keywords);
        attributes.put("diseaseOntologyDescription", keywords);
        attributes.put("diseaseFreeText", keywords);
        attributes.put("countryOfOrigin", keywords);

        searchContext.setAttributes(attributes);
        searchContext.setCompanyId(companyId);
        searchContext.setKeywords(keywords);
        System.out.println(searchContext.getAttributes());

        QueryConfig queryConfig = new QueryConfig();

        queryConfig.setHighlightEnabled(false);
        queryConfig.setScoreEnabled(false);
        //searchContext.setAttribute("materialType:", keywords);
        searchContext.setQueryConfig(queryConfig);

        System.out.println(searchContext.getCompanyId());
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
                Sample.class);
        System.out.println("-----SampleLocalServiceImpl search called------"+indexer.getFullQuery(searchContext));
        System.out.println("-----SampleLocalServiceImpl search called------"+indexer);


        return indexer.search(searchContext);
    }
public Hits search(长公司ID,字符串关键字)抛出SearchException{
System.out.println(“----SampleLocalServiceImpl搜索调用----”;
SearchContext SearchContext=新的SearchContext();
searchContext.setAndSearch(false);
Map attributes=newhashmap();
attributes.put(“sampleCollectionName”,关键字);
attributes.put(“biobankName”,关键字);
attributes.put(“materialType”,关键字);
attributes.put(“容器”,关键字);
属性。放置(“存储温度”,关键字);
attributes.put(“sampledTime”,关键字);
attributes.put(“解剖学零件本体论”,关键词);
attributes.put(“解剖部分本体论版本”,关键词);
attributes.put(“解剖部分本体代码”,关键字);
attributes.put(“解剖部位本体描述”,关键词);
attributes.put(“解剖部分自由文本”,关键字);
属性。放置(“性”,关键词);
attributes.put(“ageLow”,关键字);
attributes.put(“ageHigh”,关键字);
attributes.put(“年龄单位”,关键字);
attributes.put(“疾病本体论”,关键字);
attributes.put(“diseaseOntologyVersion”,关键字);
attributes.put(“diseaseOntologyCode”,关键字);
attributes.put(“diseaseOntologyDescription”,关键字);
attributes.put(“diseaseFreeText”,关键字);
attributes.put(“原产国”,关键字);
searchContext.setAttributes(attributes);
searchContext.setCompanyId(companyId);
searchContext.setKeywords(关键字);
System.out.println(searchContext.getAttributes());
QueryConfig QueryConfig=新建QueryConfig();
queryConfig.setHighlightabled(假);
queryConfig.setScoreEnabled(假);
//setAttribute(“materialType:”,关键字);
setQueryConfig(queryConfig);
System.out.println(searchContext.getCompanyId());
Indexer Indexer=IndexerRegistryUtil.nullSafeGetIndexer(
样本(类别);
System.out.println(“----samplelocalserviceinpl-search调用----”+indexer.getFullQuery(searchContext));
System.out.println(“----SampleLocalServiceImpl搜索调用----”+索引器);
返回indexer.search(searchContext);
}
我通过localserviceutil类从jsp调用此搜索方法

因此,当我在搜索框中键入
blood
时,我不会得到任何结果,但当我键入
materialType:blood
时,我会返回结果

  • 对于emtpy搜索,查询日志提供
    +(+(+(entryClassName:com.xxx.portlet.xxx.model.Sample))
    (提供完整的结果集)
  • 如果我输入血型,查询日志会显示

    +(+((+(entryClassName:com.xxx.portlet.xxx.model.Sample)))+(资产类别标题:*血液*资产名称:*血液*注释:血液内容:血液描述:血液属性:血液标题:血液
    url:blood用户名:*blood*)

    (空结果集)

  • 如果我键入materialType:blood,查询日志将显示
    +(+(+(entryClassName:com.xxx.portlet.xxx.model.Sample)))
    +(材料类型:*血液*材料类型:血液)
    (匹配结果集)

我希望用户能够在框中键入自由文本并返回匹配结果。但目前这并不起作用,因为自由文本搜索只是在liferay默认字段上搜索。我怎样才能解决这个问题


该问题也已发布。

设置
searchContext.setAttributes(attributes)是不够的localserviceinpl
类的
点击搜索方法中的code>。我还必须重写我的
索引器
类中的
postprocessearchquery
方法。因此,在我的
索引器
类中添加了以下方法后,我使其正常工作

    @Override
    public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
        throws Exception {
        System.out.println("-----postProcessSearchQuery called------");

        addSearchTerm(searchQuery, searchContext, "sampleCollectionName", true);
        addSearchTerm(searchQuery, searchContext, "biobankName", true);
        addSearchTerm(searchQuery, searchContext, "materialType", true);
        addSearchTerm(searchQuery, searchContext, "container", true);
        addSearchTerm(searchQuery, searchContext, "storageTemperature", true);
        .....
        .....

        LinkedHashMap<String, Object> params =
            (LinkedHashMap<String, Object>)searchContext.getAttribute("params");

        if (params != null) {
            String expandoAttributes = (String)params.get("expandoAttributes");

            if (Validator.isNotNull(expandoAttributes)) {
                addSearchExpando(searchQuery, searchContext, expandoAttributes);
            }
        }
    }
@覆盖
public void postprocessearchquery(BooleanQuery searchQuery,SearchContext SearchContext)
抛出异常{
System.out.println(“----postprocessearchquery调用----”;
addSearchTerm(searchQuery,searchContext,“sampleCollectionName”,true);
addSearchTerm(searchQuery,searchContext,“biobankName”,true);
addSearchTerm(searchQuery,searchContext,“materialType”,true);
addSearchTerm(searchQuery,searchContext,“容器”,true);
addSearchTerm(searchQuery,searchContext,“storageTemperature”,true);
.....
.....
LinkedHashMap参数=
(LinkedHashMap)searchContext.getAttribute(“参数”);
如果(参数!=null){
String expandoAttributes=(String)params.get(“expandoAttributes”);
if(Validator.isNotNull(expandoAttributes)){
addSearchExpando(searchQuery、searchContext、expandoAttributes);
}
}
}

是什么让你认为
SearchContext.attributes
Document.fields
映射到同一个属性?您应该检查索引器的
search
方法,以了解它是如何将搜索上下文映射到字段的。您是指我正在扩展的BaseIndexer。我最终看到在使用facet的地方调用了“LuceneIndexSearcher.search”。我必须使用facet来完成这项工作吗?我一直在关注liferay的搜索和索引文档,其中没有使用方面。你不需要方面(尽管它们也支持过滤),但你需要
    @Override
    public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
        throws Exception {
        System.out.println("-----postProcessSearchQuery called------");

        addSearchTerm(searchQuery, searchContext, "sampleCollectionName", true);
        addSearchTerm(searchQuery, searchContext, "biobankName", true);
        addSearchTerm(searchQuery, searchContext, "materialType", true);
        addSearchTerm(searchQuery, searchContext, "container", true);
        addSearchTerm(searchQuery, searchContext, "storageTemperature", true);
        .....
        .....

        LinkedHashMap<String, Object> params =
            (LinkedHashMap<String, Object>)searchContext.getAttribute("params");

        if (params != null) {
            String expandoAttributes = (String)params.get("expandoAttributes");

            if (Validator.isNotNull(expandoAttributes)) {
                addSearchExpando(searchQuery, searchContext, expandoAttributes);
            }
        }
    }