2009年8月6日
摘要: 1<%@page contentType="text/html; charset=GBK"%>
2<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
3<%@ taglib uri="http:/... 阅读全文
html
<p><a href="#" class="run">Run</a></p>
<div id="box">
</div>
css
<style type="text/css">
body {}{}{}{
margin: 20px auto;
padding: 0;
width: 580px;
font: 80%/120% Arial, Helvetica, sans-serif;
}
a {}{}{}{
font-weight: bold;
color: #000000;
}
#box {}{}{}{
background: #6699FF;
height: 100px;
width: 100px;
position: relative;
}
</style>
jquery
1$(document).ready(function(){
2 $(".run").click(function(){
3
4 $("#box").animate({opacity: "0.1", left: "+=400"}, 1200)
5 .animate({opacity: "0.4", top: "+=160", height: "20", width: "20"}, "slow")
6 .animate({opacity: "1", left: "0", height: "100", width: "100"}, "slow")
7 .animate({top: "0"}, "fast")
8 .slideUp()
9 .slideDown("slow")
10 return false;
11
12 });
13});
(?=xxx)
|
正向预搜索(向右)
|
正向预搜索,判断当前位置右侧是否能匹配指定表达式
|
(?!xxx)
|
正向预搜索否定,判断当前位置右侧是否不能够匹配指定表达式
|
(?<=xxx)
|
反向预搜索(向左)
|
反向预搜索,判断当前位置左侧是否能够匹配指定表达式
|
(?<!xxx)
|
反向预搜索否定,判断当前位置左侧是否不能够匹配指定表达式
|
1 function batchProcessData(data,telArr,index){
2 if(data==0){
3 var option = new Option(telArr[index],telArr[index]);
4 var counts = $('bindTel').options.length;
5 $('bindTel').options[counts]=option;
6 var restrictionObj = $('bindTel');
7 var allNum =",";
8 for(i=0;i<restrictionObj.options.length;i++){
9 var value = restrictionObj.options[i].value;
10 allNum += value+',';
11 }
12 $('bindTelNo').value=allNum;
13 }
14 index +=1;
15 if(index==telArr.length){
16 return;
17 }
18 var fieldNameArr = [];
19 var fieldValueArr = [];
20 fieldNameArr[0]='tel_no';
21 fieldValueArr[0]=telArr[index];
22 sysManagerService.isExist('t_user_bind',fieldNameArr[0],fieldValueArr[0],{
23 callback:
24 function(data){
25 batchProcessData(data,telArr,index);
26 }
27 });
28 }
1 function batchAddTel(){
2 var telnum = $('telNo');
3 var telArr = telnum.value.split(/[^\d-]/g);
4 var effTelArr = new Array();
5 for(var i=0;i<telArr.length;i++){
6 if(""==telArr[i]){
7 continue;
8 }
9 var patrn=/(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^[0-9]{11}$)/;
10 if (!patrn.test(telArr[i])){
11 continue;
12 }
13 if($('bindTelNo').value.indexOf(','+telArr[i]+',') !=-1){
14 continue;
15 }
16 effTelArr.push(telArr[i]);
17 }
18 effTelArr = unique_Array(effTelArr);
19 if(effTelArr.length > 0){
20 var fieldNameArr = [];
21 var fieldValueArr = [];
22 fieldNameArr[0]='tel_no';
23 fieldValueArr[0]=effTelArr[0];
24 sysManagerService.isExist('t_user_bind',fieldNameArr[0],fieldValueArr[0],{//回调函数调用多个参数
25 callback:
26 function(data){
27 batchProcessData(data,effTelArr,0);
28 }
29 });
30 }
31 }
package org.apache.lucene.demo;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.FilterIndexReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.HitCollector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.TopDocCollector;
/** Simple command-line based search demo. */
public class SearchFiles {
/** Use the norms from one field for all fields. Norms are read into memory,
* using a byte of memory per document per searched field. This can cause
* search of large collections with a large number of fields to run out of
* memory. If all of the fields contain only a single token, then the norms
* are all identical, then single norm vector may be shared. */
private static class OneNormsReader extends FilterIndexReader {
private String field;
public OneNormsReader(IndexReader in, String field) {
super(in);
this.field = field;
}
public byte[] norms(String field) throws IOException {
return in.norms(this.field);
}
}
private SearchFiles() {}
/** Simple command-line based search demo. */
public static void main(String[] args) throws Exception {
String index = "index";
String field = "content";
boolean multipleFields = true;
IndexReader reader = IndexReader.open(index);//IndexReader 根据 index 指定的路径 访问索引,扫描索引。
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer();
BufferedReader in =new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
while (true) {
System.out.println("Enter query: ");
String line = in.readLine();
if (line == null || line.length() == -1)
break;
line = line.trim();
if (line.length() == 0)
break;
if (!multipleFields) {
QueryParser parser = new QueryParser(field, analyzer);
Query query = parser.parse(field);// 根据指定的单个field查询
parser.setDefaultOperator(parser.OR_OPERATOR.OR);
//多个字符串以空格份格时,OR : a b 含有a或b均可。
//AND a b 必须含有 a和b。
doPagingSearch(searcher, query);
} else {
String[] fields = new String[2];
fields[0] = "contents";
fields[1] = "name";
BooleanClause.Occur[] flags = new BooleanClause.Occur[] {
BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
//根据多个field查询时。should,should查询字段在 name或是contents任何一个中,均做为一条记录返回。
//must,must .必须 即在 name 中,又在contents 中。
Query query = MultiFieldQueryParser.parse(line, fields, flags,
analyzer);
doPagingSearch(searcher, query);
}
}
reader.close();
}
/**
* This method uses a custom HitCollector implementation which simply prints out
* the docId and score of every matching document.
*
* This simulates the streaming search use case, where all hits are supposed to
* be processed, regardless of their relevance.
*/
public static void doPagingSearch( Searcher searcher, Query query) throws IOException {
// Collect enough docs to show 5 pages
TopDocCollector collector = new TopDocCollector(20);//最多结果集个数。
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
int numTotalHits = collector.getTotalHits();//搜索到的符合条件的记录总条数。
System.out.println(numTotalHits + " total matching documents");
for(int i=0;i<numTotalHits;i++){
Document doc = searcher.doc(hits[i].doc);
System.out.println("path.."+doc.get("path"));
System.out.println("modified.."+doc.get("modified"));
System.out.println("name.."+doc.get("name"));
System.out.println("parent"+doc.get("parent"));
System.out.println("content..."+doc.get("content"));
}
}
}
package org.apache.lucene.demo;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
/** Index all text files under a directory. */
public class IndexFiles {
private IndexFiles() {}
static final File INDEX_DIR = new File("index");//索引止录。建在当前目录的/index下
/** Index all text files under a directory. */
public static void main(String[] args) {//args[0] 文件路径. main 方法:对args[0]指定的文件路径下的所有文件建立索引。
final File docDir = new File(args[0]);
if (!docDir.exists() || !docDir.canRead()) {
System.out .println("Document directory '" + docDir.getAbsolutePath() + "' does not exist or is not readable, please check the path");
System.exit(1);
}
Date start = new Date();
try {
IndexWriter writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
//IndexWriter负责创建和维护索引
//IndexWriter(String path, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl)
//path:路径 Analyzer:文本分析器 create:是否创建新索引 mfl 最大field数量
System.out.println("Indexing to directory '" + INDEX_DIR + "'...");
indexDocs(writer, docDir);
System.out.println("Optimizing...");
writer.optimize();//优化索引
writer.close();//关闭
Date end = new Date();
System.out.println(end.getTime() - start.getTime() + " total milliseconds");
} catch (IOException e) {
System.out.println(" caught a " + e.getClass()
+ "\n with message: " + e.getMessage());
}
}
static void indexDocs(IndexWriter writer, File file) throws IOException {
// do not try to index files that cannot be read
if (file.canRead()) {
if (file.isDirectory()) {
String[] files = file.list();
// an IO error could occur
if (files != null) {
for (int i = 0; i < files.length; i++) {
indexDocs(writer, new File(file, files[i]));
}
}
} else {
System.out.println("adding " + file);
try {
writer.addDocument(FileDocument.Document(file));
}
// at least on windows, some temporary files raise this
// exception with an "access denied" message
// checking if the file can be read doesn't help
catch (FileNotFoundException fnfe) {
;
}
}
}
}
}
package org.apache.lucene.demo;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File;
import java.io.FileReader;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
/** A utility for making Lucene Documents from a File. */
public class FileDocument {
public static Document Document(File f)
throws java.io.FileNotFoundException {
// make a new, empty document
Document doc = new Document();
doc.add(new Field("contents", new FileReader(f)));
doc.add(new Field("path", f.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.add(new Field("modified", DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE),Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("name",f.getName(),Field.Store.YES,Field.Index.NOT_ANALYZED));
//Field
// return the document
return doc;
}
private FileDocument() {}
}
<html>
<body>
<script type="text/javascript">
function sortkids(e) {
// This is the element whose children we are going to sort
if (typeof e == "string") e = document.getElementById(e);
// Transfer the element (but not text node) children of e to a real array
var kids = [];
for(var x = e.firstChild; x != null; x = x.nextSibling)
if (x.nodeType == 1 /* Node.ELEMENT_NODE */) kids.push(x);
// Now sort the array based on the text content of each kid.
// Assume that each kid has only a single child and it is a Text node
kids.sort(function(n, m) { // This is the comparator function for sorting
var s = n.firstChild.data; // text of node n
var t = m.firstChild.data; // text of node m
if (s < t) return -1; // n comes before m
else if (s > t) return 1; // n comes after m
else return 0; // n and m are equal
});
// Now append the kids back into the parent in their sorted order.
// When we insert a node that is already part of the document, it is
// automatically removed from its current position, so reinserting
// these nodes automatically moves them from their old position
// Note that any text nodes we skipped get left behind, however.
for(var i = 0; i < kids.length; i++) e.appendChild(kids[i]);
}
</script>
<ul id="list"> <!-- This is the list we'll sort -->
<li>one<li>two<li>three<li>four <!-- items are not in alphabetical order -->
</ul>
<!-- this is the button that sorts the list -->
<button onclick="sortkids('list')">Sort list</button>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="GBK" xml:lang="GBK">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title></title>
<script type="text/javascript">
function search(str,pattern)
{
alert(str.search(pattern));
}
function testAA(){
var s1 = '"abc\'';
var s2 = '\'abc\'';
var pattern1 = /['"][^'"]*['"]/;
var pattern2 = /(['"])[^'"]*\1/;
<!-- alert(s1.search(pattern1));-->
<!-- alert(s1.search(pattern2));-->
<!-- alert(s2.search(pattern1));-->
<!-- alert(s2.search(pattern2));-->
<!-- var s3 = 'JavaScriptscript';-->
<!-- var s4 = 'JavaScriptScript';-->
<!-- var pattern3 = /(Java([sS]cript))\2/;-->
<!-- alert(s3.search(pattern3));-->
<!-- alert(s4.search(pattern3));-->
var s5 = 'ABCC';
var pattern4 = /(A)(B)(C)\2/;
var pattern5 = /(A)(?:B)(C)\2/;
alert(s5.search(pattern4));
alert(s5.search(pattern5));
}
function testReplace(){
var p1 = /ab/;
var p2 =/ab/g;
var text = 'abcdefgab';
<!-- alert( text.replace(p1,'11'));-->
<!-- alert( text.replace(p2,'11'));-->
var p3 = /(ab)(cd)/;
var p4 = /(ab)(cd)/g;
var t3 = 'abcdabcd';
alert(t3.replace(p3,'$1'));
alert(t3.replace(p4,'$1'));
alert(t3.replace(p3,'$2'));
alert(t3.replace(p4,'$2'));
}
function testMatch(){
var s = 'a1b2c3d4';
<!-- var p =/(\w\d)/;-->
<!-- var a = s.match(p);-->
<!-- alert(a.length);-->
<!-- for(x in a){-->
<!-- alert(a[x]);-->
<!-- }-->
<!-- var p1 = /(\w\d)/g;-->
<!-- var a1 = s.match(p1);-->
<!-- alert(a1.length);-->
<!-- for(x in a1){-->
<!-- alert(a1[x]);-->
<!-- }-->
var s2 = '(a1)(b2)(c3)(d4)';
var p2 = /(\w\d)/;
var a2 = s2.match(p2);
alert(a2.length);
for(x in a2){
alert(a2[x]);
}
}
function testSplit(){
var s1 = 'a , b , c';
<!-- var a1 = s1.split(',');-->
<!-- alert(a1.length);-->
<!-- for(x in a1){-->
<!-- alert(a1[x]+a1[x].length);-->
<!-- }-->
var p1 = /\s,\s/;
var a2 = s1.split(p1);
alert(a2.length);
for(x in a2){
alert(a2[x]+a2[x].length);
}
}
function testNewReg(){
var p = new RegExp('\\d');
var p1 = new RegExp('\\d','g');
var p2 = new RegExp('^\\d');
var s = 'a12345';
alert(s.replace(p,'a'));
alert(s.replace(p1,'a'));
alert(s.replace(p2,'a'));
}
function testExec(){
var p = /Java/g;
var t = 'JavaScript is more fun than Java!';
var r;
while((r=p.exec(t))!=null){
alert(r.length+'..matched...'+r[0]+'..positon..'+r.index +'..next..'+p.lastIndex);
}
var p1 = /Java/;
while((r=p1.exec(t))!=null){
alert(r.length+'..matched...'+r[0]+'..positon..'+r.index +'..next..'+p1.lastIndex);
}
}
function testTest(){
var p = /java/i;
alert(p.test('JavaScript'));
}
</script>
</head>
<body>
<form action="">
<a href="#" onclick="search()">search</a>
<a href="#" onclick="search()">dddd</a>
<input type="button" value="search('124!abc','(abc)')" onclick="search('124!abc','(abc)')"></input>
<input type="button" value="search('124!abc','(abc){2,}')" onclick="search('124!abc','(abc){2,}')"></input>
<input type="button" value="search('aab','a*b')" onclick="search('aab','a*b')"></input>
<input type="button" value="search('aab','a*?b')" onclick="search('aab','a*?b')"></input>
<input type="button" value="test" onclick="testAA()"></input>
<br/>
<input type="button" value="testReplace" onclick="testReplace()"></input>
<input type="button" value="testMatch" onclick="testMatch()"></input>
<input type="button" value="testSplit" onclick="testSplit()"></input>
<input type="button" value="testNewReg" onclick="testNewReg()"></input>
<input type="button" value="testExec" onclick="testExec()"></input>
<input type="button" value="testTest" onclick="testTest()"></input>
</form>
</body>
</html>