Search in sources :

Example 11 with Indexer

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();
    }
}
Also used : IndexDocument(org.wso2.carbon.registry.indexing.solr.IndexDocument) AsyncIndexer(org.wso2.carbon.registry.indexing.AsyncIndexer) Test(org.junit.Test)

Example 12 with Indexer

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;
}
Also used : RegistryConfigLoader(org.wso2.carbon.registry.indexing.RegistryConfigLoader) Indexer(org.wso2.carbon.registry.indexing.indexer.Indexer) HashMap(java.util.HashMap)

Aggregations

IndexDocument (org.wso2.carbon.registry.indexing.solr.IndexDocument)7 Test (org.junit.Test)5 Resource (org.wso2.carbon.registry.core.Resource)4 AsyncIndexer (org.wso2.carbon.registry.indexing.AsyncIndexer)4 HashMap (java.util.HashMap)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 IOException (java.io.IOException)2 List (java.util.List)2 WordExtractor (org.apache.poi.hwpf.extractor.WordExtractor)2 XWPFWordExtractor (org.apache.poi.xwpf.extractor.XWPFWordExtractor)2 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)2 Association (org.wso2.carbon.registry.core.Association)2 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)2 RegistryConfigLoader (org.wso2.carbon.registry.indexing.RegistryConfigLoader)2 Indexer (org.wso2.carbon.registry.indexing.indexer.Indexer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1