public String search()

in remoting/server/web/usages.web.api/src/org/netbeans/modules/jackpot30/backend/usages/api/Usages.java [50:107]


    public String search(@QueryParam("path") String segment, @QueryParam("signatures") String signatures, @QueryParam("searchResources") @DefaultValue("true") boolean searchResources) throws IOException, InterruptedException {
        StringBuilder result = new StringBuilder();
        CategoryStorage category = CategoryStorage.forId(segment);
        Index idx = category.getIndex();
        String origSignature = signatures;

        if ((signatures.startsWith("FIELD:") || signatures.startsWith("ENUM_CONSTANT:")) && signatures.split(":").length == 4) {
            //handle old clients sending field type inside as part of the field handle:
            signatures = signatures.substring(0, signatures.lastIndexOf(':'));
        }

        List<String> found = new ArrayList<String>();
        Query query = Queries.createQuery(KEY_SIGNATURES, "does-not-exist", signatures, QueryKind.EXACT);

        //TODO: field selector:
        idx.query(found, new ConvertorImpl(), null, new AtomicBoolean(), query);

        if (found.isEmpty()) {
            //transient: try old index structure with field handles containing the field type
            query = Queries.createQuery(KEY_SIGNATURES, "does-not-exist", origSignature, QueryKind.EXACT);

            //TODO: field selector:
            idx.query(found, new ConvertorImpl(), null, new AtomicBoolean(), query);
        }

        if (searchResources) {
            //look for usages from resources:
            String[] parts = signatures.split(":");

            if (parts.length >= 2 ) {
                String otherSignature;

                switch (parts[0]) {
                    case "FIELD": case "ENUM_CONSTANT":
                    case "METHOD":
                        if (parts.length >= 3) {
                            otherSignature = "OTHER:" + parts[1] + ":" + parts[2];
                            break;
                        }
                    default:
                        otherSignature = "OTHER:" + parts[1];
                        break;
                }

                query = Queries.createQuery(KEY_SIGNATURES, "does-not-exist", otherSignature, QueryKind.EXACT);

                //TODO: field selector:
                idx.query(found, new ConvertorImpl(), null, new AtomicBoolean(), query);
            }
        }

        for (String foundFile : found) {
            result.append(foundFile);
            result.append("\n");
        }

        return result.toString();
    }