org.apache.lucene.analysis.en.EnglishAnalyzer Java Examples

The following examples show how to use org.apache.lucene.analysis.en.EnglishAnalyzer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrefixConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInetV4() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    PrefixCondition wildcardCondition = new PrefixCondition(0.5f, "name", "192.168.");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("192.168.", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #2
Source File: PrefixConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInetV6() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    PrefixCondition wildcardCondition = new PrefixCondition(0.5f, "name", "2001:db8:2de:0:0:0:0:e");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #3
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoubleOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #4
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInetV4() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", "192.168.0.01", "192.168.0.045", true, true);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(TermRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((TermRangeQuery) query).getField());
    Assert.assertEquals("192.168.0.1", ((TermRangeQuery) query).getLowerTerm().utf8ToString());
    Assert.assertEquals("192.168.0.45", ((TermRangeQuery) query).getUpperTerm().utf8ToString());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesLower());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesUpper());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #5
Source File: PhraseConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testPhraseQuery() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperBoolean());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    List<String> values = new ArrayList<>();
    values.add("hola");
    values.add("adios");

    PhraseCondition phraseCondition = new PhraseCondition(0.5f, "name", values, 2);
    Query query = phraseCondition.query(mappers);
    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.PhraseQuery.class, query.getClass());
    org.apache.lucene.search.PhraseQuery luceneQuery = (org.apache.lucene.search.PhraseQuery) query;
    Assert.assertEquals(values.size(), luceneQuery.getTerms().length);
    Assert.assertEquals(2, luceneQuery.getSlop());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #6
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntegerOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #7
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testLongClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42L, 43, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43L, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #8
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testLongOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42f, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #9
Source File: CodePatternSearcher.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
private static List<String> search(List<String> contents, String query, int n) throws IOException, ParseException {
    List<String> r=new ArrayList<>();
    Directory dir=new RAMDirectory();
    IndexWriter indexWriter=new IndexWriter(dir, new IndexWriterConfig(new EnglishAnalyzer()));
    for (String method:contents){
        Document document=new Document();
        document.add(new TextField("content",method, Field.Store.YES));
        indexWriter.addDocument(document);
    }
    indexWriter.close();
    QueryParser qp = new QueryParser("content", new EnglishAnalyzer());
    IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(dir));
    TopDocs topDocs = indexSearcher.search(qp.parse(query), n);
    for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
        r.add(indexSearcher.doc(scoreDoc.doc).get("content"));
    }
    return r;
}
 
