import java.io.File; import java.io.IOException; publicclassIndex{ publicstaticvoidmain(String[] args)throws IOException { //Codec codec = new SimpleTextCodec(); Codec codec = new HexinCodec(); //Codec codec = new Lucene46Codec(); String INDEX_DIR = "e:\\index"; Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_48); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_48, analyzer); iwc.setCodec(codec); IndexWriter writer = null; iwc.setOpenMode(OpenMode.CREATE); iwc.setUseCompoundFile(false); try { writer = new IndexWriter(FSDirectory.open(new File(INDEX_DIR)), iwc); Document doc = new Document(); doc.add(new TextField("title", "who are you, you are a man", Field.Store.YES)); doc.add(new TextField("content", "A long way to go there. Please drive a car", Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new TextField("title", "are you sure", Field.Store.YES)); doc.add(new TextField("content", "He is a good man. He is a driver", Field.Store.NO)); writer.addDocument(doc); writer.commit(); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
String index = "e:\\index"; IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(index))); IndexSearcher searcher = new IndexSearcher(reader); String queryString = "driver"; Query query = new TermQuery(new Term("content", queryString)); System.out.println("Searching for: " + query.toString()); Date start = new Date(); TopDocs results = searcher.search(query, null, 100); Date end = new Date(); System.out.println("Time: "+(end.getTime()-start.getTime())+"ms"); ScoreDoc[] hits = results.scoreDocs; int numTotalHits = results.totalHits; System.out.println(numTotalHits + " total matching documents"); for (int i = 0; i < hits.length; i++) { String output = ""; Document doc = searcher.doc(hits[i].doc); output += "doc="+hits[i].doc+" score="+hits[i].score; String title = doc.get("title"); if (title != null) { output += " " + title; } System.out.println(output); } reader.close(); } }
在Eclipse中运行Index.java,此时会报错 A SPI class of type org.apache.lucene.codecs.Codec with name ‘Lucene46’ does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath.The current classpath supports the following names:[]
#$interface = "1.0" Sub main ' turn on synchronous mode so we don't miss any data crt.Screen.Synchronous = True crt.Screen.Send "ssh test@192.168.1.1" & VbCr ' Wait for a tring that looks like "password: " or "Password: " crt.Screen.WaitForString "assword:" ' Send your password followed by a carriage return crt.Screen.Send "test" & VbCr ' turn off synchronous mode to restore normal input processing crt.Screen.Synchronous = False EndSub
1.反向索引 2.检索词和布尔查询: 并查询: +new +house 或者 new AND house 或查询: new house 或者 new OR house 排除查询: new house –rental 或者 new house NOT rental 短语查询: “new home” OR “new house” 3 bedrooms” AND “walk in closet” AND “granite countertops” 分组查询: New AND (house OR (home NOT improvement NOT depot NOT grown)) (+(buying purchasing -renting) +(home house residence –(+property -bedroom)))
范围查询: yearsOld:[18 TO 21] 18 <= x <= 21 yearsOld:{18 TO 21} 18 < x < 21 yearsOld:[18 TO 21} 18 <= x < 21 created:[2012-02-01T00:00.0Z TO 2012-08-02T00:00.0Z]
这段代码里,if not polyphonse判断里的句子只有在上面的for没有被break时才执行,也就是for循环执行时才执行,这种情况在编程中经常遇到,而python提供了for else循环语句,于是可以修改成:
1 2 3 4 5 6
for item in self.polyphone[key]: if chars.find(item[key]['context']) != -1: result.append(item[key]['pron'].strip()[:-1].lower()) break else : result.append(self.dict[key].split(",")[0].strip()[:-1].lower())