You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Mila88 <ha...@gmail.com> on 2016/07/08 18:12:17 UTC

Using "escape"

I want to use escape with query parser, But I'm quite new and not sure how to
add it. Here is my example project, and here is the link to escape
http://lucene.apache.org/core/3_0_3/api/all/org/apache/lucene/queryParser/QueryParser.html#escape%28java.lang.String%29



import java.io.File;
import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

public class Searcher {
	
   IndexSearcher indexSearcher;
   QueryParser queryParser;
   Query query;
   
   public Searcher(String indexDirectoryPath) 
      throws IOException{
      Directory indexDirectory = 
         FSDirectory.open(new File(indexDirectoryPath));
      indexSearcher = new IndexSearcher(indexDirectory);
      queryParser = new QueryParser(Version.LUCENE_36,
         LuceneConstants.CONTENTS,
         new StandardAnalyzer(Version.LUCENE_36));
   }
   //QueryParser parser=new
QueryParser(Version.LUCENE_30,langCode,this.getAnalyzer());
   // Query query=parser.parse(queryString);
  // int maxSearchLength=1000;
  // TopDocs topDocs=searcher.search(query,null,maxSearchLength);
   public TopDocs search( String searchQuery) 
      throws IOException, ParseException{
      query = queryParser.parse(searchQuery);
      return indexSearcher.search(query, LuceneConstants.MAX_SEARCH);
   }

   
   
  //  get this document 
   public Document getDocument(ScoreDoc scoreDoc) 
      throws CorruptIndexException, IOException{
      return indexSearcher.doc(scoreDoc.doc);	
   }

   public void close() throws IOException{
      indexSearcher.close();
   }
}



--
View this message in context: http://lucene.472066.n3.nabble.com/Using-escape-tp4286398.html
Sent from the Lucene - Java Developer mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org