Package org.apache.lucene.queryParser

Examples of org.apache.lucene.queryParser.MultiFieldQueryParser


    tx = s.beginTransaction();
    Map<String, Float> boosts = new HashMap<String, Float>(2);
    boosts.put( "title", new Float(4) );
    boosts.put( "description", new Float(1) );
    MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] {"title", "description"}, new StandardAnalyzer(), boosts);
    Query luceneQuery = parser.parse( "dark" );
    FullTextQuery ftQuery = s.createFullTextQuery( luceneQuery, Dvd.class )
        .setProjection( FullTextQuery.DOCUMENT_ID, FullTextQuery.EXPLANATION, FullTextQuery.THIS );
    @SuppressWarnings("unchecked") List<Object[]> results = ftQuery.list();
    assertEquals( 2, results.size() );
    for (Object[] result : results) {
View Full Code Here


    s.clear();

    FullTextSession session = Search.getFullTextSession( s );
    tx = session.beginTransaction();

    QueryParser parser = new MultiFieldQueryParser( new String[] { "name", "authors.name" }, new StandardAnalyzer() );
    Query query;
    List<?> result;

    query = parser.parse( "Hugo" );
    result = session.createFullTextQuery( query, Product.class ).list();
    assertEquals( "collection of embedded ignored", 1, result.size() );

    // update the collection
    Product p = (Product) result.get( 0 );
    p.getAuthors().add( a4 );

    // PhraseQuery
    query = new TermQuery( new Term( "orders.orderNumber", "ZERTYD" ) );
    result = session.createFullTextQuery( query, Product.class ).list();
    assertEquals( "collection of untokenized ignored", 1, result.size() );
    query = new TermQuery( new Term( "orders.orderNumber", "ACVBNM" ) );
    result = session.createFullTextQuery( query, Product.class ).list();
    assertEquals( "collection of untokenized ignored", 1, result.size() );

    tx.commit();

    s.clear();

    tx = s.beginTransaction();
    session = Search.getFullTextSession( s );
    query = parser.parse( "Proust" );
    result = session.createFullTextQuery( query, Product.class ).list();
    // HSEARCH-56
    assertEquals( "update of collection of embedded ignored", 1, result.size() );

    s.delete( s.get( Product.class, p1.getId() ) );
View Full Code Here

    s.clear();

    FullTextSession session = Search.getFullTextSession( s );
    tx = session.beginTransaction();

    QueryParser parser = new MultiFieldQueryParser( new String[] { "name", "state.name" }, new StandardAnalyzer() );
    Query query;
    List<?> result;

    query = parser.parse( "Bavaria" );
    result = session.createFullTextQuery( query, StateCandidate.class ).list();
    assertEquals( "IndexEmbedded ignored.", 1, result.size() );
    tx.commit();
    s.clear();
   
    tx = s.beginTransaction();
    state.setName( "Hessen" );
    state = (State) s.merge( state );
    tx.commit();
    s.clear();
   
    tx = s.beginTransaction();
    session = Search.getFullTextSession( s );
    query = parser.parse( "Hessen" );
    result = session.createFullTextQuery( query, StateCandidate.class ).list();
    assertEquals( "IndexEmbedded ignored.", 1, result.size() );
    tx.commit();
    s.clear();
    s.close();
View Full Code Here

    }

    public void run() {
      Session s = sf.openSession();
      Transaction tx = s.beginTransaction();
      QueryParser parser = new MultiFieldQueryParser(
          new String[] { "name", "physicalDescription", "suspectCharge" },
          new StandardAnalyzer()
      );
      FullTextQuery query = getQuery( "John Doe", parser, s );
      assertTrue( query.getResultSize() != 0 );
View Full Code Here

    }

    public void run() {
      Session s = sf.openSession();
      Transaction tx = s.beginTransaction();
      QueryParser parser = new MultiFieldQueryParser(
          new String[] { "name", "physicalDescription", "suspectCharge" },
          new StandardAnalyzer()
      );
      FullTextQuery query = getQuery( "John Doe", parser, s );
      assertTrue( query.getResultSize() != 0 );
View Full Code Here

    searcher = new IndexSearcher(indexName);
    Analyzer analyzer = new StandardAnalyzer();
    getFieldInfo();

    MultiFieldQueryParser parser = new MultiFieldQueryParser(queryString, analyzer);

    int arraySize = indexedFields.size();
    String indexedArray[] = new String[arraySize];
    for (int ii = 0; ii < arraySize; ii++) {
      indexedArray[ii] = (String) indexedFields.get(ii);
    }
    query = parser.parse(queryString, indexedArray, analyzer);
    System.out.println("Searching for: " + query.toString());
    return (query);

  }
View Full Code Here

    searcher = new IndexSearcher(indexName);
    Analyzer analyzer = new StandardAnalyzer();
    getFieldInfo();

    MultiFieldQueryParser parser = new MultiFieldQueryParser(queryString, analyzer);

    int arraySize = fields.size();
    fieldsArray = new String[arraySize];
    for (int ii = 0; ii < arraySize; ii++) {
      fieldsArray[ii] = (String) fields.get(ii);
    }
    query = parser.parse(queryString, fieldsArray, analyzer);
    System.out.println("Searching for: " + query.toString());
    Hits hits = searcher.search(query);
    return (hits);

  }
View Full Code Here

            }

            //build a query based on the fields, searchString and cached analyzer
            //NOTE: This is an area for improvement since the MultiFieldQueryParser
            // has some weirdness.
            MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
            Query query = parser.parse(searchString);
            //run the search
            Hits hits = is.search(query);
            //reset this table model with the new results
            resetSearchResults(hits);
        } catch (Exception e){
View Full Code Here

            String[] fields = {FIELD_NAME};

            //build a query based on the fields, searchString and cached analyzer
            //NOTE: This is an area for improvement since the MultiFieldQueryParser
            // has some weirdness.
            MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
            Query query =parser.parse(searchString);
            //run the search
            Hits hits = is.search(query);
            //reset this list model with the new results
            resetSearchResults(hits);
        } catch (Exception e){
View Full Code Here

      //search for query string on metadata name field and content
      //where metadata name = metaDataToSearch
      Query queryMetadata = new TermQuery(new Term(IndexingConstants.METADATA, metaDataToSearch));
      andQuery.add(queryMetadata, BooleanClause.Occur.MUST);
    }
    Query query = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields,
        analyzer).parse(queryString);
    andQuery.add(query, BooleanClause.Occur.MUST);
    logger.debug("Searching for: " + andQuery.toString());
    int hitsPerPage = 50;
   
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryParser.MultiFieldQueryParser

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.