Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 50219 invoked from network); 20 Dec 2007 14:36:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Dec 2007 14:36:44 -0000 Received: (qmail 68547 invoked by uid 500); 20 Dec 2007 14:36:25 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 68517 invoked by uid 500); 20 Dec 2007 14:36:25 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 68506 invoked by uid 99); 20 Dec 2007 14:36:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2007 06:36:25 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of erickerickson@gmail.com designates 209.85.128.190 as permitted sender) Received: from [209.85.128.190] (HELO fk-out-0910.google.com) (209.85.128.190) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2007 14:36:01 +0000 Received: by fk-out-0910.google.com with SMTP id z23so3268001fkz.5 for ; Thu, 20 Dec 2007 06:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=ErHcy2l7nIixdNP9IZOLxUlkvoHUo9tbUyjUTf3YZMU=; b=smaRJjMsWBB7cgRXTHcPtetaWy+JJgeuNb+wcHZVWS5rpUWLYmuxYpXgOU6GMXQRdhrgV4KpThJLhCen6xMt/93oMofD1Q9o/KLIl1GCSPID9rs9B/YIvvGMCHfaqfUsXv1qrAOZJOEMQNtzihQlo521IKfhDQfTHBsW9xdHKGA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=ZiO8LAQzo7iipw7RrN1hsgynHW78Dh7GfdVcxpEn2yT0IXQMpwEw9sdQWOzC0HnxVzjAUODbgK+ePPXCXtqj9eRXbXvdhJLp5/RVXNu+ethaJxhlXtV+5FhU2pHZ0slbMQUjVgL85CENCoYEiTzGVxumZWYOv0cOgoKT2yvp7G4= Received: by 10.82.107.15 with SMTP id f15mr93103buc.0.1198161362824; Thu, 20 Dec 2007 06:36:02 -0800 (PST) Received: by 10.82.191.6 with HTTP; Thu, 20 Dec 2007 06:36:02 -0800 (PST) Message-ID: <359a92830712200636w26deccd8pbd68fdec1154ade8@mail.gmail.com> Date: Thu, 20 Dec 2007 09:36:02 -0500 From: "Erick Erickson" To: java-user@lucene.apache.org Subject: Re: Problem with Escape characters in lucene demo search In-Reply-To: <012101c842bb$37584b30$a608e190$@ca> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_20631_4372377.1198161362817" References: <00e801c8428b$807d93e0$8178bba0$@ca> <359a92830712191641g1c1983c6r2c1fc471a4b5247f@mail.gmail.com> <012101c842bb$37584b30$a608e190$@ca> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_20631_4372377.1198161362817 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline use Luke. Google Lucene luke and you'll find it..... You can use it to examine the contents of your index in many different ways. It's invaluable when exploring the different analyzers and making sure that your index has what you *think* it has. Erick On Dec 19, 2007 10:48 PM, Baljeet Dhaliwal wrote: > How do i check in my index. It looks like bytecode to me. My searched file > does contain word "login" with quotes. > > B > > -----Original Message----- > From: Erick Erickson [mailto:erickerickson@gmail.com] > Sent: December-19-07 4:41 PM > To: java-user@lucene.apache.org > Subject: Re: Problem with Escape characters in lucene demo search > > I'm pretty sure StandardAnalyzer is stripping these off. Have you looked > in your index to see if "longin" (with quotes) is even in there? I think > you'll find that it's not. > > Best > Erick > > On Dec 19, 2007 5:07 PM, Baljeet Dhaliwal wrote: > > > Hi there > > > > > > > > I am having a problem in using escape characters with lucene demo code. > I > > used the following code for IndexFiles and SearchFiles. The code works > > fine > > for regular searching and also with wildcard. However, when I try to use > > escape characters, somehow it strips them off. For example: when i > search > > for "login" through "\"login\"" or for that matter try to use any > escape > > character, lucene strips the escape characters and looks for the text > only > > (login as against "login") > > > > > > > > Can someone help please. > > > > > > > > Cheers > > > > B > > > > > > > > > > > > IndexFiles.java > > > > > > > > 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.document.Document; > > > > import org.apache.lucene.index.IndexWriter; > > > > > > > > import java.io.BufferedReader; > > > > import java.io.File; > > > > import java.io.FileNotFoundException; > > > > import java.io.IOException; > > > > import java.io.InputStreamReader; > > > > 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 all text files under a directory. */ > > > > public static void main(String[] args) { > > > > String usage = "java org.apache.lucene.demo.IndexFiles > > "; > > > > /*if (args.length == 0) { > > > > System.err.println("Usage: " + usage); > > > > System.exit(1); > > > > }*/ > > > > > > > > /*if (INDEX_DIR.exists()) { > > > > System.out.println("Cannot save index to '" +INDEX_DIR+ "' > directory, > > please delete it first"); > > > > System.exit(1); > > > > }*/ > > > > > > > > //final File docDir = new File(args[0]); > > > > //File docDir = new File(args[0]); > > > > File docDir = new File("F:/bsd-logs/logs"); > > > > 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 { > > > > System.out.println("Indexing to directory '" +INDEX_DIR+ "'..."); > > > > BufferedReader in = null; > > > > int i = 0; > > > > while (i==0){ > > > > IndexWriter writer = new IndexWriter(INDEX_DIR, new > > StandardAnalyzer(), true); > > > > > > > > indexDocs(writer, docDir); > > > > System.out.println("Optimizing..."); > > > > writer.optimize(); > > > > in = new BufferedReader(new > > InputStreamReader(System.in, "UTF-8")); > > > > i=1; > > > > /*System.out.println("Enter another directory: "); > > > > > > > > docDir = new File(in.readLine()); > > > > writer.close(); > > > > String args1[] = > > {"\\users\\baljeet\\documents\\rees\\programs\\ > > "}; > > > > DeleteFiles.main(args1);*/ > > > > } > > > > > > > > > > > > > > > > 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 { > > > > Document doc = FileDocument.Document(file); > > > > System.out.println("Path = "+doc.getField("path")); > > > > 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) { > > > > ; > > > > } > > > > } > > > > } > > > > } > > > > > > > > } > > > > > > > > > > > > > > > > SearchFiles.java > > > > > > > > > > > > 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.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.QueryParser; > > > > import org.apache.lucene.search.Hits; > > > > import org.apache.lucene.search.IndexSearcher; > > > > import org.apache.lucene.search.Query; > > > > import org.apache.lucene.search.Searcher; > > > > > > > > import java.io.BufferedReader; > > > > import java.io.FileReader; > > > > import java.io.IOException; > > > > import java.io.InputStreamReader; > > > > import java.util.Collection; > > > > import java.util.Date; > > > > import java.util.Hashtable; > > > > import java.util.Iterator; > > > > > > > > /** 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. */ > > > > public 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 usage = > > > > "Usage: java org.apache.lucene.demo.SearchFiles [-index dir] > [-field > > f] [-repeat n] [-queries file] [-raw] [-norms field]"; > > > > if (args.length > 0 && ("-h".equals(args[0]) || > > "-help".equals(args[0]))) { > > > > System.out.println(usage); > > > > System.exit(0); > > > > } > > > > > > > > String index = "index"; > > > > String field = "contents"; > > > > String queries = null; > > > > int repeat = 0; > > > > boolean raw = false; > > > > String normsField = null; > > > > > > > > for (int i = 0; i < args.length; i++) { > > > > if ("-index".equals(args[i])) { > > > > index = args[i+1]; > > > > i++; > > > > } else if ("-field".equals(args[i])) { > > > > field = args[i+1]; > > > > i++; > > > > } else if ("-queries".equals(args[i])) { > > > > queries = args[i+1]; > > > > i++; > > > > } else if ("-repeat".equals(args[i])) { > > > > repeat = Integer.parseInt(args[i+1]); > > > > i++; > > > > } else if ("-raw".equals(args[i])) { > > > > raw = true; > > > > } else if ("-norms".equals(args[i])) { > > > > normsField = args[i+1]; > > > > i++; > > > > } > > > > } > > > > > > > > IndexReader reader = IndexReader.open(index); > > > > > > > > if (normsField != null) > > > > reader = new OneNormsReader(reader, normsField); > > > > > > > > Collection h = > > reader.getFieldNames(IndexReader.FieldOption.INDEXED); > > > > Iterator it = h.iterator(); > > > > while (it.hasNext()){ > > > > System.out.println("Iterator Value = "+it.next()); > > > > > > > > } > > > > > > > > > > > > > > > > Searcher searcher = new IndexSearcher(reader); > > > > Analyzer analyzer = new StandardAnalyzer(); > > > > > > > > BufferedReader in = null; > > > > if (queries != null) { > > > > in = new BufferedReader(new FileReader(queries)); > > > > } else { > > > > in = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); > > > > } > > > > QueryParser parser = new QueryParser(field, analyzer); > > > > while (true) { > > > > if (queries == null) // prompt the user > > > > System.out.println("Enter query: "); > > > > > > > > String line = in.readLine(); > > > > > > > > if (line == null || line.length() == -1) > > > > break; > > > > > > > > line = line.trim(); > > > > if (line.length() == 0) > > > > break; > > > > System.out.println("line 1= "+line); > > > > // line = QueryParser.escape(line); > > > > System.out.println("line 2= "+line); > > > > Query query = parser.parse(line); > > > > > > > > System.out.println("Searching for: " + query.toString(field)); > > > > > > > > Hits hits = searcher.search(query); > > > > > > > > > > > > if (repeat > 0) { // repeat & time as > > benchmark > > > > Date start = new Date(); > > > > for (int i = 0; i < repeat; i++) { > > > > hits = searcher.search(query); > > > > } > > > > Date end = new Date(); > > > > System.out.println("Time: "+(end.getTime()-start.getTime > ())+"ms"); > > > > } > > > > > > > > > > > > System.out.println(hits.length() + " total matching documents"); > > > > > > > > final int HITS_PER_PAGE = 10; > > > > for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) > { > > > > int end = Math.min(hits.length(), start + HITS_PER_PAGE); > > > > for (int i = start; i < end; i++) { > > > > > > > > if (raw) { // output raw format > > > > System.out.println("doc="+hits.id(i)+" > score="+hits.score(i)); > > > > continue; > > > > } > > > > > > > > Document doc = hits.doc(i); > > > > String path = doc.get("path"); > > > > if (path != null) { > > > > System.out.println((i+1) + ". " + path); > > > > //getSearchedLine(path, "kvoll"); > > > > String title = doc.get("title"); > > > > if (title != null) { > > > > System.out.println(" Title: " + doc.get("title")); > > > > } > > > > } else { > > > > System.out.println((i+1) + ". " + "No path for this > document"); > > > > } > > > > } > > > > > > > > if (queries != null) // non-interactive > > > > break; > > > > > > > > if (hits.length() > end) { > > > > System.out.println("more (y/n) ? "); > > > > line = in.readLine(); > > > > if (line.length() == 0 || line.charAt(0) == 'n') > > > > break; > > > > } > > > > } > > > > } > > > > reader.close(); > > > > } > > > > } > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > > ------=_Part_20631_4372377.1198161362817--