Package org.apache.lucene.queryParser

Examples of org.apache.lucene.queryParser.QueryParser


  public void testPerFieldAnalyzer() throws Exception {
    PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
    analyzer.addAnalyzer("partnum", new KeywordAnalyzer());

    QueryParser queryParser = new QueryParser(Version.LUCENE_CURRENT, "description", analyzer);
    Query query = queryParser.parse("partnum:Q36 AND SPACE");

    ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
    assertEquals("Q36 kept as-is",
              "+partnum:Q36 +space", query.toString("description"));
    assertEquals("doc found!", 1, hits.length);
View Full Code Here


    "w1 xx w2 yy w3",
    "w1 w3 xx w2 yy w3"
  };

  public Query makeQuery(String queryText) throws ParseException {
    Query q = (new QueryParser(Version.LUCENE_CURRENT, field, new WhitespaceAnalyzer())).parse(queryText);
    return q;
  }
View Full Code Here

    checkBadQuery("\"jo*  id:1 smith\""); // mixing fields in a phrase is bad
    checkBadQuery("\"jo* \"smith\" \""); // phrases inside phrases is bad
  }

  private void checkBadQuery(String qString) {
    QueryParser qp = new ComplexPhraseQueryParser(Version.LUCENE_CURRENT, defaultFieldName, analyzer);
    Throwable expected = null;
    try {
      qp.parse(qString);
    } catch (Throwable e) {
      expected = e;
    }
    assertNotNull("Expected parse error in " + qString, expected);

View Full Code Here

  }

  private void checkMatches(String qString, String expectedVals)
      throws Exception {
    QueryParser qp = new ComplexPhraseQueryParser(Version.LUCENE_CURRENT, defaultFieldName, analyzer);
    qp.setFuzzyPrefixLength(1); // usually a good idea

    Query q = qp.parse(qString);

    HashSet expecteds = new HashSet();
    String[] vals = expectedVals.split(",");
    for (int i = 0; i < vals.length; i++) {
      if (vals[i].length() > 0)
View Full Code Here

    addDoc("Brute willis", w);
    addDoc("B. willis", w);
    IndexReader r = w.getReader();
    w.close();

    Query q = new QueryParser(Version.LUCENE_CURRENT, "field", analyzer).parse( "giga~0.9" );

    // 3. search
    IndexSearcher searcher = new IndexSearcher(r);
    ScoreDoc[] hits = searcher.search(q, 10).scoreDocs;
    assertEquals(1, hits.length);
View Full Code Here

    writerA.close();

    writerB.addDocument(lDoc3);
    writerB.close();

    QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, "fulltext", new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    Query query = parser.parse("handle:1");

    Searcher[] searchers = new Searcher[2];
    searchers[0] = new IndexSearcher(indexStoreB, true);
    searchers[1] = new IndexSearcher(indexStoreA, true);
    Searcher mSearcher = new MultiSearcher(searchers);
    ScoreDoc[] hits = mSearcher.search(query, null, 1000).scoreDocs;

    assertEquals(3, hits.length);

    Explanation explain = mSearcher.explain(query, hits[0].doc);
    String exp = explain.toString(0);
    assertTrue(exp, exp.indexOf("maxDocs=3") > -1);
    assertTrue(exp, exp.indexOf("docFreq=3") > -1);
   
    query = parser.parse("handle:\"1 2\"");
    hits = mSearcher.search(query, null, 1000).scoreDocs;

    assertEquals(3, hits.length);

    explain = mSearcher.explain(query, hits[0].doc);
View Full Code Here

        analyzer = new StopAnalyzer(Version.LUCENE_CURRENT);
    }


    public void testSearch() throws Exception {
      Query query = new QueryParser(Version.LUCENE_CURRENT, "contents",analyzer).parse("test");

        int numHits = searcher.search(query, null, 1000).totalHits;

        assertEquals("Find document(s)", 2, numHits);
    }
View Full Code Here

    {
        List<RepositoryContentIndex> indexes = getHashcodeIndexes( principal, selectedRepos );

        try
        {
            QueryParser parser = new MultiFieldQueryParser( new String[]{HashcodesKeys.MD5, HashcodesKeys.SHA1},
                                           new HashcodesHandlers().getAnalyzer() );
            LuceneQuery query = new LuceneQuery( parser.parse( checksum ) );
            SearchResults results = searchAll( query, limits, indexes, null );
            results.getRepositories().addAll( this.localIndexedRepositories );

            return results;
        }
View Full Code Here

    {
        List<RepositoryContentIndex> indexes = getBytecodeIndexes( principal, selectedRepos );

        try
        {
            QueryParser parser = new BytecodeHandlers().getQueryParser();
            LuceneQuery query = new LuceneQuery( parser.parse( term ) );
            SearchResults results = searchAll( query, limits, indexes, null );
            results.getRepositories().addAll( this.localIndexedRepositories );

            return results;
        }
View Full Code Here

    {
        List<RepositoryContentIndex> indexes = getFileContentIndexes( principal, selectedRepos );

        try
        {
            QueryParser parser = new FileContentHandlers().getQueryParser();
            LuceneQuery query = null;
            SearchResults results = null;
            if ( previousSearchTerms == null || previousSearchTerms.isEmpty() )
            {
                query = new LuceneQuery( parser.parse( term ) );
                results = searchAll( query, limits, indexes, null );
            }
            else
            {
                // AND the previous search terms
                BooleanQuery booleanQuery = new BooleanQuery();
                for ( String previousSearchTerm : previousSearchTerms )
                {
                    booleanQuery.add( parser.parse( previousSearchTerm ), BooleanClause.Occur.MUST );
                }

                query = new LuceneQuery( booleanQuery );
                Filter filter = new QueryWrapperFilter( parser.parse( term ) );
                results = searchAll( query, limits, indexes, filter );
            }
            results.getRepositories().addAll( this.localIndexedRepositories );

            return results;
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryParser.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.