Package org.apache.lucene.queryparser.classic

Examples of org.apache.lucene.queryparser.classic.QueryParser


    LogInfo.begin_track("Constructing Searcher");
    if (!searchingStrategy.equals("exact") && !searchingStrategy.equals("inexact"))
      throw new RuntimeException("Bad searching strategy: " + searchingStrategy);
    this.searchStrategy = searchingStrategy;

    queryParser = new QueryParser(
        Version.LUCENE_44,
        FbIndexField.TEXT.fieldName(),
        searchingStrategy.equals("exact") ? new KeywordAnalyzer() : new StandardAnalyzer(Version.LUCENE_44));
    LogInfo.log("Opening index dir: " + indexDir);
    IndexReader indexReader = DirectoryReader.open(SimpleFSDirectory.open(new File(indexDir)));
View Full Code Here


    }
               
    private int doSearch(String searchPhrase, int maxNumberOfHits, Version luenceVersion) throws NullPointerException, ParseException, IOException {
        LOG.trace("*** Search Phrase: {} ***", searchPhrase);

        QueryParser parser = new QueryParser(luenceVersion, "contents", analyzer);
        Query query = parser.parse(searchPhrase);
        TopScoreDocCollector collector = TopScoreDocCollector.create(maxNumberOfHits, true);
        indexSearcher.search(query, collector);
        hits = collector.topDocs().scoreDocs;
       
        LOG.trace("*** Search generated {} hits ***", hits.length);
View Full Code Here

         TopDocs topDoc = null;
         if ( text.indexOf( '-' ) == -1 ) {
            q = new TermQuery( new Term( iv_lookupFieldName, text ) );
            topDoc = iv_searcher.search( q, iv_maxHits );
         } else // needed the KeyworkAnalyzer for situations where the hypen was included in the f-word
            final QueryParser query = new QueryParser( Version.LUCENE_40, iv_lookupFieldName, new KeywordAnalyzer() );
            try {
               //CTAKES-63 - I believe all of the chars in the str token should be escaped to avoid issues such as a token ending with ']'
               //topDoc = iv_searcher.search(query.parse(text.replace('-', ' ')), iv_maxHits);
               final String escaped = QueryParserBase.escape( text.replace( '-', ' ' ) );
               topDoc = iv_searcher.search( query.parse( escaped ), iv_maxHits );
            } catch ( ParseException e ) {
               // thrown by QueryParser.parse()
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
View Full Code Here

                String field = LuceneUtil.encodeQName(qname, db.getSymbols());

                Analyzer analyzer = worker.getAnalyzer(null, qname, broker, docs);

                QueryParser parser = new QueryParser(LuceneIndex.LUCENE_VERSION_IN_USE, field, analyzer);

                worker.setOptions(options, parser);

                Query query = parser.parse(queryStr);

                searcher.search(query, collector);
            }
           
            return collector.getFacetResults();
View Full Code Here

        }
    }

    public ClassicQueryParserWrapper(String field, Analyzer analyzer) {
        super(field, analyzer);
        parser = new QueryParser(LuceneIndex.LUCENE_VERSION_IN_USE, field, analyzer);
    }
View Full Code Here

    Analyzer analyzer = new FNLPAnalyzer(Version.LUCENE_47);
    // Now search the index:
    DirectoryReader ireader = DirectoryReader.open(dir);
    IndexSearcher isearcher = new IndexSearcher(ireader);
    // Parse a simple query that searches for "text":
    QueryParser parser = new QueryParser(Version.LUCENE_47, "content", analyzer);
    Query query = parser.parse("保修费用");
    ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
   
    System.out.println("Hello World");
    // Iterate through the results:
    for (int i = 0; i < hits.length; i++) {
View Full Code Here

                String field = LuceneUtil.encodeQName(qname, db.getSymbols());

                Analyzer analyzer = worker.getAnalyzer(null, qname, broker, docs);

                QueryParser parser = new QueryParser(LuceneIndex.LUCENE_VERSION_IN_USE, field, analyzer);

                worker.setOptions(options, parser);

                Query query = parser.parse(queryStr);
               
                collector.qname = qname;
                collector.query = query;

                searcher.search(query, collector);
View Full Code Here

    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(
        filepath)));
    indexSearcher = new IndexSearcher(reader);
    analyzer = new StandardAnalyzer(Version.LUCENE_48);
    if (fieldName.equalsIgnoreCase(Indexer.LABEL_FIELD_NAME)) {
      parser = new QueryParser(Version.LUCENE_48,
          Indexer.LABEL_FIELD_NAME, analyzer);
    } else {
      parser = new QueryParser(Version.LUCENE_48,
          Indexer.CONTENT_FIELD_NAME, analyzer);
    }

  }
View Full Code Here

        try {
            Directory directory = textIndex.getDirectory() ;
            Analyzer analyzer = textIndex.getAnalyzer() ;
            IndexReader indexReader = DirectoryReader.open(directory) ;
            IndexSearcher indexSearcher = new IndexSearcher(indexReader);
            QueryParser queryParser = new QueryParser(TextIndexLucene.VER, textIndex.getDocDef().getPrimaryField(), analyzer);
            Query query = queryParser.parse("*:*");
            ScoreDoc[] sDocs = indexSearcher.search(query, 1000).scoreDocs ;
            for ( ScoreDoc sd : sDocs ) {
                System.out.println("Doc: "+sd.doc) ;
                Document doc = indexSearcher.doc(sd.doc) ;
                // Don't forget that many fields aren't stored, just indexed.
View Full Code Here

        try {
            Directory directory = spatialIndex.getDirectory() ;
            Analyzer analyzer = spatialIndex.getAnalyzer() ;
            IndexReader indexReader = DirectoryReader.open(directory) ;
            IndexSearcher indexSearcher = new IndexSearcher(indexReader);
            QueryParser queryParser = new QueryParser(SpatialIndexLucene.VER, spatialIndex.getDocDef().getEntityField(), analyzer);
            Query query = queryParser.parse("*:*");
            ScoreDoc[] sDocs = indexSearcher.search(query, 1000).scoreDocs ;
            for ( ScoreDoc sd : sDocs ) {
                System.out.println("Doc: "+sd.doc) ;
                Document doc = indexSearcher.doc(sd.doc) ;
                //System.out.println(doc) ;
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryparser.classic.QueryParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.