use of datawave.query.util.MockMetadataHelper in project datawave by NationalSecurityAgency.
the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoSingleFieldWithNoExpansion.
@Test
public void expandContentPhraseFunctionIntoSingleFieldWithNoExpansion() throws ParseException {
Set<String> fields = Sets.newHashSet("FOO", "BAR");
Set<String> tfFields = Sets.newHashSet("FOO");
// Configure the mock metadata helper.
MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
mockMetadataHelper.setIndexedFields(fields);
mockMetadataHelper.addTermFrequencyFields(tfFields);
ShardQueryConfiguration config = new ShardQueryConfiguration();
config.setNoExpansionFields(Sets.newHashSet("FOO"));
// Execute the test.
String original = "content:phrase(termOffsetMap, 'abc', 'def')";
runTest(original, original, config, mockMetadataHelper);
}
use of datawave.query.util.MockMetadataHelper in project datawave by NationalSecurityAgency.
the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoMultipleFields.
@Test
public void expandContentPhraseFunctionIntoMultipleFields() throws ParseException {
Set<String> fields = Sets.newHashSet("FOO", "BAR");
// Configure the mock metadata helper.
MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
mockMetadataHelper.setIndexedFields(fields);
mockMetadataHelper.addTermFrequencyFields(fields);
this.metadataHelper = mockMetadataHelper;
// Execute the test.
String original = "content:phrase(termOffsetMap, 'abc', 'def')";
String expected = "((content:phrase(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:phrase(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
runTest(original, expected);
original = "content:phrase((FOO || BAR), termOffsetMap, 'abc', 'def')";
expected = "((content:phrase(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:phrase(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
runTest(original, expected, mockMetadataHelper);
}
use of datawave.query.util.MockMetadataHelper in project datawave by NationalSecurityAgency.
the class FunctionIndexQueryExpansionVisitorTest method expandContentScoredPhraseFunctionIntoMultipleFields.
@Test
public void expandContentScoredPhraseFunctionIntoMultipleFields() throws ParseException {
Set<String> fields = Sets.newHashSet("FOO", "BAR");
Set<String> tfFields = Sets.newHashSet("FOO", "BAR");
// Configure the mock metadata helper.
MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
mockMetadataHelper.setIndexedFields(fields);
mockMetadataHelper.addTermFrequencyFields(tfFields);
this.metadataHelper = mockMetadataHelper;
// Execute the test.
String original = "content:scoredPhrase(-1.5, termOffsetMap, 'abc', 'def')";
String expected = "(content:scoredPhrase(FOO, -1.5, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:scoredPhrase(BAR, -1.5, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc')";
runTest(original, expected);
}
use of datawave.query.util.MockMetadataHelper in project datawave by NationalSecurityAgency.
the class FunctionIndexQueryExpansionVisitorTest method expandContentAdjacentFunctionIntoMultipleFields.
@Test
public void expandContentAdjacentFunctionIntoMultipleFields() throws ParseException {
Set<String> fields = Sets.newHashSet("FOO", "BAR");
Set<String> tfFields = Sets.newHashSet("FOO", "BAR");
// Configure the mock metadata helper.
MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
mockMetadataHelper.setIndexedFields(fields);
mockMetadataHelper.addTermFrequencyFields(tfFields);
this.metadataHelper = mockMetadataHelper;
// Execute the test.
String original = "content:adjacent(termOffsetMap, 'abc', 'def')";
String expected = "((content:adjacent(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:adjacent(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
runTest(original, expected);
original = "content:adjacent((FOO || BAR), termOffsetMap, 'abc', 'def')";
expected = "((content:adjacent(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:adjacent(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
runTest(original, expected);
}
use of datawave.query.util.MockMetadataHelper in project datawave by NationalSecurityAgency.
the class ContentFunctionsTest method testJexlFunctionArgumentDescriptors.
private void testJexlFunctionArgumentDescriptors(String query, String expected, Set<String> contentFields) throws ParseException {
MockMetadataHelper metadataHelper = new MockMetadataHelper();
metadataHelper.addTermFrequencyFields(Arrays.asList("BODY", "META"));
metadataHelper.setIndexedFields(Sets.newHashSet("BODY", "META"));
if (contentFields != null) {
metadataHelper.addContentFields(contentFields);
}
MockDateIndexHelper dateIndexHelper = new MockDateIndexHelper();
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode ref = script.jjtGetChild(0);
Assert.assertEquals("First child of ASTJexlScript is not an ASTReference", ASTReference.class, ref.getClass());
JexlNode child = ref.jjtGetChild(0);
Assert.assertEquals("First child of ASTJexlScript is not an AStFunctionNode", ASTFunctionNode.class, child.getClass());
ASTFunctionNode function = (ASTFunctionNode) child;
JexlArgumentDescriptor desc = new ContentFunctionsDescriptor().getArgumentDescriptor(function);
JexlNode indexQuery = desc.getIndexQuery(null, metadataHelper, dateIndexHelper, null);
ASTJexlScript expectedScript = JexlASTHelper.parseJexlQuery(expected);
JexlNode scriptChild = expectedScript.jjtGetChild(0);
Assert.assertTrue("Expected " + JexlStringBuildingVisitor.buildQuery(scriptChild) + " but was " + JexlStringBuildingVisitor.buildQuery(indexQuery), JexlASTHelper.equals(scriptChild, indexQuery));
}
Aggregations