Example #10
Source File: InMemoryIndex.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public InMemoryIndex(Map<String,String> id2Text){
    Analyzer analyzer = new EnglishAnalyzer();
    IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    try {
        IndexWriter writer = new IndexWriter(directory, iwc);
        for (String id:id2Text.keySet()) {
            Document doc=new Document();
            doc.add(new StringField("id", id, Field.Store.YES));
            doc.add(new TextField("content", id2Text.get(id), Field.Store.YES));
            writer.addDocument(doc);
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #11
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloatClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 43.42F, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43.42f, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #12
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloatOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42f, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42f, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #13
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoubleClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 43.42D, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43.42D, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #14
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntegerClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42, 43, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #15
Source File: KNearestNeighborClassifierTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * This test is for the scenario where in the first topK results from the MLT query, we have less results
 * for the expected class than the results for the bad class.
 * But the results for the expected class have a better score in comparison with the results of the second class.
 * So we would expect a greater score for the best ranked class.
 *
 * @throws Exception if any error happens
 */
@Test
public void testUnbalancedClasses() throws Exception {
  LeafReader leafReader = null;
  try {
    Analyzer analyzer = new EnglishAnalyzer();
    leafReader = getSampleIndex(analyzer);
    KNearestNeighborClassifier knnClassifier = new KNearestNeighborClassifier(leafReader, null,analyzer, null, 3, 1, 1, categoryFieldName, textFieldName);
    List<ClassificationResult<BytesRef>> classes = knnClassifier.getClasses(SUPER_STRONG_TECHNOLOGY_INPUT);
    assertTrue(classes.get(0).getScore() > classes.get(1).getScore());
    checkCorrectClassification(knnClassifier, SUPER_STRONG_TECHNOLOGY_INPUT, TECHNOLOGY_RESULT);
  } finally {
    if (leafReader != null) {
      leafReader.close();
    }
  }
}
 
Example #16
Source File: KNearestNeighborClassifierTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * This test is for the scenario where in the first topK results from the MLT query, we have the same number of results per class.
 * But the results for a class have a better ranking in comparison with the results of the second class.
 * So we would expect a greater score for the best ranked class.
 *
 * @throws Exception if any error happens
 */
@Test
public void testRankedClasses() throws Exception {
  LeafReader leafReader = null;
  try {
    Analyzer analyzer = new EnglishAnalyzer();
    leafReader = getSampleIndex(analyzer);
    KNearestNeighborClassifier knnClassifier = new KNearestNeighborClassifier(leafReader, null, analyzer, null, 6, 1, 1, categoryFieldName, textFieldName);
    List<ClassificationResult<BytesRef>> classes = knnClassifier.getClasses(STRONG_TECHNOLOGY_INPUT);
    assertTrue(classes.get(0).getScore() > classes.get(1).getScore());
    checkCorrectClassification(knnClassifier, STRONG_TECHNOLOGY_INPUT, TECHNOLOGY_RESULT);
  } finally {
    if (leafReader != null) {
      leafReader.close();
    }
  }
}
 
Example #17
Source File: TestTextField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAnalyzeMultiTerm() {
  // No terms provided by the StopFilter (stop word) for the multi-term part.
  // This is supported. Check TextField.analyzeMultiTerm returns null (and does not throw an exception).
  BytesRef termBytes = TextField.analyzeMultiTerm("field", "the", new StopAnalyzer(EnglishAnalyzer.ENGLISH_STOP_WORDS_SET));
  assertNull(termBytes);

  // One term provided by the WhitespaceTokenizer for the multi-term part.
  // This is the regular case. Check TextField.analyzeMultiTerm returns it (and does not throw an exception).
  termBytes = TextField.analyzeMultiTerm("field", "Sol", new WhitespaceAnalyzer());
  assertEquals("Sol", termBytes.utf8ToString());

  // Two terms provided by the WhitespaceTokenizer for the multi-term part.
  // This is not allowed. Expect an exception.
  SolrException exception = expectThrows(SolrException.class, () -> TextField.analyzeMultiTerm("field", "term1 term2", new WhitespaceAnalyzer()));
  assertEquals("Unexpected error code", SolrException.ErrorCode.BAD_REQUEST.code, exception.code());
}
 
Example #18
Source File: IEX2LevAMAZON.java    From Clusion with GNU General Public License v3.0 6 votes vote down vote up
public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
	String line = value.toString();

	CharArraySet noise = EnglishAnalyzer.getDefaultStopSet();
	// We are using a standard tokenizer that eliminates the stop words.
	// We can use Stemming tokenizer such Porter
	// A set of English noise keywords is used that will eliminates
	// words such as "the, a, etc"
	Analyzer analyzer = new StandardAnalyzer(noise);
	List<String> token = Tokenizer.tokenizeString(analyzer, line);
	Iterator<String> it = token.iterator();
	while (it.hasNext()) {
		word.set(it.next());
		fileName.set(key);
		if (!mapTable.containsKey(fileName.toString() + word.toString())) {
			context.write(fileName, word);
			mapTable.put(fileName.toString() + word.toString(), new IntWritable(1));
		}
	}
}
 
Example #19
Source File: IEX2LevAMAZON.java    From Clusion with GNU General Public License v3.0 6 votes vote down vote up
public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
	String line = value.toString();
	CharArraySet noise = EnglishAnalyzer.getDefaultStopSet();
	// We are using a standard tokenizer that eliminates the stop words.
	// We can use Stemming tokenizer such Porter
	// A set of English noise keywords is used that will eliminates
	// words such as "the, a, etc"
	Analyzer analyzer = new StandardAnalyzer(noise);
	List<String> token = Tokenizer.tokenizeString(analyzer, line);
	Iterator<String> it = token.iterator();
	while (it.hasNext()) {
		word.set(it.next());
		fileName.set(key);
		if (!mapTable.containsKey(fileName.toString() + word.toString())) {
			context.write(word, fileName);
			mapTable.put(fileName.toString() + word.toString(), new IntWritable(1));
		}

	}
}
 
Example #20
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInetV6() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = range("name").boost(0.5f)
                                                 .lower("2001:DB8:2de::e13")
                                                 .upper("2001:DB8:02de::e23")
                                                 .includeLower(true)
                                                 .includeUpper(true)
                                                 .build();
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(TermRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((TermRangeQuery) query).getField());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e13", ((TermRangeQuery) query).getLowerTerm().utf8ToString());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e23", ((TermRangeQuery) query).getUpperTerm().utf8ToString());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesLower());
    Assert.assertEquals(true, ((TermRangeQuery) query).includesUpper());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #21
