Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-909: Demo targets for running the demo.

Doron Cohen1de7b02e98b2
diff --git a/CHANGES.txt b/CHANGES.txt
index 4cfacbcc3af..8db53d880fa 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -265,6 +265,8 @@ Build
6. LUCENE-907: Include LICENSE.TXT and NOTICE.TXT in the META-INF dirs of
demo war, demo jar, and the contrib jars. (Michael Busch)
+
+ 7. LUCENE-909: Demo targets for running the demo. (Doron Cohen)
======================= Release 2.1.0 2007-02-14 =======================
diff --git a/src/demo/demo-build.template b/src/demo/demo-build.template
index 810bbde6d4b..da4197356b3 100644
--- a/src/demo/demo-build.template
+++ b/src/demo/demo-build.template
@@ -90,9 +90,72 @@
<target name="clean"
description="Removes contents of build directory">
<delete dir="${build.dir}"/>
+ <delete dir="${common.dir}/demo-text-dir"/>
+ <delete dir="${common.dir}/demo-html-dir"/>
</target>
-
+ <!-- ================================================================== -->
+ <!-- R U N T E X T I N D E X I N G D E M O -->
+ <!-- ================================================================== -->
+ <!-- -->
+ <!-- ================================================================== -->
+ <target name="demo-index-text" depends="jar-demo"
+ description="Run text indexing demo (index the sources of the demo).">
+ <echo>----- (1) Prepare dir ----- </echo>
+ <echo>cd ${common.dir} </echo>
+ <echo>rmdir demo-text-dir </echo>
+ <delete dir="${common.dir}/demo-text-dir"/>
+ <echo>mkdir demo-text-dir </echo>
+ <mkdir dir="${common.dir}/demo-text-dir"/>
+ <echo>cd demo-text-dir </echo>
+ <echo>----- (2) Index the files located under ${common.dir}/src ----- </echo>
+ <invoke-java class="IndexFiles" params="${common.dir}/src/demo" paramsDisplay="../src/demo" type="text"/>
+ </target>
+
+ <!-- ================================================================== -->
+ <!-- R U N T E X T S E A R C H D E M O -->
+ <!-- ================================================================== -->
+ <!-- -->
+ <!-- ================================================================== -->
+ <target name="demo-search-text" depends="jar-demo"
+ description="Run interactive search demo.">
+ <echo>----- Interactive search ----- </echo>
+ <echo>cd demo-text-dir </echo>
+ <invoke-java class="SearchFiles" params="-index index" paramsDisplay="-index index" type="text"/>
+ </target>
+
+
+ <!-- ================================================================== -->
+ <!-- R U N H T M L I N D E X I N G D E M O -->
+ <!-- ================================================================== -->
+ <!-- -->
+ <!-- ================================================================== -->
+ <target name="demo-index-html" depends="jar-demo"
+ description="Run html indexing demo (index the javadocs).">
+ <echo>----- (1) Prepare dir ----- </echo>
+ <echo>cd ${common.dir} </echo>
+ <echo>rmdir demo-html-dir </echo>
+ <delete dir="${common.dir}/demo-html-dir"/>
+ <echo>mkdir demo-html-dir </echo>
+ <mkdir dir="${common.dir}/demo-html-dir"/>
+ <echo>cd demo-html-dir </echo>
+ <echo>----- (2) Index the files located under ${common.dir}/src ----- </echo>
+ <invoke-java class="IndexFiles" params="${common.dir}/docs/api" paramsDisplay="../docs/api" type="html"/>
+ </target>
+
+ <!-- ================================================================== -->
+ <!-- R U N H T M L S E A R C H D E M O -->
+ <!-- ================================================================== -->
+ <!-- -->
+ <!-- ================================================================== -->
+ <target name="demo-search-html" depends="jar-demo"
+ description="Run interactive search demo.">
+ <echo>----- Interactive search ----- </echo>
+ <echo>cd demo-html-dir </echo>
+ <invoke-java class="SearchFiles" params="-index index" paramsDisplay="-index index" type="html"/>
+ </target>
+
+
<!--+
| M A C R O S
+-->
@@ -115,4 +178,26 @@
</sequential>
</macrodef>
+ <macrodef name="invoke-java">
+ <attribute name="class"/>
+ <attribute name="params"/>
+ <attribute name="paramsDisplay"/>
+ <attribute name="type"/>
+ <sequential>
+ <echo>java -classpath "../${core.name}.jar;../${demo.name}.jar" org.apache.lucene.demo.@{class} @{paramsDisplay} </echo>
+ <java classname="org.apache.lucene.demo.@{class}"
+ dir="${common.dir}/demo-@{type}-dir"
+ fork="true"
+ failonerror="true"
+ maxmemory="128m"
+ >
+ <arg value="@{params}"/>
+ <classpath>
+ <pathelement location="${common.dir}/${core.name}.jar"/>
+ <pathelement location="${common.dir}/${demo.name}.jar"/>
+ </classpath>
+ </java>
+ </sequential>
+ </macrodef>
+
</project>
diff --git a/src/demo/org/apache/lucene/demo/SearchFiles.java b/src/demo/org/apache/lucene/demo/SearchFiles.java
index 182c8c56059..7308908ac04 100644
--- a/src/demo/org/apache/lucene/demo/SearchFiles.java
+++ b/src/demo/org/apache/lucene/demo/SearchFiles.java
@@ -111,13 +111,17 @@ public class SearchFiles {
QueryParser parser = new QueryParser(field, analyzer);
while (true) {
if (queries == null) // prompt the user
- System.out.print("Query: ");
+ System.out.println("Enter query: ");
String line = in.readLine();
if (line == null || line.length() == -1)
break;
+ line = line.trim();
+ if (line.length() == 0)
+ break;
+
Query query = parser.parse(line);
System.out.println("Searching for: " + query.toString(field));
@@ -161,7 +165,7 @@ public class SearchFiles {
break;
if (hits.length() > end) {
- System.out.print("more (y/n) ? ");
+ System.out.println("more (y/n) ? ");
line = in.readLine();
if (line.length() == 0 || line.charAt(0) == 'n')
break;