<?xml version="1.0" encoding="UTF-8"?>
<!--
    Ant buildfile for testing TET with the Lucene search software.
    
    To try this out, drop the Lucene JAR file into the same directory
    as this build.xml file. The build.xml file expects the following
    Lucene JAR files in this directory: lucene-core-5.2.1.jar,
    lucene-analyzers-common-5.2.1.jar, lucene-queryparser-5.2.1.jar.
    
    The names and locations of these JAR files can be overridden by using
    the "lucene-core.jar", "lucene-analyzers-common.jar" and
    "lucene-queryparser.jar" properties.
    
    Invoke "ant index" to create an index over the PDF files that come with 
    the TET distribution. Then invoke "ant search" to run a simple command-line
    based query environment.
    
    The search application accepts the Lucene query language. After entering
    the query the results will be displayed in a simple query pager. The pager
    must be exited by entering "q", before the next query can be entered. 
    
    As the search application will run under Ant, there will be a "[java]"
    prefix before each output line. The prefix will not appear when running
    the applications directly with the JVM under the "java" command.
-->
<project name="tet-lucene" default="all">
    <!--
        For optionally overriding the default properties with a platform-specific
        "unix.properties" or "windows.properties" file and a generic 
        "build.properties" file.
    -->
    <condition property="os.family" value="unix">
        <or>
            <os family="unix"/>
            <os family="mac"/>
        </or>
    </condition>

    <condition property="os.family" value="windows">
        <os family="windows"/>
    </condition>

    <property file="${os.family}.properties"/>
    <property file="build.properties" />
    
    <!-- Location of the TET Java binaries. -->
    <property name="tet.java.dir" value="../../bind/java" />
    <property name="tet.jni.dir" value="${tet.java.dir}" />
    <property name="tet.jar" value="${tet.java.dir}/TET.jar" />
    
    <!-- Searchpath for the indexer, to find the CJK CMaps and other resources -->
    <property name="tet.searchpath" value="../../resource/cmap ../../resource" />

    <!-- Location of the Lucene core JAR file. -->
    <property name="lucene-core.jar" value="lucene-core-8.0.0.jar" />

    <!-- Location of the Lucene analyzers common JAR file. -->
    <property name="lucene-analyzers-common.jar" value="lucene-analyzers-common-8.0.0.jar" />

    <!-- Location of the Lucene queryparser JAR file. -->
    <property name="lucene-queryparser.jar" value="lucene-queryparser-8.0.0.jar" />

    <!-- Java source and target directories. -->
    <property name="src.dir" value="src" />
    <property name="bin.dir" value="bin" />
   
    <!-- Directory for storing the Lucene index. -->
    <property name="index.dir" value="index" />
    
    <!--
        Root of the directory tree that is searched recursively for PDF
        documents to be added to the index, the default is the "data" directory
        of the TET distribution.
    -->
    <property name="root.dir" value="../../bind/data" />

    <path id="classpath">
        <pathelement location="${lucene-core.jar}" />
        <pathelement location="${lucene-analyzers-common.jar}" />
        <pathelement location="${lucene-queryparser.jar}" />
        <pathelement location="${tet.jar}" />
        <pathelement location="${bin.dir}" />
    </path>
    
    <target name="all" depends="compile" />

    <target name="compile">
        <mkdir dir="${bin.dir}"/>
        <javac srcdir="${src.dir}" destdir="${bin.dir}" includeantruntime="false">
            <classpath refid="classpath" />
        </javac>
    </target>

    <target name="index" depends="compile">
        <echo>Indexing PDF files in directory "${root.dir}"</echo>
        <java classname="com.pdflib.tet.lucene.IndexPdfFiles" fork="true">
            <jvmarg value="-Djava.library.path=${tet.jni.dir}" />
            <jvmarg value="-Dtet.searchpath=${tet.searchpath}" />
            <classpath refid="classpath" />
            <arg value="-index" />
            <arg value="${index.dir}" />
            <arg value="-docs" />
            <arg value="${root.dir}" />
        </java>
    </target>

    <target name="search" depends="compile">
        <java classname="com.pdflib.tet.lucene.SearchFiles" fork="true">
            <jvmarg value="-Djava.library.path=${tet.jni.dir}" />
            <classpath refid="classpath" />
            <arg value="-index" />
            <arg value="${index.dir}" />
        </java>
    </target>
    
    <target name="clean">
        <delete includeemptydirs="true">
            <fileset dir="${bin.dir}" includes="**/*" />
        </delete>
        <delete dir="${index.dir}" />
    </target>
</project>
