Example usage for org.apache.lucene.index IndexWriter addDocument

List of usage examples for org.apache.lucene.index IndexWriter addDocument

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexWriter addDocument.

Prototype

public long addDocument(Iterable<? extends IndexableField> doc) throws IOException 

Source Link

Document

Adds a document to this index.

Usage

From source file:com.concursive.connect.web.modules.documents.dao.FileItemIndexer.java

License:Open Source License

/**
 * Description of the Method/*from w  w w .  j ava  2 s .  c o  m*/
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    FileItem fileItem = (FileItem) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(fileItem.getLinkItemId());
    String ext = fileItem.getExtension();
    String filename = fileItem.getFullFilePath();
    String contents = ContentUtils.getText(ext, filename);
    // add the document
    Document document = new Document();
    document.add(new Field("type", "file", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(
            new Field("fileId", String.valueOf(fileItem.getId()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("folderId", String.valueOf(fileItem.getFolderId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(fileItem.getLinkItemId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    // determine if membership is needed for this content based on a guest's access to the data
    int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
    if (membership == 1 && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(),
            "project-documents-files-download")) {
        membership = 0;
    }
    document.add(
            new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", fileItem.getSubject() + " - " + fileItem.getClientFilename(),
            Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower",
            (fileItem.getSubject() + " - " + fileItem.getClientFilename()).toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("filename", fileItem.getClientFilename(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("extension", fileItem.getExtension(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("contents",
            fileItem.getSubject() + " " + fileItem.getClientFilename() + " " + ContentUtils.toText(contents),
            Field.Store.YES, Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(fileItem.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    document.add(
            new Field("size", String.valueOf(fileItem.getSize()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        System.out.println("FileItemIndexer-> fileId: " + fileItem.getId());
        System.out.println("FileItemIndexer-> folderId: " + fileItem.getFolderId());
        System.out.println("FileItemIndexer-> projectId: " + fileItem.getLinkItemId());
        System.out.println("FileItemIndexer-> title: " + fileItem.getId());
        System.out.println("FileItemIndexer-> extension: " + fileItem.getExtension());
    }
}

From source file:com.concursive.connect.web.modules.issues.dao.TicketIndexer.java

License:Open Source License

/**
 * Description of the Method// w  w w  .  ja v a  2s  .  c  o m
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    Ticket ticket = (Ticket) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(ticket.getProjectId());
    // populate the document
    Document document = new Document();
    document.add(new Field("type", "ticket", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(
            new Field("ticketId", String.valueOf(ticket.getId()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("projectTicketId", String.valueOf(ticket.getProjectTicketCount()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(ticket.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("membership", (project.getFeatures().getMembershipRequired() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title",
            "#" + ticket.getProjectTicketCount() + " "
                    + (ticket.getProblem().length() > 150
                            ? ContentUtils.toText(ticket.getProblem().substring(0, 150))
                            : ContentUtils.toText(ticket.getProblem())),
            Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", "#" + ticket.getProjectTicketCount() + " "
            + (ticket.getProblem().length() > 150 ? ContentUtils.toText(ticket.getProblem().substring(0, 150))
                    : ContentUtils.toText(ticket.getProblem())).toLowerCase(),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", ContentUtils.toText("#" + ticket.getProjectTicketCount()) + " "
            + ContentUtils.toText(ticket.getProblem()) + " " + ContentUtils.toText(ticket.getSolution()) + " "
            + ContentUtils.toText(ticket.getLocation()) + " " + ContentUtils.toText(ticket.getCause()),
            Field.Store.YES, Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(ticket.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    document.add(new Field("enteredBy", String.valueOf(ticket.getEnteredBy()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        LOG.debug("Added: " + ticket.getId());
    }
}

From source file:com.concursive.connect.web.modules.lists.dao.TaskCategoryIndexer.java

License:Open Source License

/**
 * Description of the Method// ww w.  j  a v  a 2  s  . c  o  m
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    TaskCategory taskCategory = (TaskCategory) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(taskCategory.getLinkItemId());
    // add the document
    Document document = new Document();
    document.add(new Field("type", "listCategory", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("listCategoryKeyId", String.valueOf(taskCategory.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("listCategoryId", String.valueOf(taskCategory.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(taskCategory.getLinkItemId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("membership", (project.getFeatures().getMembershipRequired() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", taskCategory.getDescription(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", taskCategory.getDescription().toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", taskCategory.getDescription(), Field.Store.YES, Field.Index.TOKENIZED));
    /*
     *  if (modified) {
     *  document.add(Field.Keyword("modified", String.valueOf(System.currentTimeMillis())));
     *  } else {
     *  document.add(Field.Keyword("modified", String.valueOf(taskCategory.getModified().getTime())));
     *  }
     */
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        System.out.println("TaskCategoryIndexer-> Added: " + taskCategory.getId());
    }
}

From source file:com.concursive.connect.web.modules.lists.dao.TaskIndexer.java

License:Open Source License

/**
 * Description of the Method//w w w .  jav  a2s  .  c  o m
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    Task task = (Task) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(task.getProjectId());
    // add the document
    Document document = new Document();
    document.add(new Field("type", "list", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("listId", String.valueOf(task.getId()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("listCategoryId", String.valueOf(task.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(task.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("membership", (project.getFeatures().getMembershipRequired() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", task.getDescription(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", task.getDescription().toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", task.getDescription() + " " + ContentUtils.toText(task.getNotes()),
            Field.Store.YES, Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(task.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        System.out.println("TaskIndexer-> Added: " + task.getId());
    }
}

From source file:com.concursive.connect.web.modules.plans.dao.AssignmentFolderIndexer.java

License:Open Source License

/**
 * Description of the Method//from ww  w  .  j a v a 2  s.c  om
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    AssignmentFolder assignmentFolder = (AssignmentFolder) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(assignmentFolder.getProjectId());
    // add the document
    Document document = new Document();
    document.add(new Field("type", "activityfolder", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("assignmentFolderId", String.valueOf(assignmentFolder.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("requirementId", String.valueOf(assignmentFolder.getRequirementId()),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(assignmentFolder.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    // determine if membership is needed for this content based on a guest's access to the data
    int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
    if (membership == 1
            && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(), "project-plan-view")) {
        membership = 0;
    }
    document.add(
            new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", assignmentFolder.getName(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", assignmentFolder.getName().toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("contents",
            assignmentFolder.getName() + " " + ContentUtils.toText(assignmentFolder.getDescription()),
            Field.Store.YES, Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(assignmentFolder.getModified().getTime()),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
    }
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        System.out.println("AssignmentFolderIndexer-> Added: " + assignmentFolder.getId());
    }
}

From source file:com.concursive.connect.web.modules.plans.dao.AssignmentIndexer.java

License:Open Source License

/**
 * Description of the Method//from  w w w  . j  av a 2s  . c  o m
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    Assignment assignment = (Assignment) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(assignment.getProjectId());
    // add the document
    Document document = new Document();
    document.add(new Field("type", "activity", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("assignmentId", String.valueOf(assignment.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("assignmentKeyId", String.valueOf(assignment.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("requirementId", String.valueOf(assignment.getRequirementId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(assignment.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    // determine if membership is needed for this content based on a guest's access to the data
    int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
    if (membership == 1
            && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(), "project-plan-view")) {
        membership = 0;
    }
    document.add(
            new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", assignment.getRole(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", assignment.getRole().toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", assignment.getRole() + " " + assignment.getTechnology(), Field.Store.YES,
            Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(assignment.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        LOG.debug("AssignmentIndexer-> Added: " + assignment.getId());
    }
}

From source file:com.concursive.connect.web.modules.plans.dao.AssignmentNoteIndexer.java

License:Open Source License

/**
 * Description of the Method/*from   ww w  .j  a  va2 s  .  co m*/
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    AssignmentNote assignmentNote = (AssignmentNote) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(assignmentNote.getProjectId());
    // add the document
    Document document = new Document();
    document.add(new Field("type", "activitynote", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("assignmentNoteId", String.valueOf(assignmentNote.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("assignmentId", String.valueOf(assignmentNote.getAssignmentId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(assignmentNote.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    // determine if membership is needed for this content based on a guest's access to the data
    int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
    if (membership == 1
            && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(), "project-plan-view")) {
        membership = 0;
    }
    document.add(
            new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", ContentUtils.toText(assignmentNote.getDescription()), Field.Store.YES,
            Field.Index.TOKENIZED));
    document.add(new Field("titleLower", ContentUtils.toText(assignmentNote.getDescription()).toLowerCase(),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", ContentUtils.toText(assignmentNote.getDescription()), Field.Store.YES,
            Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(assignmentNote.getEntered().getTime()),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
    }
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        LOG.debug("AssignmentNoteIndexer-> Added: " + assignmentNote.getId());
    }
}

From source file:com.concursive.connect.web.modules.plans.dao.RequirementIndexer.java

License:Open Source License

/**
 * Description of the Method//from   w ww  .  j a  va 2  s . com
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    Requirement requirement = (Requirement) item;
    // use the project's general access to speedup guest projects
    Project project = ProjectUtils.loadProject(requirement.getProjectId());
    // add the document
    Document document = new Document();
    document.add(new Field("type", "outline", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("requirementKeyId", String.valueOf(requirement.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("requirementId", String.valueOf(requirement.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(requirement.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    // determine if membership is needed for this content based on a guest's access to the data
    int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
    if (membership == 1
            && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(), "project-plan-view")) {
        membership = 0;
    }
    document.add(
            new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", requirement.getShortDescription(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", requirement.getShortDescription().toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("contents",
            requirement.getShortDescription() + " " + ContentUtils.toText(requirement.getDescription()) + " "
                    + requirement.getSubmittedBy() + " " + requirement.getDepartmentBy(),
            Field.Store.YES, Field.Index.TOKENIZED));
    if (modified) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(requirement.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        LOG.debug("RequirementIndexer-> Added: " + requirement.getId());
    }
}

From source file:com.concursive.connect.web.modules.profile.dao.ProjectIndexer.java

License:Open Source License

/**
 * Converts a project to a Lucene Document and adds to the index
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 *///from   w  ww .  j a  va  2  s. c  o m
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    Project project = (Project) item;
    // add the document
    Document document = new Document();
    document.add(new Field("type", "project", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("instanceId", String.valueOf(project.getInstanceId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectKeyId", String.valueOf(project.getId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(
            new Field("projectId", String.valueOf(project.getId()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("projectCategoryId1", String.valueOf(project.getSubCategory1Id()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    // determine if membership is needed for this content based on a guest's access to the data
    int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
    if (membership == 1
            && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(), "project-profile-view")) {
        membership = 0;
    }
    document.add(
            new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(
            new Field("approved", ((project.getApproved() || project.getApprovalDate() != null) ? "1" : "0"),
                    Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("closed", ((project.getClosed() || project.getCloseDate() != null) ? "1" : "0"),
            Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(
            new Field("website", (project.getPortal() ? "1" : "0"), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("title", project.getTitle(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleLower", project.getTitle().toLowerCase(), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(
            new Field("keywords", (StringUtils.hasText(project.getKeywords()) ? project.getKeywords() : ""),
                    Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", project.getTitle() + " " + project.getShortDescription()
            + (StringUtils.hasText(project.getDescription())
                    ? " " + ContentUtils.toText(ContentUtils.stripHTML(project.getDescription()))
                    : "")
            + (StringUtils.hasText(project.getKeywords()) ? " " + project.getKeywords() : ""), Field.Store.YES,
            Field.Index.TOKENIZED));
    if (project.getEntered() == null) {
        document.add(new Field("entered", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("entered", String.valueOf(project.getEntered().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    if (modified || project.getModified() == null) {
        document.add(new Field("modified", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
        document.add(new Field("newsDate", String.valueOf(System.currentTimeMillis()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    } else {
        document.add(new Field("modified", String.valueOf(project.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
        document.add(new Field("newsDate", String.valueOf(project.getModified().getTime()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    document.add(new Field("location", project.getLocation(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("ratingCount", String.valueOf(project.getRatingCount()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("ratingValue", String.valueOf(project.getRatingValue()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    document.add(new Field("ratingAverage", String.valueOf(project.getRatingAverage()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    writer.addDocument(document);
    if (LOG.isDebugEnabled() && modified) {
        LOG.debug("Added: " + project.getId());
    }
}

From source file:com.concursive.connect.web.modules.promotions.dao.AdIndexer.java

License:Open Source License

/**
 * Description of the Method/*from w  ww.  j av a2  s  .c o m*/
 *
 * @param writer   Description of the Parameter
 * @param item     Description of the Parameter
 * @param modified Description of the Parameter
 * @throws IOException Description of the Exception
 */
public void add(IndexWriter writer, Object item, boolean modified) throws IOException {
    Ad ad = (Ad) item;
    // add the document
    Document document = new Document();
    document.add(new Field("type", "ads", Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("adId", String.valueOf(ad.getId()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("projectId", String.valueOf(ad.getProjectId()), Field.Store.YES,
            Field.Index.UN_TOKENIZED));
    if (ad.getCategoryId() != -1) {
        document.add(new Field("categoryId", String.valueOf(ad.getCategoryId()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }
    document.add(
            new Field("location", String.valueOf(ProjectUtils.loadProject(ad.getProjectId()).getLocation()),
                    Field.Store.YES, Field.Index.TOKENIZED));
    document.add(
            new Field("instanceId", String.valueOf(ProjectUtils.loadProject(ad.getProjectId()).getInstanceId()),
                    Field.Store.YES, Field.Index.UN_TOKENIZED));
    if (ad.getProjectId() > -1) {
        // use the project's general access to speedup guest projects
        Project project = ProjectUtils.loadProject(ad.getProjectId());
        document.add(new Field("projectCategoryId", String.valueOf(project.getCategoryId()), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
        document.add(new Field("guests", (project.getFeatures().getAllowGuests() ? "1" : "0"), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
        document.add(new Field("participants", (project.getFeatures().getAllowParticipants() ? "1" : "0"),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
        // determine if membership is needed for this content based on a guest's access to the data
        int membership = project.getFeatures().getMembershipRequired() ? 1 : 0;
        if (membership == 1
                && ProjectUtils.hasAccess(project.getId(), UserUtils.createGuestUser(), "project-ads-view")) {
            membership = 0;
        }
        document.add(
                new Field("membership", String.valueOf(membership), Field.Store.YES, Field.Index.UN_TOKENIZED));
    }
    document.add(new Field("title", ad.getHeading(), Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("titleFull", ad.getHeading(), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(
            new Field("titleLower", ad.getHeading().toLowerCase(), Field.Store.YES, Field.Index.UN_TOKENIZED));
    document.add(new Field("contents", ad.getHeading() + " " + ContentUtils.toText(ad.getContent()),
            Field.Store.YES, Field.Index.TOKENIZED));
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    if (ad.getPublishDate() != null) {
        document.add(new Field("modified", String.valueOf(formatter.format(ad.getPublishDate())),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
        document.add(new Field("published", String.valueOf(formatter.format(ad.getPublishDate())),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
    }
    if (ad.getExpirationDate() != null) {
        document.add(new Field("expired", String.valueOf(formatter.format(ad.getExpirationDate())),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
    }
    writer.addDocument(document);
    if (System.getProperty("DEBUG") != null && modified) {
        System.out.println("AdIndexer-> Added: " + ad.getId());
    }
}