Java List Create createOrderedQuery(String attributeName, List ids)

Here you can find the source of createOrderedQuery(String attributeName, List ids)

Description

Step 1 in Collaborative Filtering using SOLR.

License

Open Source License

Declaration

public static String createOrderedQuery(String attributeName,
        List<String> ids) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static int MAX_SAME_PRODUCT_COUNT = 2900;

    /**/*from www  .  j a va  2  s  .co m*/
     * Step 1 in Collaborative Filtering using SOLR.
     * <br/>
     * Finds similar users who like the same document
     */
    public static String createOrderedQuery(String attributeName,
            List<String> ids) {
        StringBuilder queryBuilder = new StringBuilder();

        if (ids != null) {

            queryBuilder.append(attributeName + ":(");

            int productCounter = 0;

            int weight = ids.size();

            for (String product : ids) {
                if (productCounter >= MAX_SAME_PRODUCT_COUNT) {
                    break;
                }

                queryBuilder.append("\"" + product + "\"^" + weight
                        + " OR ");
                productCounter++;
                weight--;
            }

            if (ids != null && ids.size() > 0) {
                queryBuilder.replace(queryBuilder.length() - 3,
                        queryBuilder.length(), "");
            }

            queryBuilder.append(")");
        }

        return queryBuilder.toString();
    }
}

Related

  1. createNormativeTroopAllocation( List probs)
  2. createNullElementList(int size)
  3. createNullList(int numberOfElements)
  4. CreateObjectList(Object... values)
  5. createOneElementList(T element)
  6. createOrgAttributeList()
  7. createOrGrow(List list, int minCapacity)
  8. createOutputTuple(List> tuples)
  9. createPostBody(final List required)