简体   繁体   中英

Lucene Index on Document is not working by ClassBridge hook

Problem : When I am uploading a word document, I am able to search on title(Entered while uploading the document) and summary, but when I search using the some text in document I am getting the result.

I am using "hibernate-search-engine : 4.3.0.Final, lucene-core : 3.6.2"

POM.XML

   <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>${hibernate.search.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-engine</artifactId>
            <version>${hibernate.search.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>3.6.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queries</artifactId>
            <version>3.6.2</version>
            <scope>runtime</scope>
        </dependency>

Classes

@Entity

@SequenceGenerator(name = "sitepagecontent_seq", sequenceName = "SITEPAGECONTENT_SEQ")
@Indexed(index = "SitePageContent")
@FullTextFilterDef(name = "condition1", impl = StatusFilterFactory.class) //Filter factory with parameters
@Analyzer (impl = StandardAnalyzer.class)
@ClassBridge(name = "splitcontentfileupload",
        index = Index.YES,
        store = Store.YES,
        impl = WordDocHandlerBridge.class,
        params = @org.hibernate.search.annotations.Parameter(name = "padding", value = " ")
        )
@Table(name = "SITE_PAGE_CONTENT")
public class SitePageContent extends BaseObject implements Comparable<SitePageContent> {

    // Fields
    private static final long serialVersionUID = -7424477214552600300L;

    private Long id;

    @IndexedEmbedded
    private Content content;

    @IndexedEmbedded
    private SitePage sitePage;

    private Long sequence;

Content.java

@Entity
@SequenceGenerator(name = "content_seq", sequenceName = "CONTENT_SEQ")

@Table(name = "CONTENT")
@VersionSupportModel
public class Content extends BaseObject implements Comparable<Content> {
// ------------------------------ FIELDS ------------------------------

    // Fields

    private static final long serialVersionUID = 1441591301055742001L;


    private Long id;

    @IndexedEmbedded
    private UploadedFile uploadedFile;

    @IndexedEmbedded
    private ContentType contentType;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String title; 

    private String prevTitle;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String teaser;    

    private String prevTeaser;

    private String linkedContentType;

    private String linkedUrl;

    private Boolean linkedContentPopup;

    @Field(index = Index.YES, store = Store.YES)
    private String status;

    private EcommUser createdBy;

    private EcommUser modifiedBy;

    @Temporal(TemporalType.DATE)
    private Date createdDate;

    @Temporal(TemporalType.DATE)
    private Date modifiedDate;

    private String shared;

    private String statusTemp;

    private Set<Request> requests = new HashSet<Request>(0);

    @ContainedIn
    private Set<SitePageContent> sitePageContents = new HashSet<SitePageContent>(0);

    private Integer version;

    private Integer articleId;

    private String summary;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String description;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String contactName;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String contactPhone;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String contactEmail;

    @Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(impl = StandardAnalyzer.class))
    private String contactPostalAddress;

WordDocHandlerBridge.java

public class WordDocHandlerBridge implements FieldBridge, ParameterizedBridge { 

    protected final Log log = LogFactory.getLog(getClass());

    public static String paddingProperty = "padding";

    private String padding = "";


    public void setParameterValues(Map arg0) {
        Object padding = arg0.get( paddingProperty );
        if (padding != null) {
            this.padding = (String) padding;
        }
    } 


    public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
        String fieldValue = "";
        SitePageContent sitCont = (SitePageContent) value;
        Content cont = sitCont.getContent();
        UploadedFile upF = cont.getUploadedFile();
        if (upF != null) {
            String fieldValue1 = upF.getFileContentType();
            if ( fieldValue1 == null ) {
                fieldValue1 = "";
            }
            byte[] fieldValue2 = upF.getFileContent();
            if ( fieldValue2 == null ) {
                fieldValue2 = new byte[0];
            }
            fieldValue = convertFile2String(fieldValue1, fieldValue2);
        } else {
            fieldValue = "";
        }
        Field field = new Field( name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
        field.setBoost( luceneOptions.getBoost() );
        document.add( field );
    }



    private String convertFile2String(String type, byte[] content) {
  }

When I debugged "WordDocHandlerBridge.java", I am able to see my content is set in Field and added to document, but when I search I am not getting it.

Note : There is a standolne program which recreates the Index for me, If I recreated , I can see the result.

Can any one please help me resolve this.

I solved this, Method in WordDocHandlerBridge this class "convertFile2String", actually opens the file and reads the file and create a String to set the value in the Field, problem is Code is not closing the "File" and some how Luecene is not updating , but when I added close to the PDF and POI files it all started working.

Point here is it used to work with Luecene 2.4, this might be new feature in Lucene 3.6, which is good one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM