Class SearchEngine
java.lang.Object
org.troy.capstone.search_engine.SearchEngine
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final PriceFilterThePriceFilterfor efficiently finding items within a specified price range.private final QueryFilterTheQueryFilterfor handling search queries using a Lucene index built from the item data.private final TableThe original table containing all item data, used for filtering and retrieving item information. -
Constructor Summary
ConstructorsConstructorDescriptionSearchEngine(Table table) Constructor forSearchEngine, filled from aTable. -
Method Summary
Modifier and TypeMethodDescriptionprivate TableapplyCategoricalFilters(Map<UIDataName, Object> searchData, Table filteredTable) Helper method to apply categorical filters (other than tags which have special handling).private TableapplyPriceFilters(Map<UIDataName, Object> searchData, Table filteredTable) Helper method to apply price filters.applySearchQueryFilter(String userQuery, Table preQueryFilteredTable) Helper method to apply the search query results as a filter on the table.private TableapplyStarFilter(Map<UIDataName, Object> searchData, Table filteredTable) Helper method to apply the star rating filter.private TableHelper method to apply tag filters since they have special handling compared to other categorical filters.filterItems(Map<UIDataName, Object> searchData) Filters the data by categorical filter selections.private SelectionselectAll(int rowCount) Select all rows in the table.
-
Field Details
-
table
The original table containing all item data, used for filtering and retrieving item information. -
priceFilter
ThePriceFilterfor efficiently finding items within a specified price range. -
queryFilter
TheQueryFilterfor handling search queries using a Lucene index built from the item data.
-
-
Constructor Details
-
SearchEngine
Constructor forSearchEngine, filled from aTable.- Parameters:
table- TheTablecontaining the data to be searched.
-
-
Method Details
-
filterItems
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
Helper method to apply the search query results as a filter on the table.- Parameters:
userQuery- TheuserQueryto be applied as a filter.preQueryFilteredTable- TheTableafter 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
Tablewith search results, or the originalTableif no filtering was applied.
-
applyTagFilters
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
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
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
Helper method to apply categorical filters (other than tags which have special handling).- Parameters:
searchData- The search data containing the selected categorical filters under theFILTERS_CONTAINERkey.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
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
Selectionobject that includes all rows in the table.
-