protected String buildSearch(Map<String, MutableInt> vendor, Map<String, MutableInt> product,
            Set<String> vendorWeighting, Set<String> productWeightings) {

        final StringBuilder sb = new StringBuilder();

        if (!appendWeightedSearch(sb, Fields.PRODUCT, product, productWeightings)) {
            return null;
        }
        sb.append(" AND ");
        if (!appendWeightedSearch(sb, Fields.VENDOR, vendor, vendorWeighting)) {
            return null;
        }
        return sb.toString();
    }
@Test
    public void testBuildSearch() {
        Map<String, MutableInt> vendor = new HashMap<>();
        Map<String, MutableInt> product = new HashMap<>();
        vendor.put("apache software foundation", new MutableInt(1));
        product.put("lucene index", new MutableInt(1));
        Set<String> vendorWeighting = new HashSet<>();
        Set<String> productWeightings = new HashSet<>();

        CPEAnalyzer instance = new CPEAnalyzer();
        String expResult = "product:(lucene index) AND vendor:(apache software foundation)";
        String result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        vendorWeighting.add("apache");
        expResult = "product:(lucene index) AND vendor:(apache^2 software foundation)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        productWeightings.add("lucene");
        expResult = "product:(lucene^2 index) AND vendor:(apache^2 software foundation)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        productWeightings.add("ignored");
        expResult = "product:(lucene^2 index) AND vendor:(apache^2 software foundation)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        vendorWeighting.clear();
        expResult = "product:(lucene^2 index) AND vendor:(apache software foundation)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        vendorWeighting.add("ignored");
        productWeightings.clear();
        expResult = "product:(lucene index) AND vendor:(apache software foundation)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        vendor.put("apache software foundation", new MutableInt(3));
        product.put("lucene index", new MutableInt(2));

        expResult = "product:(lucene^2 index^2) AND vendor:(apache^3 software^3 foundation^3)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        vendorWeighting.add("apache");
        expResult = "product:(lucene^2 index^2) AND vendor:(apache^4 software^3 foundation^3)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        productWeightings.add("lucene");
        expResult = "product:(lucene^3 index^2) AND vendor:(apache^4 software^3 foundation^3)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        productWeightings.clear();
        productWeightings.add("lucene2");
        expResult = "product:(lucene^3 index^2 lucene2^3) AND vendor:(apache^4 software^3 foundation^3)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);

        vendor.put("apache software foundation", new MutableInt(1));
        vendor.put("apache", new MutableInt(2));
        product.put("lucene index", new MutableInt(1));
        product.put("lucene", new MutableInt(2));
        vendorWeighting.clear();
        productWeightings.clear();
        productWeightings.add("lucene2");
        expResult = "product:(lucene^3 lucene2^3 lucene^2 index lucene2^2) AND vendor:(apache^2 apache software foundation)";
        result = instance.buildSearch(vendor, product, vendorWeighting, productWeightings);
        assertEquals(expResult, result);
    }