public void testFieldPrefix() { SpellingQueryConverter converter = new SpellingQueryConverter(); converter.setAnalyzer(new WhitespaceAnalyzer()); var original = "content:(developer OR programmer)"; Collection /*<Token>*/ tokens = converter.convert(original); Assert.IsNotNull(tokens); Assert.AreEqual(2, tokens.size()); var tokenArr = tokens.toArray(); Assert.AreEqual("developer", ((Token)tokenArr[0]).term()); Assert.AreEqual("programmer", ((Token)tokenArr[1]).term()); Assert.IsTrue(isOffsetCorrect(original, tokens)); original = "content:((developer OR programmer) AND cobol) company:ibm"; tokens = converter.convert(original); Assert.IsNotNull(tokens); Assert.AreEqual(4, tokens.size()); tokenArr = tokens.toArray(); Assert.AreEqual("developer", ((Token)tokenArr[0]).term()); Assert.AreEqual("programmer", ((Token)tokenArr[1]).term()); Assert.AreEqual("cobol", ((Token)tokenArr[2]).term()); Assert.AreEqual("ibm", ((Token)tokenArr[3]).term()); Assert.IsTrue(isOffsetCorrect(original, tokens)); }
public void test() { SpellingQueryConverter converter = new SpellingQueryConverter(); //converter.init(new NamedList()); converter.setAnalyzer(new WhitespaceAnalyzer()); Collection /*<Token>*/ tokens = converter.convert("field:foo"); assertTrue("tokens is null and it shouldn't be", tokens != null); assertTrue("tokens Size: " + tokens.size() + " is not: " + 1, tokens.size() == 1); }
public void testMultipleClauses() { SpellingQueryConverter converter = new SpellingQueryConverter(); //converter.init(new NamedList()); converter.setAnalyzer(new WhitespaceAnalyzer()); // two field:value pairs should give two tokens Collection /*<Token>*/ tokens = converter.convert("买text_field:我购买了道具和服装。 field2:bar"); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 2", 2, tokens.size()); // a field:value pair and a search term should give two tokens tokens = converter.convert("text_field:我购买了道具和服装。 bar"); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 2", 2, tokens.size()); }
public void testUnicode() { SpellingQueryConverter converter = new SpellingQueryConverter(); //converter.init(new NamedList()); converter.setAnalyzer(new WhitespaceAnalyzer()); // chinese text value Collection /*<Token>*/ tokens = converter.convert("text_field:我购买了道具和服装。"); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); tokens = converter.convert("text_购field:我购买了道具和服装。"); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); tokens = converter.convert("text_field:我购xyz买了道具和服装。"); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); }
public void testSpecialChars() { SpellingQueryConverter converter = new SpellingQueryConverter(); //converter.init(new NamedList()); converter.setAnalyzer(new WhitespaceAnalyzer()); string original = "field_with_underscore:value_with_underscore"; Collection /*<Token>*/ tokens = converter.convert(original); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); assertTrue("Token offsets do not match", isOffsetCorrect(original, tokens)); original = "field_with_digits123:value_with_digits123"; tokens = converter.convert(original); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); assertTrue("Token offsets do not match", isOffsetCorrect(original, tokens)); original = "field-with-hyphens:value-with-hyphens"; tokens = converter.convert(original); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); assertTrue("Token offsets do not match", isOffsetCorrect(original, tokens)); // mix 'em up and add some to the value // original = "field_with-123s:value_,.|with-hyphens"; // tokens = converter.convert(original); // assertTrue("tokens is null and it shouldn't be", tokens != null); // assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); // assertTrue("Token offsets do not match", isOffsetCorrect(original, tokens)); original = "foo:bar^5.0"; tokens = converter.convert(original); assertTrue("tokens is null and it shouldn't be", tokens != null); assertEquals("tokens Size: " + tokens.size() + " is not 1", 1, tokens.size()); assertTrue("Token offsets do not match", isOffsetCorrect(original, tokens)); }