Package org.apache.lucene.analysis.standard

Examples of org.apache.lucene.analysis.standard.StandardAnalyzer


  }

  public void testStaticMethod1() throws QueryNodeException {
    String[] fields = { "b", "t" };
    String[] queries = { "one", "two" };
    Query q = QueryParserUtil.parse(queries, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("b:one t:two", q.toString());

    String[] queries2 = { "+one", "+two" };
    q = QueryParserUtil.parse(queries2, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("(+b:one) (+t:two)", q.toString());

    String[] queries3 = { "one", "+two" };
    q = QueryParserUtil.parse(queries3, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("b:one (+t:two)", q.toString());

    String[] queries4 = { "one +more", "+two" };
    q = QueryParserUtil.parse(queries4, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("(b:one +b:more) (+t:two)", q.toString());

    String[] queries5 = { "blah" };
    try {
      q = QueryParserUtil.parse(queries5, fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
View Full Code Here


  public void testStaticMethod2() throws QueryNodeException {
    String[] fields = { "b", "t" };
    BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
        BooleanClause.Occur.MUST_NOT };
    Query q = QueryParserUtil.parse("one", fields, flags,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+b:one -t:one", q.toString());

    q = QueryParserUtil.parse("one two", fields, flags, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());

    try {
      BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
      q = QueryParserUtil.parse("blah", fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
  }
View Full Code Here

    String[] fields = { "b", "t" };
    BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
        BooleanClause.Occur.MUST_NOT };
    StandardQueryParser parser = new StandardQueryParser();
    parser.setMultiFields(fields);
    parser.setAnalyzer(new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));

    Query q = QueryParserUtil.parse("one", fields, flags,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));// , fields, flags, new
    // StandardAnalyzer());
    assertEquals("+b:one -t:one", q.toString());

    q = QueryParserUtil.parse("one two", fields, flags, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());

    try {
      BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
      q = QueryParserUtil.parse("blah", fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
  }
View Full Code Here

    String[] queries = { "one", "two", "three" };
    String[] fields = { "f1", "f2", "f3" };
    BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
        BooleanClause.Occur.MUST_NOT, BooleanClause.Occur.SHOULD };
    Query q = QueryParserUtil.parse(queries, fields, flags,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+f1:one -f2:two f3:three", q.toString());

    try {
      BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
      q = QueryParserUtil
          .parse(queries, fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
  }
View Full Code Here

    String[] queries = { "one", "two" };
    String[] fields = { "b", "t" };
    BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
        BooleanClause.Occur.MUST_NOT };
    Query q = QueryParserUtil.parse(queries, fields, flags,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+b:one -t:two", q.toString());

    try {
      BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
      q = QueryParserUtil
          .parse(queries, fields, flags2, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
  }
View Full Code Here

    q = parser.parse("[a TO c]", null);
    assertEquals("f1:[a TO c] f2:[a TO c] f3:[a TO c]", q.toString());
  }

  public void testStopWordSearching() throws Exception {
    Analyzer analyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT);
    Directory ramDir = new RAMDirectory();
    IndexWriter iw = new IndexWriter(ramDir, analyzer, true,
        IndexWriter.MaxFieldLength.LIMITED);
    Document doc = new Document();
    doc.add(new Field("body", "blah the footest blah", Field.Store.NO,
View Full Code Here

  }

  public void testSimple() throws Exception {
    String[] fields = { "b", "t" };
    MultiFieldQueryParserWrapper mfqp = new MultiFieldQueryParserWrapper(
        fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));

    Query q = mfqp.parse("one");
    assertEquals("b:one t:one", q.toString());

    q = mfqp.parse("one two");
View Full Code Here

    Map boosts = new HashMap();
    boosts.put("b", Float.valueOf(5));
    boosts.put("t", Float.valueOf(10));
    String[] fields = { "b", "t" };
    MultiFieldQueryParserWrapper mfqp = new MultiFieldQueryParserWrapper(
        fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT), boosts);

    // Check for simple
    Query q = mfqp.parse("one");
    assertEquals("b:one^5.0 t:one^10.0", q.toString());
View Full Code Here

  public void testStaticMethod1() throws ParseException {
    String[] fields = { "b", "t" };
    String[] queries = { "one", "two" };
    Query q = MultiFieldQueryParserWrapper.parse(queries, fields,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("b:one t:two", q.toString());

    String[] queries2 = { "+one", "+two" };
    q = MultiFieldQueryParserWrapper.parse(queries2, fields,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("(+b:one) (+t:two)", q.toString());

    String[] queries3 = { "one", "+two" };
    q = MultiFieldQueryParserWrapper.parse(queries3, fields,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("b:one (+t:two)", q.toString());

    String[] queries4 = { "one +more", "+two" };
    q = MultiFieldQueryParserWrapper.parse(queries4, fields,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("(b:one +b:more) (+t:two)", q.toString());

    String[] queries5 = { "blah" };
    try {
      q = MultiFieldQueryParserWrapper.parse(queries5, fields,
          new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
View Full Code Here

  public void testStaticMethod2() throws ParseException {
    String[] fields = { "b", "t" };
    BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
        BooleanClause.Occur.MUST_NOT };
    Query q = MultiFieldQueryParserWrapper.parse("one", fields, flags,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+b:one -t:one", q.toString());

    q = MultiFieldQueryParserWrapper.parse("one two", fields, flags,
        new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
    assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());

    try {
      BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
      q = MultiFieldQueryParserWrapper.parse("blah", fields, flags2,
          new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
      fail();
    } catch (IllegalArgumentException e) {
      // expected exception, array length differs
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.analysis.standard.StandardAnalyzer

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.