use of org.wso2.carbon.registry.indexing.indexer.Indexer in project carbon-apimgt by wso2.
the class PlainTextIndexerTest method testShouldReturnIndexedDocumentWhenParameterCorrect.
@Test
public void testShouldReturnIndexedDocumentWhenParameterCorrect() throws RegistryException {
String mediaType = "text/txt";
final String MEDIA_TYPE = "mediaType";
AsyncIndexer.File2Index file2Index = new AsyncIndexer.File2Index("".getBytes(), null, "", -1234, "");
PlainTextIndexer indexer = new PlainTextIndexer();
// should return the default media type when media type is not defined in file2Index
IndexDocument text = indexer.getIndexedDocument(file2Index);
if (!"text/(.)".equals(text.getFields().get(MEDIA_TYPE).get(0))) {
Assert.fail();
}
// should return the media type we have set in the file2Index
file2Index.mediaType = mediaType;
text = indexer.getIndexedDocument(file2Index);
if (!mediaType.equals(text.getFields().get(MEDIA_TYPE).get(0))) {
Assert.fail();
}
}
use of org.wso2.carbon.registry.indexing.indexer.Indexer in project carbon-apimgt by wso2.
the class RegistrySearchUtil method getSearchAttributes.
private static Map<String, String> getSearchAttributes(String searchQuery) {
String[] searchQueries = searchQuery.split("&");
String apiState = "";
String publisherRoles = "";
Map<String, String> attributes = new HashMap<String, String>();
for (String searchCriterea : searchQueries) {
String[] keyVal = searchCriterea.split("=");
if (STORE_VIEW_ROLES.equals(keyVal[0])) {
attributes.put("propertyName", keyVal[0]);
attributes.put("rightPropertyValue", keyVal[1]);
attributes.put("rightOp", "eq");
} else if (PUBLISHER_ROLES.equals(keyVal[0])) {
publisherRoles = keyVal[1];
} else {
if (LCSTATE_SEARCH_KEY.equals(keyVal[0])) {
apiState = keyVal[1];
continue;
}
attributes.put(keyVal[0], keyVal[1]);
}
}
// check whether the new document indexer is engaged
RegistryConfigLoader registryConfig = RegistryConfigLoader.getInstance();
Map<String, Indexer> indexerMap = registryConfig.getIndexerMap();
Indexer documentIndexer = indexerMap.get(DOCUMENT_MEDIA_TYPE_KEY);
String complexAttribute;
if (documentIndexer != null && DOCUMENT_INDEXER.equals(documentIndexer.getClass().getName())) {
// field check on document_indexed was added to prevent unindexed(by new DocumentIndexer) from coming up as search results
// on indexed documents this property is always set to true
complexAttribute = ClientUtils.escapeQueryChars(API_RXT_MEDIA_TYPE) + " OR mediaType_s:(" + ClientUtils.escapeQueryChars(DOCUMENT_RXT_MEDIA_TYPE) + " AND document_indexed_s:true)";
// this was designed this way so that content search can be fully functional if registry is re-indexed after engaging DocumentIndexer
if (!StringUtils.isEmpty(publisherRoles)) {
complexAttribute = "(" + ClientUtils.escapeQueryChars(API_RXT_MEDIA_TYPE) + " AND publisher_roles_ss:" + publisherRoles + ") OR mediaType_s:(" + ClientUtils.escapeQueryChars(DOCUMENT_RXT_MEDIA_TYPE) + " AND publisher_roles_s:" + publisherRoles + ")";
}
} else {
// document indexer required for document content search is not engaged, therefore carry out the search only for api artifact contents
complexAttribute = ClientUtils.escapeQueryChars(API_RXT_MEDIA_TYPE);
if (!StringUtils.isEmpty(publisherRoles)) {
complexAttribute = "(" + ClientUtils.escapeQueryChars(API_RXT_MEDIA_TYPE) + " AND publisher_roles_ss:" + publisherRoles + ")";
}
}
attributes.put(DOCUMENTATION_SEARCH_MEDIA_TYPE_FIELD, complexAttribute);
attributes.put(API_OVERVIEW_STATUS, apiState);
return attributes;
}
Aggregations