Class SearchEngine

java.lang.Object
org.troy.capstone.search_engine.SearchEngine

public class SearchEngine extends Object
The SearchEngine class is responsible for filtering items based on various criteria such as price range, star rating, categorical filters, and search queries. It utilizes a PriceRangeFinder for efficient price range filtering and a QueryFilter for handling search queries with Lucene.
  • Field Details

    • table

      private final Table table
      The original table containing all item data, used for filtering and retrieving item information.
    • priceFilter

      private final PriceFilter priceFilter
      The PriceFilter for efficiently finding items within a specified price range.
    • queryFilter

      private final QueryFilter queryFilter
      The QueryFilter for handling search queries using a Lucene index built from the item data.
  • Constructor Details

    • SearchEngine

      public SearchEngine(Table table)
      Constructor for SearchEngine, filled from a Table.
      Parameters:
      table - The Table containing the data to be searched.
  • Method Details

    • filterItems

      public Table filterItems(Map<UIDataName, Object> searchData)
      Filters the data by categorical filter selections. For tags, we use AND so all tags are there as multiple can be selected. For other categorical filters, we use OR since only one value is there.
      Parameters:
      searchData - The search data containing the filters to be applied.
      Returns:
      The table containing the items that match the search criteria.
    • applySearchQueryFilter

      public Table applySearchQueryFilter(String userQuery, Table preQueryFilteredTable)
      Helper method to apply the search query results as a filter on the table.
      Parameters:
      userQuery - The userQuery to be applied as a filter.
      preQueryFilteredTable - The Table after applying all filters except the search query filter, so that the search query filter is only applied to the already filtered items for better performance.
      Returns:
      The filtered Table with search results, or the original Table if no filtering was applied.
    • applyTagFilters

      private Table applyTagFilters(Map<String, Set<String>> filtersContainer, Table filteredTable)
      Helper method to apply tag filters since they have special handling compared to other categorical filters.
      Parameters:
      filtersContainer - The filters container containing the selected tags under the "Tags" key.
      filteredTable - The table to apply the tag filters on.
      Returns:
      The selection of items that match the selected tags. Returns ALL items if no tags are selected or if the selected tags value is not found in the filters container.
    • applyStarFilter

      private Table applyStarFilter(Map<UIDataName, Object> searchData, Table filteredTable)
      Helper method to apply the star rating filter.
      Parameters:
      searchData - The search data containing the minimum star rating.
      filteredTable - The table to apply the star rating filter on.
      Returns:
      The table of items that match the minimum star rating. Returns the original table if the minimum star rating value is not found in the search data or is not of the expected type.
    • applyPriceFilters

      private Table applyPriceFilters(Map<UIDataName, Object> searchData, Table filteredTable)
      Helper method to apply price filters.
      Parameters:
      searchData - The search data containing the minimum and/or maximum price.
      filteredTable - The table to apply the price filter on.
      Returns:
      The table of items that match the price criteria. Returns the original table if the minimum or maximum price value are not of the expected type.
    • applyCategoricalFilters

      private Table applyCategoricalFilters(Map<UIDataName, Object> searchData, Table filteredTable)
      Helper method to apply categorical filters (other than tags which have special handling).
      Parameters:
      searchData - The search data containing the selected categorical filters under the FILTERS_CONTAINER key.
      filteredTable - The table to apply the categorical filters on.
      Returns:
      The table of items that match the selected categorical filters, or the original table if no valid filters are found in the search data.
    • selectAll

      private Selection selectAll(int rowCount)
      Select all rows in the table.
      Parameters:
      rowCount - The number of rows in the table to create a selection that includes all rows.
      Returns:
      A Selection object that includes all rows in the table.