Source File: PrefixConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testString() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperString());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    PrefixCondition prefixCondition = new PrefixCondition(0.5f, "name", "tr");
    Query query = prefixCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #22
Source File: QueryParserImpl.java    From AdSearch_Endpoints with Apache License 2.0 6 votes vote down vote up
@Override
  public List<String> parseQuery(String queryStr) {
    // tokenize queryStr, remove stop word, stemming
	List<String> tokens = new ArrayList<String>();
	AttributeFactory factory = AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY;
	Tokenizer tokenizer = new StandardTokenizer(factory);
	tokenizer.setReader(new StringReader(queryStr));
	CharArraySet stopWords = EnglishAnalyzer.getDefaultStopSet();
    TokenStream tokenStream = new StopFilter(tokenizer, stopWords);
//    StringBuilder sb = new StringBuilder();
    CharTermAttribute charTermAttribute = tokenizer.addAttribute(CharTermAttribute.class);
    try {
    	tokenStream.reset();
        while (tokenStream.incrementToken()) {
            String term = charTermAttribute.toString();
            
            tokens.add(term);
//            sb.append(term + " ");
        }
        tokenStream.end();
        tokenStream.close();

        tokenizer.close();  
	} catch (IOException e) {
		e.printStackTrace();
	}
//	System.out.println("QU="+ sb.toString());
	return tokens;	
  }
 
Example #23
Source File: WildcardConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInetV6() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    WildcardCondition wildcardCondition = new WildcardCondition(0.5f, "name", "2001:db8:2de:0:0:0:0:e*");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.WildcardQuery.class, query.getClass());
    org.apache.lucene.search.WildcardQuery luceneQuery = (org.apache.lucene.search.WildcardQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("2001:db8:2de:0:0:0:0:e*", luceneQuery.getTerm().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #24
Source File: WildcardConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInetV4() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    WildcardCondition wildcardCondition = new WildcardCondition(0.5f, "name", "192.168.*");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.WildcardQuery.class, query.getClass());
    org.apache.lucene.search.WildcardQuery luceneQuery = (org.apache.lucene.search.WildcardQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("192.168.*", luceneQuery.getTerm().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #25
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDouble() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42.42D);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #26
Source File: FuzzyConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFuzzyQuery() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperBoolean());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    FuzzyCondition fuzzyCondition = new FuzzyCondition(0.5f, "name", "tr", 1, 2, 49, true);
    Query query = fuzzyCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.FuzzyQuery.class, query.getClass());
    org.apache.lucene.search.FuzzyQuery luceneQuery = (org.apache.lucene.search.FuzzyQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr", luceneQuery.getTerm().text());
    Assert.assertEquals(1, luceneQuery.getMaxEdits());
    Assert.assertEquals(2, luceneQuery.getPrefixLength());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #27
Source File: WildcardConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testString() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperString());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    WildcardCondition wildcardCondition = new WildcardCondition(0.5f, "name", "tr*");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(org.apache.lucene.search.WildcardQuery.class, query.getClass());
    org.apache.lucene.search.WildcardQuery luceneQuery = (org.apache.lucene.search.WildcardQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr*", luceneQuery.getTerm().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #28
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInteger() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #29
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testLong() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42L);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #30
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloat() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42.42F);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}