• R/O
  • SSH
  • HTTPS

nls: 提交


Commit MetaInfo

修订版13 (tree)
时间2011-05-09 19:41:37
作者linuxchecker

Log Message

moved core components independently

更改概述

差异

--- src/org/mathsci/distance/NldCore.java (nonexistent)
+++ src/org/mathsci/distance/NldCore.java (revision 13)
@@ -0,0 +1,37 @@
1+package org.mathsci.distance;
2+import java.util.*;
3+import java.io.*;
4+
5+class NldCore
6+{
7+ static final Properties properties = new Properties();
8+ static public String index;
9+ static File INDEX_DIR;
10+ static int max_pages;
11+ static int debug_level;
12+ static public boolean timewatch = false;
13+ static public long start_time = 0;
14+ protected NldCore()
15+ {
16+ try
17+ {
18+ InputStream rs = NldSearcher.class.getClassLoader().getResourceAsStream("nld.properties");
19+ if(rs==null) throw new IOException("Property file cannot be read");
20+ InputStreamReader inFile = new InputStreamReader(rs);
21+ properties.load(inFile);
22+ index = properties.getProperty("lucene.index.path");
23+ debug_level = Integer.parseInt(properties.getProperty("lucene.debug.level","0"));
24+ INDEX_DIR = new File(index);
25+ max_pages = new Integer(properties.getProperty("lucene.index.pages"));
26+ if("yes".equals(properties.getProperty("lucene.timewatch")) ||
27+ "true".equals(properties.getProperty("lucene.timewatch")) )
28+ {
29+ timewatch = true;
30+ }
31+ }catch(IOException e)
32+ {
33+ e.printStackTrace();
34+ }
35+ }
36+
37+}
--- src/org/mathsci/distance/NldSearcher.java (revision 12)
+++ src/org/mathsci/distance/NldSearcher.java (revision 13)
@@ -38,15 +38,10 @@
3838 import org.apache.lucene.store.Directory;
3939 import org.apache.lucene.store.RAMDirectory;
4040
41-public class NldSearcher {
41+public class NldSearcher extends NldCore {
4242
43- static final Properties properties = new Properties();
44- static public String index;
45- static File INDEX_DIR;
4643 static RAMDirectory RAM_INDEX_DIR;
4744 static public String IPADIC;
48- static public boolean timewatch = false;
49- static public long start_time = 0;
5045 static public NldSearcher search = new NldSearcher();
5146 static IndexReader reader;
5247 static IndexSearcher searcher;
@@ -53,23 +48,13 @@
5348
5449 public NldSearcher()
5550 {
51+ super();
5652 try
5753 {
58- InputStream rs = NldSearcher.class.getClassLoader().getResourceAsStream("nld.properties");
59- if(rs==null) throw new IOException("Property file cannot be read");
60- InputStreamReader inFile = new InputStreamReader(rs);
61- properties.load(inFile);
62- index = properties.getProperty("lucene.index.path");
63- INDEX_DIR = new File(index);
6454 IPADIC = properties.getProperty("ipadic.path");
6555
6656 // RAM_INDEX_DIR = new RAMDirectory();
6757
68- if("yes".equals(properties.getProperty("lucene.timewatch")) ||
69- "true".equals(properties.getProperty("lucene.timewatch")) )
70- {
71- timewatch = true;
72- }
7358 reader = IndexReader.open(FSDirectory.open(new File(index)), true);
7459 searcher = new IndexSearcher(reader);
7560
@@ -109,7 +94,7 @@
10994 String line = in.readLine();
11095 line = line.trim();
11196 Query query = parser.parse(line);
112-// System.out.println("Searching for: " + query.toString(field));
97+ System.out.println("Searching for: " + query.toString(field));
11398 double numHitsTotal = doStreamingSearch(searcher, query);
11499 return(numHitsTotal);
115100 }
@@ -122,10 +107,17 @@
122107 searcher.search(query, streamingHitCollector);
123108 ScoreDoc[] hits = streamingHitCollector.topDocs().scoreDocs;
124109 int numTotalHits = streamingHitCollector.getTotalHits();
125- System.out.println(numTotalHits + " total matching documents");
110+ System.out.println(numTotalHits + " total matching documents");
126111 int start = 0;
127112 int end = Math.min(numTotalHits, hitsPerPage);
128-
113+ if(debug_level>0)
114+ {
115+ for(int i=0;i<hits.length;++i)
116+ {
117+ Document d = searcher.doc(hits[i].doc);
118+ System.out.println("["+i+"]"+" "+d.get("path")+":"+d.getFields());
119+ }
120+ }
129121 return(numTotalHits);
130122 }
131123
--- src/org/mathsci/distance/NldCommand.java (revision 12)
+++ src/org/mathsci/distance/NldCommand.java (revision 13)
@@ -1,7 +1,9 @@
11 package org.mathsci.distance;
22
3+
34 import org.apache.commons.codec.binary.Base64;
45
6+import org.mathsci.distance.NldCore;
57 import org.mathsci.distance.NldIndexer;
68 import org.mathsci.distance.NldSearcher;
79 import org.apache.lucene.index.IndexWriter;
@@ -8,25 +10,19 @@
810 import org.apache.lucene.store.FSDirectory;
911 import org.apache.lucene.util.Version;
1012
11-import java.io.File;
12-import java.io.FileNotFoundException;
1313 import java.io.IOException;
14-import java.util.Date;
15-import java.util.Properties;
16-
17-import java.io.FileReader;
1814 import java.io.StringReader;
19-
20-
21-import org.apache.lucene.document.DateTools;
22-import org.apache.lucene.document.Field;
23-
2415 import java.io.BufferedReader;
2516 import java.io.InputStreamReader;
17+import java.util.Date;
18+import java.util.Properties;
19+import java.lang.Integer;
2620
2721 import org.apache.lucene.analysis.Analyzer;
2822 import org.apache.lucene.analysis.standard.StandardAnalyzer;
2923 import org.apache.lucene.document.Document;
24+import org.apache.lucene.document.DateTools;
25+import org.apache.lucene.document.Field;
3026 import org.apache.lucene.index.FilterIndexReader;
3127 import org.apache.lucene.index.IndexReader;
3228 import org.apache.lucene.queryParser.QueryParser;
@@ -37,38 +33,16 @@
3733 import org.apache.lucene.search.Scorer;
3834 import org.apache.lucene.search.TopScoreDocCollector;
3935
40-import java.lang.Integer;
4136
42-public class NldCommand {
43- static final Properties properties = new Properties();
44- static public String index;
45- static File INDEX_DIR;
46- static int max_pages;
47- static public boolean timewatch = false;
48- static public long start_time = 0;
37+public class NldCommand extends NldCore {
4938
50- static private void initNldCommand()
39+ public NldCommand()
5140 {
52- try
53- {
54- InputStreamReader inFile = new InputStreamReader(NldSearcher.class.getClassLoader().getResourceAsStream("nld.properties"));
55- properties.load(inFile);
56- index = properties.getProperty("lucene.index.path");
57- INDEX_DIR = new File(index);
58- max_pages = new Integer(properties.getProperty("lucene.index.pages"));
59- if("yes".equals(properties.getProperty("lucene.timewatch")) ||
60- "true".equals(properties.getProperty("lucene.timewatch")) )
61- {
62- timewatch = true;
63- }
64- }catch(IOException e)
65- {
66- e.printStackTrace();
67- }
41+ super();
6842 }
6943
7044 public static void main(String[] args) {
71- initNldCommand();
45+ NldCommand nc = new NldCommand();
7246
7347 if("indexer".equals(args[0]))
7448 {
@@ -78,7 +52,11 @@
7852 {
7953 try{
8054 NldSearcher searcher = new NldSearcher();
81- searcher.searcher(args[0]);
55+ String queries = args[1];
56+
57+ if(args.length>2) queries = queries.concat(" AND "+args[2]);
58+
59+ searcher.searcher(queries);
8260 }catch(Exception e)
8361 {
8462 e.printStackTrace();
--- bin/nld.sh (revision 12)
+++ bin/nld.sh (revision 13)
@@ -22,10 +22,10 @@
2222 echo "usage: " $0 "searcher <words>";
2323 exit 1;
2424 else
25- DATA="-queries $2"
25+ DATA="$2"
2626 if [ "X"$3 != "X" ];
2727 then
28- DATA2="-queries $3";
28+ DATA2="$3";
2929 fi
3030 $JAVA $OPTIONS -cp $NLD_JAR:$LIBS org.mathsci.distance.NldCommand searcher $DATA $DATA2
3131 fi
Show on old repository browser