Apache Lucene open-source search software
LUCENE-591: index meta keywords in contrib/demo
Robert Muirfe8274576962
diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txtindex 8be38816a0e..63b253af23d 100644--- a/lucene/contrib/CHANGES.txt+++ b/lucene/contrib/CHANGES.txt@@ -143,6 +143,9 @@ Bug fixes* LUCENE-590: Demo HTML parser gives incorrect summaries when title is repeated as a heading(Curtis d'Entremont via Robert Muir)++* LUCENE-591: The demo indexer now indexes meta keywords.+ (Curtis d'Entremont via Robert Muir)API Changesdiff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.javaindex 64ab05acc2e..67cafbf2fad 100644--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.java+++ b/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.java@@ -70,6 +70,11 @@ public class HTMLDocument {// Add the tag-stripped contents as a Reader-valued Text field so it will// get tokenized and indexed.doc.add(new Field("contents", parser.getReader()));++ // add any document keywords if they exist+ String keywords = parser.getMetaTags().getProperty("keywords");+ if (keywords != null)+ doc.add(new Field("contents", keywords, Field.Store.NO, Field.Index.ANALYZED));// Add the summary as a field that is stored and returned with// hit documents for display.diff --git a/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java b/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.javaindex 79e96dc287b..6fbe35187e8 100644--- a/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java+++ b/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java@@ -43,4 +43,24 @@ public class TestDemo extends LuceneTestCase {System.setOut(outSave);}}++ // LUCENE-591+ public void testIndexKeywords() throws Exception {+ File dir = getDataFile("test-files/html");+ File indexDir = new File(TEMP_DIR, "demoIndex2");+ IndexHTML.main(new String[] { "-create", "-index", indexDir.getPath(), dir.getPath() });+ File queries = getDataFile("test-files/queries2.txt");+ PrintStream outSave = System.out;+ try {+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();+ PrintStream fakeSystemOut = new PrintStream(bytes);+ System.setOut(fakeSystemOut);+ SearchFiles.main(new String[] { "-index", indexDir.getPath(), "-queries", queries.getPath()});+ fakeSystemOut.flush();+ String output = bytes.toString(); // intentionally use default encoding+ assertTrue(output.contains("1 total matching documents"));+ } finally {+ System.setOut(outSave);+ }+ }}diff --git a/lucene/contrib/demo/src/test/org/apache/lucene/demo/test-files/html/test2.html b/lucene/contrib/demo/src/test/org/apache/lucene/demo/test-files/html/test2.htmlnew file mode 100644index 00000000000..cddd3effa16--- /dev/null+++ b/lucene/contrib/demo/src/test/org/apache/lucene/demo/test-files/html/test2.html@@ -0,0 +1,9 @@+<html>+ <head>+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />+ <meta name="keywords" content="dogs,fish" />+ </head>+ <body>+ This document is actually not about cats!+ </body>+</html>diff --git a/lucene/contrib/demo/src/test/org/apache/lucene/demo/test-files/queries2.txt b/lucene/contrib/demo/src/test/org/apache/lucene/demo/test-files/queries2.txtnew file mode 100644index 00000000000..86cc85730b7--- /dev/null+++ b/lucene/contrib/demo/src/test/org/apache/lucene/demo/test-files/queries2.txt@@ -0,0 +1 @@++contents:dogs +contents:fish